maatify / common
Common DTOs and helpers for all maatify libraries
Installs: 833
Dependents: 5
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 1
Open Issues: 0
pkg:composer/maatify/common
Requires
- php: >=8.2
- ext-intl: *
- ext-mbstring: *
- ezyang/htmlpurifier: ^4.19
- maatify/psr-logger: ^1.0
Requires (Dev)
- doctrine/dbal: ^4.3
- friendsofphp/php-cs-fixer: ^3.89
- mongodb/mongodb: ^2.0
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
- predis/predis: ^2.3
README
๐ฆ maatify/common
๐ 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
| Key | Value |
|---|---|
| Version | 2.0.0 Stable |
| Release Date | 2025-12-17 |
| PHP Requirement | โฅ 8.2 |
| License | MIT |
| Coverage | 98 % |
| Tests Passed | 70+ (160+ Assertions) |
๐งฉ Overview
This library provides reusable, framework-agnostic building blocks (DTOs, helpers, traits, enums, validators) shared across the Maatify ecosystem.
๐ Documentation & Release Files
| File | Description |
|---|---|
/docs/README.full.md |
Full documentation (Phases 1โ13) |
/docs/enums.md |
Enums & constants reference |
CHANGELOG.md |
Version history (updated to 2.0.0) |
CONTRIBUTING.md |
Contribution guidelines |
VERSION |
Current version โ 2.0.0 |
Core Modules:
-
๐งฎ Pagination Helpers โ
PaginationHelper,PaginationDTO,PaginationResultDTOUnified pagination structures for API responses and MySQL queries. -
๐งผ Security Sanitization โ
InputSanitizer,SanitizesInputTraitClean and escape user input safely with internalHTMLPurifierintegration. -
๐ง Core Traits โ
SingletonTrait,SanitizesInputTraitReusable traits for singleton pattern, safe input handling, and shared helpers. -
โจ Text & Placeholder Utilities โ
TextFormatter,PlaceholderRenderer,RegexHelper,SecureComparePowerful text formatting, placeholder rendering, and secure string comparison tools. -
๐ Date & Time Utilities โ
DateFormatter,DateHelperHumanized difference, timezone conversion, and localized date rendering (EN/AR/FR). -
๐งฉ Validation & Filtering Tools โ
Validator,Filter,ArrayHelperEmail/URL/UUID/Slug validation, input detection, and advanced array cleanup utilities. -
โ๏ธ Enums & Constants Standardization โ
TextDirectionEnum,MessageTypeEnum,ErrorCodeEnum,PlatformEnum,AppEnvironmentEnum,CommonPaths,CommonLimits,CommonHeaders,Defaults,EnumHelperCentralized enum and constant definitions ensuring consistent standards, reusable helpers, and unified configuration across all Maatify libraries.
โ ๏ธ Design Scope Notice
maatify/commonis 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:
| Dependency | Purpose | Link |
|---|---|---|
| ezyang/htmlpurifier | Secure HTML/XSS sanitization engine | github.com/ezyang/htmlpurifier |
| psr/log | Standardized PSR-3 logging interface | www.php-fig.org/psr/psr-3 |
| phpunit/phpunit | Unit testing framework (development only) | phpunit.de |
maatify/commonintegrates these open-source libraries to deliver a consistent and secure foundation for all other Maatify components.
๐ง Note:
maatify/commonautomatically configures HTMLPurifier to use an internal cache directory atstorage/purifier_cachefor 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/cacheor 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
use Maatify\Common\Traits\SingletonTrait; final class ConfigManager { use SingletonTrait; public function get(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
use Maatify\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
use Maatify\Common\Pagination\DTO\PaginationDTO; $pagination = new PaginationDTO( 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
use Maatify\Common\Helpers\TapHelper; use Maatify\DataAdapters\Adapters\MongoAdapter; $config = new EnvironmentConfig(__DIR__ . '/../'); $mongo = TapHelper::tap(new MongoAdapter($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:
| Principle | Description |
|---|---|
| ๐งฉ Isolation | The callback runs in isolation, returning no value. |
| ๐ Immutability | The original object/value is returned unchanged. |
| ๐งผ Clarity | Reduces boilerplate for setup code. |
| ๐ง Testability | Simple 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
| Aspect | Benefit |
|---|---|
| โป๏ธ Fluent Initialization | Enables building adapters and services in one clean line. |
| ๐ง Ecosystem Consistency | Aligns with other helpers like PathHelper, EnumHelper, and TimeHelper. |
| ๐งผ Reduced Boilerplate | Replaces multiple setup lines with a single expressive call. |
| ๐งฉ Universal Reusability | Works 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:
| Library | Description | Usage in Project |
|---|---|---|
| ezyang/htmlpurifier | Standards-compliant HTML filtering library | Powers InputSanitizer to ensure XSS-safe and standards-compliant HTML output with full Unicode support. |
| psr/log | PSR-3 logging interface | Enables standardized logging across sanitization, and validation components. |
| phpunit/phpunit | PHP unit testing framework | Provides 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)
| Phase | Title | Status | Files Created | Notes |
|---|---|---|---|---|
| 1 | Pagination Module | โ Completed | 3 | Pagination DTOs & helpers |
| 3 | Security & Input Sanitization | โ Completed | 3 | InputCleaner, HTMLPurifier wrapper, XSS-safe normalizers |
| 3b | Core Traits โ Singleton System | โ Completed | 1 | SingletonTrait implementation |
| 4 | Text & Placeholder Utilities | โ Completed | 8 | PlaceholderRenderer, TextFormatter, RegexHelper, SecureCompare |
| 5 | Date & Time Utilities | โ Completed | 4 | HumanizeDifference, LocalizedDateFormatter, Timestamp helpers |
| 6 | Validation & Filtering Tools | โ Completed | 3 | Validator, Filter, ArrayHelper + full PHPUnit suite |
| 7 | Enums & Constants Standardization | โ Completed | 10 + 5 tests | Unified Enum system, EnumHelper, JSONSerializableTrait, ValueEnum base |
| 8 | Testing & Release (v1.0.0) | โ Completed | 6 | CHANGELOG, CONTRIBUTING, VERSION, README.full.md, CI integration, initial stable release |
| 10 | TapHelper Utility | โ Completed | 1 | Introduced TapHelper + full test coverage |
| 12 | Version Hotfix | โ Completed | 1 | Fixed 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โ version2.0.0confirmed
๐ 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 Abdulalim โ Backend 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