Skip to content

Repository files navigation

Maatify.dev


📦 maatify/common

VersionPHPLicenseStatus

BuildPHPStanCode Quality

Monthly DownloadsTotal DownloadsStars

ChangelogSecurityFull DocsContributing


🏁 Stable Release v2.0.0 — Architectural Cleanup & Scope Stabilization

The core foundational library of the Maatify.dev ecosystem providing standardized DTOs, validation, sanitization, date/time, text utilities, and shared core helpers.

📦 This is the stable version (v1.0.10) of maatify/common, released on 2025-12-09. 🔗 بالعربي 🇸🇦


🧭 Version Information

KeyValue
Version2.0.0 Stable
Release Date2025-12-17
PHP Requirement≥ 8.2
LicenseMIT
Coverage98 %
Tests Passed70+ (160+ Assertions)

🧩 Overview

This library provides reusable, framework-agnostic building blocks (DTOs, helpers, traits, enums, validators) shared across the Maatify ecosystem.


📘 Documentation & Release Files

FileDescription
/docs/README.full.mdFull documentation (Phases 1–13)
/docs/enums.mdEnums & constants reference
CHANGELOG.mdVersion history (updated to 2.0.0)
CONTRIBUTING.mdContribution guidelines
VERSIONCurrent version → 2.0.0

Core Modules:

  • 🧮 Pagination HelpersPaginationHelper, PaginationDTO, PaginationResultDTO Unified pagination structures for API responses and MySQL queries.

  • 🧼 Security SanitizationInputSanitizer, SanitizesInputTrait Clean and escape user input safely with internal HTMLPurifier integration.

  • 🧠 Core TraitsSingletonTrait, SanitizesInputTrait Reusable traits for singleton pattern, safe input handling, and shared helpers.

  • Text & Placeholder UtilitiesTextFormatter, PlaceholderRenderer, RegexHelper, SecureCompare Powerful text formatting, placeholder rendering, and secure string comparison tools.

  • 🕒 Date & Time UtilitiesDateFormatter, DateHelper Humanized difference, timezone conversion, and localized date rendering (EN/AR/FR).

  • 🧩 Validation & Filtering ToolsValidator, Filter, ArrayHelper Email/URL/UUID/Slug validation, input detection, and advanced array cleanup utilities.

  • ⚙️ Enums & Constants StandardizationTextDirectionEnum, MessageTypeEnum, ErrorCodeEnum, PlatformEnum, AppEnvironmentEnum, CommonPaths, CommonLimits, CommonHeaders, Defaults, EnumHelper Centralized enum and constant definitions ensuring consistent standards, reusable helpers, and unified configuration across all Maatify libraries.


⚠️Design Scope Notice

maatify/common is intentionally limited to pure helpers, DTOs, traits, enums, and shared utilities.

It contains no adapters, repositories, drivers, storage contracts, or IO-related abstractions. Any such responsibilities belong to dedicated infrastructure packages.

⚙️ Installation

composer require maatify/common

📦 Dependencies

This library directly relies on:

DependencyPurposeLink
ezyang/htmlpurifierSecure HTML/XSS sanitization enginegithub.com/ezyang/htmlpurifier
psr/logStandardized PSR-3 logging interfacewww.php-fig.org/psr/psr-3
phpunit/phpunitUnit testing framework (development only)phpunit.de

maatify/common integrates these open-source libraries to deliver a consistent and secure foundation for all other Maatify components.

🧠 Note:maatify/common automatically configures HTMLPurifier to use an internal cache directory at storage/purifier_cache for optimized performance. This ensures faster sanitization on subsequent calls without requiring manual setup.

If you wish to override the cache path, set the environment variable:

HTMLPURIFIER_CACHE_PATH=/path/to/custom/cache

or modify it programmatically via:

$config->set('Cache.SerializerPath', '/custom/cache/path');

🧠 SingletonTrait

A clean, PSR-friendly Singleton implementation to manage single-instance service classes safely.

🔹 Example Usage

