maatify/common

Common DTOs and helpers for all maatify libraries

Installs: 414

Dependents: 5

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 1

Open Issues: 0

pkg:composer/maatify/common

v1.0.9 2025-11-26 09:29 UTC

This package is auto-updated.

Last update: 2025-11-26 09:32:02 UTC


README

Maatify.dev

๐Ÿ“ฆ maatify/common

Version PHP License Status

Build PHPStan Code Quality

Monthly Downloads Total Downloads Stars

Changelog Security Full Docs Contributing

๐Ÿ Stable Release v1.0.9 โ€” Redis Client Contract Added

The core foundational library of the Maatify.dev ecosystem providing standardized DTOs, validation, sanitization, date/time, locking, text utilities, and now a unified RepositoryInterface powering all Maatify data layers.

๐Ÿ“ฆ This is the stable version (v1.0.8) of maatify/common, released on 2025-11-22. ๐Ÿ”— ุจุงู„ุนุฑุจูŠ ๐Ÿ‡ธ๐Ÿ‡ฆ

๐Ÿงญ Version Information

Key Value
Version 1.0.9 Stable
Release Date 2025-11-26
PHP Requirement โ‰ฅ 8.4
License MIT
Coverage 98 %
Tests Passed 66 (150 Assertions)

๐Ÿงฉ Overview

This library provides reusable, framework-agnostic building blocks (DTOs, helpers, traits, enums, validators, lockingโ€ฆ) shared across all Maatify ecosystem packages such as:

  • maatify/data-adapters
  • maatify/data-fakes
  • maatify/mongo-activity
  • maatify/psr-logger
  • maatify/bootstrap

New in v1.0.9: A unified RedisClientInterface providing a minimal KV API compatible with phpredis, Predis, and FakeRedisConnection.

New in v1.0.8: A unified RepositoryInterface that standardizes CRUD operations across MySQL, Mongo, Redis, Predis, and DBAL repositories.

๐Ÿš€ Whatโ€™s New in v1.0.9 (Phase 17)

โญ Redis Client Contract Added

Phase 17 introduces the RedisClientInterface, a minimal and unified Redis API surface shared across phpredis, Predis, and the in-memory FakeRedisConnection.

โœ” Added

  • RedisClientInterface

    • get()
    • set()
    • del()
    • keys()

โœ” Updated

  • README.full.md
  • API Map
  • roadmap.json
  • CHANGELOG โ†’ v1.0.9
  • VERSION โ†’ 1.0.9
  • Added /docs/phases/README.phase17.md

โœ” Compatibility

  • Fully driver-agnostic (phpredis / predis / fakes)
  • Required for next updates in:
    • maatify/data-fakes (FakeRedis โ†’ full KV compatibility)
    • maatify/data-adapters (RedisAdapter)
    • maatify/data-repository (cache decorators)

๐Ÿš€ Whatโ€™s New in v1.0.8 (Phase 16)

โญ Repository Layer Foundation

Phase 16 introduces a standardized repository contract used across the entire Maatify ecosystem.

โœ” Added

  • RepositoryInterface

    • find()
    • findAll()
    • insert()
    • update()
    • delete()
    • paginate()

โœ” Updated

  • README.full.md
  • API Map
  • roadmap.json
  • CHANGELOG โ†’ v1.0.8
  • VERSION โ†’ 1.0.8
  • Added /docs/phases/README.phase16.md

โœ” Compatibility

  • 100% backward-compatible
  • No breaking changes in existing adapters
  • Required for the upcoming maatify/data-repository package

๐Ÿ“˜ Documentation & Release Files

File Description
/docs/README.full.md Full documentation (Phases 1โ€“17)
/docs/enums.md Enums & constants reference
/docs/phases/README.phase16.md Phase 16 โ€” Repository Layer Foundation
CHANGELOG.md Version history (updated to 1.0.9)
CONTRIBUTING.md Contribution guidelines
VERSION Current version โ†’ 1.0.9

Core Modules:

  • ๐Ÿงฎ Pagination Helpers โ€” PaginationHelper, PaginationDTO, PaginationResultDTO Unified pagination structures for API responses and MySQL queries.

  • ๐Ÿ” Lock System โ€” FileLockManager, RedisLockManager, HybridLockManager Safe execution control for cron jobs, distributed tasks, and queue workers.

  • ๐Ÿงผ Security Sanitization โ€” InputSanitizer, SanitizesInputTrait Clean and escape user input safely with internal HTMLPurifier integration.

  • ๐Ÿง  Core Traits โ€” SingletonTrait, SanitizesInputTrait Reusable traits for singleton pattern, safe input handling, and shared helpers.

  • โœจ Text & Placeholder Utilities โ€” TextFormatter, PlaceholderRenderer, RegexHelper, SecureCompare Powerful text formatting, placeholder rendering, and secure string comparison tools.

  • ๐Ÿ•’ Date & Time Utilities โ€” DateFormatter, DateHelper Humanized difference, timezone conversion, and localized date rendering (EN/AR/FR).

  • ๐Ÿงฉ Validation & Filtering Tools โ€” Validator, Filter, ArrayHelper Email/URL/UUID/Slug validation, input detection, and advanced array cleanup utilities.

  • โš™๏ธ Enums & Constants Standardization โ€” TextDirectionEnum, 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.

  • ๐Ÿ”Œ Redis Client Contract โ€” RedisClientInterface Minimal keyโ€“value Redis abstraction compatible with:

    • phpredis
    • Predis
    • FakeRedisConnection

โš™๏ธ 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/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

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());

๐Ÿ” Lock System

Advanced locking utilities to prevent concurrent executions in Cron jobs, queue workers, or API-critical flows.

๐Ÿ”น Available Managers

Class Type Description
FileLockManager Local File-based lock stored in /tmp or any directory
RedisLockManager Distributed Uses Redis or Predis client for network-safe locking
HybridLockManager Smart Automatically chooses Redis if available, otherwise falls back to file lock
LockCleaner Utility Cleans up stale .lock files after timeouts
LockModeEnum Enum Defines whether lock should EXECUTION (non-blocking) or QUEUE (waits until free)

๐Ÿง  Example 1 โ€” File Lock

use Maatify\Common\Lock\FileLockManager;

$lock = new FileLockManager('/tmp/maatify/cron/report.lock', 600);

if (! $lock->acquire()) {
    exit("Another job is running.\n");
}

echo "Running safely...\n";

$lock->release();

โš™๏ธ Example 2 โ€” Redis Lock

use Maatify\Common\Lock\RedisLockManager;

$lock = new RedisLockManager('cleanup_task', ttl: 600);

if ($lock->acquire()) {
    echo "Cleaning...\n";
    $lock->release();
}

โœ… Works automatically with both phpredis and predis. If Redis is down, it logs an error via maatify/psr-logger.

๐Ÿš€ Example 3 โ€” Hybrid Lock (Recommended)

use Maatify\Common\Lock\HybridLockManager;
use Maatify\Common\Lock\LockModeEnum;

$lock = new HybridLockManager(
    key: 'daily_summary',
    mode: LockModeEnum::QUEUE,
    ttl: 600
);

$lock->run(function () {
    echo "Generating daily summary...\n";
});

Automatically uses Redis if available, otherwise falls back to file lock.

๐Ÿงน Example 4 โ€” Clean Old Locks

use Maatify\Common\Lock\LockCleaner;

LockCleaner::cleanOldLocks(sys_get_temp_dir() . '/maatify/locks', 900);

๐Ÿงพ Notes

  • All lock operations are fully logged (via maatify/psr-logger).
  • Default lock expiration (TTL) is 300 seconds (5 minutes).
  • Hybrid mode retries every 0.5 seconds when using queue mode.

๐Ÿ—‚ Directory (Lock Module)

src/Lock/
โ”œโ”€โ”€ LockInterface.php
โ”œโ”€โ”€ LockModeEnum.php
โ”œโ”€โ”€ FileLockManager.php
โ”œโ”€โ”€ RedisLockManager.php
โ”œโ”€โ”€ HybridLockManager.php
โ””โ”€โ”€ LockCleaner.php

๐Ÿ•’ Cron Lock System (Legacy Section)

This module provides simple yet powerful locking mechanisms to prevent concurrent cron executions.

Available implementations :

  • FileCronLock โ€” lightweight local lock for single-host environments.
  • RedisCronLock โ€” distributed lock using Redis or Predis, automatically disabled if Redis is unavailable.

Interface:

use Maatify\Common\Lock\LockInterface;

Example:

use Maatify\Common\Lock\FileLockManager;

$lock = new FileLockManager('/var/locks/daily_job.lock', 300);

if (! $lock->acquire()) {
    exit("Cron already running...\n");
}

echo "Running job...\n";

// ... job logic ...

$lock->release();

โœ… If Redis or Predis is installed, you can use:

use Maatify\Common\Lock\RedisLockManager;

$lock = new RedisLockManager('daily_job');
if ($lock->acquire()) {
    // do work
    $lock->release();
}

Redis version automatically logs a warning (and safely disables itself) if Redis isnโ€™t available.

๐Ÿงผ Input Sanitization

Use Maatify\Common\Security\InputSanitizer to clean any user or system input safely.

use Maatify\Common\Security\InputSanitizer;

echo InputSanitizer::sanitize('<script>alert(1)</script>', 'output');
// Output: &lt;script&gt;alert(1)&lt;/script&gt;

โœจ Text & Placeholder Utilities

Reusable text manipulation and safe string utilities shared across all Maatify libraries.

๐Ÿ”น PlaceholderRenderer

Safely render nested placeholders within templates.

use Maatify\Common\Text\PlaceholderRenderer;

$template = 'Hello, {{user.name}} ({{user.email}})';
$data = ['user' => ['name' => 'Mohamed', 'email' => 'm@maatify.dev']];

echo PlaceholderRenderer::render($template, $data);
// Output: Hello, Mohamed (m@maatify.dev)

๐Ÿ”น TextFormatter

Normalize, slugify, or title-case strings consistently across platforms.

use Maatify\Common\Text\TextFormatter;

TextFormatter::slugify('Hello World!');      // hello-world
TextFormatter::normalize('ร„ร–รœรŸ Test');       // aeoeuess-test
TextFormatter::titleCase('maatify common');  // Maatify Common

๐Ÿ”น RegexHelper

Convenient wrapper for regex operations.

use Maatify\Common\Text\RegexHelper;

RegexHelper::replace('/\d+/', '#', 'Item123'); // Item#

๐Ÿ”น SecureCompare

Timing-safe string comparison for token or signature checks.

use Maatify\Common\Text\SecureCompare;

if (SecureCompare::equals($provided, $stored)) {
    echo 'Tokens match safely.';
}

โœ… Includes full unit test coverage (tests/Text/*)
โœ… Cross-platform transliteration with fallback normalization
โœ… Used by other Maatify libraries for formatting, matching, and signature checks

๐Ÿ—‚ Directory (Text Utilities)

src/Text/
โ”œโ”€โ”€ PlaceholderRenderer.php
โ”œโ”€โ”€ TextFormatter.php
โ”œโ”€โ”€ RegexHelper.php
โ””โ”€โ”€ SecureCompare.php

๐Ÿ”ง Tip: These utilities are internally leveraged by maatify/i18n, maatify/security, and maatify/queue-manager for consistent text normalization, placeholder expansion, and token validation.

๐Ÿ•’ Date & Time Utilities

Reusable date and time formatting utilities with localization and humanized difference support.

use Maatify\Common\Date\DateFormatter;
use Maatify\Common\Date\DateHelper;
use DateTime;
๐Ÿ”น Humanize Difference

Convert two timestamps into a natural, human-friendly expression:

$a = new DateTime('2025-11-09 10:00:00');
$b = new DateTime('2025-11-09 09:00:00');

echo DateFormatter::humanizeDifference($a, $b, 'en'); // "1 hour(s) ago"
echo DateFormatter::humanizeDifference($a, $b, 'ar'); // "ู…ู†ุฐ 1 ุณุงุนุฉ"
๐Ÿ”น Localized Date String

Format any DateTime into a locale-aware representation:

$date = new DateTime('2025-11-09 12:00:00');
echo DateHelper::toLocalizedString($date, 'ar', 'Africa/Cairo'); // ูฉ ู†ูˆูู…ุจุฑ ูขู ูขูฅุŒ ูข:ู ู  ู…
echo DateHelper::toLocalizedString($date, 'en', 'America/New_York'); // November 9, 2025, 7:00 AM

โœ… Supports English (en), Arabic (ar), and French (fr) locales
โœ… Handles timezone conversion and localized month/day names automatically
โœ… Backed by IntlDateFormatter for precise localization
โœ… Fully covered with unit tests (tests/Date/*)

๐Ÿ—‚ Directory (Date Utilities)

src/Date/
โ”œโ”€โ”€ DateFormatter.php
โ””โ”€โ”€ DateHelper.php

๐Ÿงฉ Validation & Filtering Utilities

Reusable validation, filtering, and array manipulation tools for ensuring clean and consistent input data across maatify projects.

use Maatify\Common\Validation\Validator;
use Maatify\Common\Validation\Filter;
use Maatify\Common\Validation\ArrayHelper;
๐Ÿ”น Validation

Perform quick and reliable validation for various input types:

Validator::email('user@maatify.dev');              // โœ… true
Validator::url('https://maatify.dev');             // โœ… true
Validator::ip('192.168.1.1');                      // โœ… true
Validator::uuid('123e4567-e89b-12d3-a456-426614174000'); // โœ… true
Validator::slug('maatify-core');                   // โœ… true
Validator::slugPath('en/gift-card/itunes-10-usd'); // โœ… true
๐Ÿ”น Numeric & Range Validation
Validator::integer('42');           // โœ… true
Validator::float('3.14');           // โœ… true
Validator::between(5, 1, 10);       // โœ… true
Validator::phone('+201234567890');  // โœ… true
๐Ÿ”น Auto Type Detection

Smart helper that detects the type of input automatically:

Validator::detectType('test@maatify.dev');     // 'email'
Validator::detectType('maatify-core');         // 'slug'
Validator::detectType('en/gift-card/item');    // 'slug_path'
Validator::detectType('42');                   // 'integer'
Validator::detectType('3.14');                 // 'float'
Validator::detectType('unknown-data');         // null

โœ… Detects and differentiates between slug and slug_path
โœ… Useful for dynamic API validation or auto-form field type detection

๐Ÿ”น Filtering

Simplify array cleaning before validation or persistence:

$data = [
    'name' => '  Mohamed  ',
    'email' => ' ',
    'bio' => '<b>Hello</b>',
    'age' => null
];

$clean = Filter::sanitizeArray($data);

// Output:
[
    'name' => 'Mohamed',
    'bio'  => '<b>Hello</b>'
]

Available methods:

  • Filter::trimArray(array $data)
  • Filter::removeEmptyValues(array $data)
  • Filter::sanitizeArray(array $data)
๐Ÿ”น Array Helper

Manipulate associative arrays in a functional and elegant way:

$data = [
    'user' => ['id' => 1, 'name' => 'Mohamed'],
    'meta' => ['role' => 'admin', 'active' => true]
];

ArrayHelper::flatten($data);
// ['user.id' => 1, 'user.name' => 'Mohamed', 'meta.role' => 'admin', 'meta.active' => true]

ArrayHelper::only($data, ['user.name']);
// ['user' => ['name' => 'Mohamed']]

ArrayHelper::except($data, ['meta']);
// ['user' => ['id' => 1, 'name' => 'Mohamed']]

โœ… Fully covered by unit tests (tests/Validation/*)
โœ… Integrated slugPath detection for multilingual slugs
โœ… Ideal for preparing request payloads or DTO normalization

๐Ÿ—‚ Directory (Validation Utilities)

src/Validation/
โ”œโ”€โ”€ Validator.php
โ”œโ”€โ”€ Filter.php
โ””โ”€โ”€ ArrayHelper.php

โš™๏ธ Enums & Constants Standardization

Centralized, reusable enumerations and constants shared across all Maatify libraries โ€” ensuring unified configuration, predictable behavior, and simplified maintenance.

๐Ÿ”น TextDirectionEnum

Defines text layout direction for UI and localization logic.

use Maatify\Common\Enums\TextDirectionEnum;

echo TextDirectionEnum::LTR->value; // 'ltr'

๐Ÿ”น MessageTypeEnum

Standard system message types used in API responses, logs, and alerts.

use Maatify\Common\Enums\MessageTypeEnum;

echo MessageTypeEnum::ERROR->value; // 'error'

๐Ÿ”น ErrorCodeEnum

Provides globally standardized error identifiers across all Maatify modules.

use Maatify\Common\Enums\ErrorCodeEnum;

throw new Exception('Invalid input', ErrorCodeEnum::INVALID_INPUT->value);

๐Ÿ”น PlatformEnum & AppEnvironmentEnum

Enumerations for defining runtime context and environment configuration.

use Maatify\Common\Enums\PlatformEnum;
use Maatify\Common\Enums\AppEnvironmentEnum;

echo PlatformEnum::WEB->value;          // 'web'
echo AppEnvironmentEnum::PRODUCTION->value; // 'production'

๐Ÿ”น EnumHelper

Smart utility class that unifies enum operations like retrieving names, values, and validating entries.

use Maatify\Common\Enums\EnumHelper;
use Maatify\Common\Enums\MessageTypeEnum;

$names  = EnumHelper::names(MessageTypeEnum::class);
$values = EnumHelper::values(MessageTypeEnum::class);
$isValid = EnumHelper::isValidValue(MessageTypeEnum::class, 'success'); // true

๐Ÿ”น EnumJsonSerializableTrait

Provides automatic JSON serialization for any Enum.

use Maatify\Common\Enums\Traits\EnumJsonSerializableTrait;
use Maatify\Common\Enums\MessageTypeEnum;

echo json_encode(MessageTypeEnum::SUCCESS); // 'success'

๐Ÿ”น Constants Classes

Organized constants for system-wide settings.

use Maatify\Common\Constants\CommonPaths;
use Maatify\Common\Constants\Defaults;

echo CommonPaths::LOG_PATH;          // '/storage/logs'
echo Defaults::DEFAULT_TIMEZONE;     // 'Africa/Cairo'

โœ… Full PHPUnit coverage (tests/Enums/*)
โœ… EnumHelper & Trait verified for stability
โœ… Consistent naming and values across all modules

๐Ÿ”Œ Redis Client Interface (Phase 17)

A unified minimal KV API that works across:

  • phpredis
  • Predis
  • FakeRedisConnection (tests)

๐Ÿ”น Example โ€” Get & Set

use Maatify\Common\Contracts\Redis\RedisClientInterface;

/** @var RedisClientInterface $redis */
$redis->set('token', 'abc123');

echo $redis->get('token'); // abc123

๐Ÿ”น Example โ€” Delete Many

$deleted = $redis->del('a', 'b', 'c');
// returns number of deleted keys

๐Ÿ”น Example โ€” Pattern Keys

print_r($redis->keys('user:*'));

๐Ÿ—‚ Directory (Enums & Constants)

src/Enums/
โ”œโ”€โ”€ TextDirectionEnum.php
โ”œโ”€โ”€ MessageTypeEnum.php
โ”œโ”€โ”€ ErrorCodeEnum.php
โ”œโ”€โ”€ PlatformEnum.php
โ”œโ”€โ”€ AppEnvironmentEnum.php
โ”œโ”€โ”€ EnumHelper.php
โ””โ”€โ”€ Traits/
    โ””โ”€โ”€ EnumJsonSerializableTrait.php

src/Constants/
โ”œโ”€โ”€ CommonPaths.php
โ”œโ”€โ”€ CommonLimits.php
โ”œโ”€โ”€ CommonHeaders.php
โ””โ”€โ”€ Defaults.php

๐Ÿงฉ 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
โ”œโ”€โ”€ Lock/
โ”‚   โ”œโ”€โ”€ LockInterface.php
โ”‚   โ”œโ”€โ”€ LockModeEnum.php
โ”‚   โ”œโ”€โ”€ FileLockManager.php
โ”‚   โ”œโ”€โ”€ RedisLockManager.php
โ”‚   โ”œโ”€โ”€ HybridLockManager.php
โ”‚   โ””โ”€โ”€ LockCleaner.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, lock, 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 โ†’ 16)

Phase Title Status Files Created Notes
1 Pagination Module โœ… Completed 3 Pagination DTOs & helpers
2 Locking System โœ… Completed 6 File / Redis / Hybrid lock managers
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
9 Logger Stability Update โœ… Completed 1 PSR-3 fallback logger improvements for HybridLockManager
10 TapHelper Utility โœ… Completed 1 Introduced TapHelper + full test coverage
11 Connectivity Foundation โœ… Completed 3 ConnectionConfigDTO, ConnectionTypeEnum, improved DSN handling
12 Version Hotfix โœ… Completed 1 Fixed version mismatch and updated VERSION file
13 Mutable ConnectionConfigDTO โœ… Completed 2 Removed readonly, added runtime overrides, enhanced DSN flexibility
14 Driver Contract Modernization โœ… Completed 4 Multi-driver AdapterInterface support (PDO, DBAL, MongoDB, Redis, Predis)
15 Redis Lock Testing Stability Update (v1.0.7) โœ… Completed 3 FakeRedisConnection, improved FakeHealthyAdapter, realistic TTL simulation, fully deterministic lock tests
16 Repository Layer Foundation (v1.0.8) โœ… Completed 1 Added RepositoryInterface with full CRUD contract + pagination & filters

โœ… 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)

๐Ÿงพ Release Verification โ€” v1.0.9 (Phase 17)

Redis Client Contract

โญ v1.0.9 โ€” Unified Redis Client API

๐Ÿ”ง Added

  • src/Contracts/Redis/RedisClientInterface.php
  • Unified driver-agnostic Redis interface:
    • get
    • set
    • del
    • keys

โœ” Updated

  • README.md
  • README.full.md
  • CHANGELOG.md โ†’ v1.0.9
  • VERSION โ†’ 1.0.9
  • Roadmap (phase17)
  • Full phase doc โ†’ docs/phases/README.phase17.md

๐Ÿงช Tests

  • Verified compatibility with FakeRedisConnection
  • Signature-safe with Predis/PhpRedis mocks
  • No breaking changes

๐Ÿงฉ Final Status

Phase 17 is completed successfully. Unified RedisClientInterface is now part of maatify/common and ready for integration with the ecosystem.

๐Ÿงพ Release Verification โ€” v1.0.8 (Phase 16)

Repository Layer Foundation

โญ v1.0.8 โ€” RepositoryInterface Introduction & Core Repository Architecture

โœ” Whatโ€™s New

This release introduces the first unified repository contract inside maatify/common, providing a clean, cross-adapter CRUD standard for all upcoming libraries.

๐Ÿ”ง Added

  • Maatify\Common\Contracts\RepositoryInterface

    • find(int|string $id): ?array
    • findAll(array $filters = []): array
    • insert(array $data): int|string
    • update(int|string $id, array $data): bool
    • delete(int|string $id): bool
    • paginate(int $page, int $perPage, array $filters = []): PaginationResultDTO
  • Added Phase 16 documentation:

    • docs/phases/README.phase16.md
  • Updated:

    • README.md
    • README.full.md
    • CHANGELOG.md โ†’ now includes v1.0.8
    • VERSION โ†’ updated from 1.0.7 โ†’ 1.0.8

๐Ÿงช Test Consistency

All existing tests remained 100% green, repository layer introduces no breaking changes.

๐Ÿ›  Compatibility Notes

  • Fully backward compatible
  • Ready foundation for maatify/data-repository library (Phase 17+)
  • Works seamlessly with MySQL / Mongo / Redis adapters

โœ… Files Verified in Phase 16 (v1.0.8)

File Status
src/Contracts/RepositoryInterface.php โœ” Added
docs/phases/README.phase16.md โœ” Added
README.md โœ” Updated
README.full.md โœ” Updated
CHANGELOG.md โœ” Updated
VERSION โœ” Updated to 1.0.8

๐Ÿงฉ Final Status

Phase 16 is completed successfully. Repository Interface is now part of the Maatify Common Core and ready for integration with higher-level repository libraries.

All files have been verified and finalized as part of Phase 15 (v1.0.7 Stable).

  • โœ… /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 1.0.7 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 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