useMaatify\Common\Traits\SingletonTrait;
finalclass ConfigManager
{
use SingletonTrait;
publicfunctionget(string$key): ?string
{
return$_ENV[$key] ?? null;
}
}
// ✅ Always returns the same instance$config = ConfigManager::obj();
// ♻️ Reset (for testing)
ConfigManager::reset();

✅ Features

  • Prevents direct construction, cloning, and unserialization.
  • Provides static obj() to access the global instance.
  • Includes reset() for testing or reinitialization.

📚 Example Usage

🔹 Paginate Array Data

useMaatify\Common\Pagination\Helpers\PaginationHelper;
$items = range(1, 100);
$result = PaginationHelper::paginate($items, page: 2, perPage: 10);
print_r($result);

Output:

[
'data' => [11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
'pagination' => Maatify\Common\DTO\PaginationDTO {
page: 2,
perPage: 10,
total: 100,
totalPages: 10,
hasNext: true,
hasPrev: true
}
]

🔹 Working with PaginationDTO

useMaatify\Common\Pagination\DTO\PaginationDTO;
$pagination = newPaginationDTO(
page: 1,
perPage: 25,
total: 200,
totalPages: 8,
hasNext: true,
hasPrev: false
);
print_r($pagination->toArray());

🧩 Helpers

🧱 TapHelper

A lightweight, fluent utility for executing a callback on a given value (usually an object) and returning that same value unchanged —
perfect for cleaner object initialization and inline setup.


⚙️ Class

Maatify\Common\Helpers\TapHelper

✅ Features

  • Executes a callback on a passed object or value.
  • Returns the same value (object, scalar, array, etc.).
  • Useful for chaining and fluent API style.
  • 100% pure function — no side effects unless your callback modifies the object.

🧠 Example Usage

useMaatify\Common\Helpers\TapHelper;
useMaatify\DataAdapters\Adapters\MongoAdapter;
$config = newEnvironmentConfig(__DIR__ . '/../');
$mongo = TapHelper::tap(newMongoAdapter($config), fn($a) => $a->connect());
// $mongo is now a connected adapter$client = $mongo->getConnection();

🧾 Functional Philosophy

TapHelper follows a simple, expressive pattern inspired by functional programming:

PrincipleDescription
🧩 IsolationThe callback runs in isolation, returning no value.
🔁 ImmutabilityThe original object/value is returned unchanged.
🧼 ClarityReduces boilerplate for setup code.
🧠 TestabilitySimple to reason about and unit-test (see TapHelperTest).

🧪 Unit Test Reference

tests/Helpers/TapHelperTest.php

Covers:

  • Returning the same object instance.
  • Callback execution correctness.
  • Compatibility with scalars and arrays.
vendor/bin/phpunit --filter TapHelperTest

🧱 Code Reference

TapHelper::tap(mixed $value, callable $callback): mixed

Executes $callback($value) then returns $value.


🧩 Architectural Benefits within the Maatify Ecosystem

AspectBenefit
♻️ Fluent InitializationEnables building adapters and services in one clean line.
🧠 Ecosystem ConsistencyAligns with other helpers like PathHelper, EnumHelper, and TimeHelper.
🧼 Reduced BoilerplateReplaces multiple setup lines with a single expressive call.
🧩 Universal ReusabilityWorks seamlessly across all Maatify libraries (bootstrap, data-adapters, rate-limiter, redis-cache, etc.).

📘 Full Documentation:docs/enums.md


🗂 Directory Structure

src/
├── Pagination/
│ ├── DTO/
│ │ └── PaginationDTO.php
│ └── Helpers/
│ ├── PaginationHelper.php
│ └── PaginationResultDTO.php
├── Helpers/
│ └── TapHelper.php
├── Security/
│ └── InputSanitizer.php
├── Traits/
│ ├── SingletonTrait.php
│ └── SanitizesInputTrait.php
├── Text/
│ ├── PlaceholderRenderer.php
│ ├── TextFormatter.php
│ ├── RegexHelper.php
│ └── SecureCompare.php
├── Date/
│ ├── DateFormatter.php
│ └── DateHelper.php
└── Validation/
├── Validator.php
├── Filter.php
└── ArrayHelper.php
Enums/
├── TextDirectionEnum.php
├── MessageTypeEnum.php
├── ErrorCodeEnum.php
├── PlatformEnum.php
├── AppEnvironmentEnum.php
├── EnumHelper.php
└── Traits/
└── EnumJsonSerializableTrait.php

📚 Built Upon

maatify/common proudly builds upon several mature and battle-tested open-source foundations:

LibraryDescriptionUsage in Project
ezyang/htmlpurifierStandards-compliant HTML filtering libraryPowers InputSanitizer to ensure XSS-safe and standards-compliant HTML output with full Unicode support.
psr/logPSR-3 logging interfaceEnables standardized logging across sanitization, and validation components.
phpunit/phpunitPHP unit testing frameworkProvides automated testing with CI/CD GitHub workflow integration.

Huge thanks to the open-source community for their contributions, making the Maatify ecosystem secure, reliable, and extensible. ❤️


📊 Updated Phase Summary Table (Phases 1 → 18)

PhaseTitleStatusFiles CreatedNotes
1Pagination Module✅ Completed3Pagination DTOs & helpers
3Security & Input Sanitization✅ Completed3InputCleaner, HTMLPurifier wrapper, XSS-safe normalizers
3bCore Traits — Singleton System✅ Completed1SingletonTrait implementation
4Text & Placeholder Utilities✅ Completed8PlaceholderRenderer, TextFormatter, RegexHelper, SecureCompare
5Date & Time Utilities✅ Completed4HumanizeDifference, LocalizedDateFormatter, Timestamp helpers
6Validation & Filtering Tools✅ Completed3Validator, Filter, ArrayHelper + full PHPUnit suite
7Enums & Constants Standardization✅ Completed10 + 5 testsUnified Enum system, EnumHelper, JSONSerializableTrait, ValueEnum base
8Testing & Release (v1.0.0)✅ Completed6CHANGELOG, CONTRIBUTING, VERSION, README.full.md, CI integration, initial stable release
10TapHelper Utility✅ Completed1Introduced TapHelper + full test coverage
12Version Hotfix✅ Completed1Fixed version mismatch and updated VERSION file

✅ Verified Test Results

PHPUnit 10.5.58 — PHP 8.4.4
• Tests: 66 • Assertions: 150 • Coverage: ~98 %
• Runtime: 0.076 s • Memory: 12 MB
• Warnings: 1 (No coverage driver available — safe to ignore)


All files have been verified and finalized as part of v2.0.0 Stable Release.

  • /docs/README.full.md – full documentation merged
  • /docs/enums.md – enums and constants reference
  • /docs/phases/README.phase7.md – phase documentation
  • CHANGELOG.md – release history initialized
  • CONTRIBUTING.md – contributor guide added
  • VERSION – version 2.0.0 confirmed

🔗 Full documentation & release notes: see /docs/README.full.md


🪪 License

MIT license © Maatify.dev
You’re free to use, modify, and distribute this library with attribution.


🧱 Authors & Credits

This library is part of the Maatify.dev Core Ecosystem, designed and maintained under the technical supervision of:

👤 Mohamed AbdulalimBackend Lead & Technical Architect
Lead architect of the Maatify Backend Infrastructure, responsible for the overall architecture, core library design,
and technical standardization across all backend modules within the Maatify ecosystem.
🔗 www.Maatify.dev | ✉️ mohamed@maatify.dev

🤝 Contributors:
The Maatify.dev Engineering Team and open-source collaborators who continuously help refine, test, and extend
the capabilities of this library across multiple Maatify projects.

🧩 This project represents a unified engineering effort led by Mohamed Abdulalim, ensuring every Maatify backend component
shares a consistent, secure, and maintainable foundation.


Built with ❤️ by Maatify.dev — Unified Ecosystem for Modern PHP Libraries


About

A core foundational library within the Maatify ecosystem — providing standardized DTOs, validation, sanitization, date/time, locking, and text utilities for all backend modules

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages