Skip to content

Repository files navigation

Maatify SharedCommon

Latest VersionPHP VersionLicense

PHPStan

ChangelogSecurity

Monthly DownloadsTotal Downloads

Maatify Ecosystem

Install

Overview

The Maatify\SharedCommon module contains foundational contracts and abstractions that are intended to be shared across all Maatify modules (such as AdminKernel, Verification, etc.). Its primary goal is to provide unified interfaces for common cross-cutting concerns like time management, security contexts, permission mapping definitions, and telemetry, enabling consistent behavior and testing across the entire system.

Purpose

By depending on SharedCommon rather than framework-specific implementations or raw PHP functions (like time() or date()), other modules can remain truly framework-agnostic. This module defines the "how we communicate" contracts for basic system realities.

Module Structure

Modules/SharedCommon/
├── Bootstrap/ # Dependency Injection bindings
│ └── SharedCommonBindings.php
├── Contracts/ # Core interfaces for time, telemetry, security, and shared module extensions
│ ├── ClockInterface.php
│ ├── Security/ # Framework-neutral security extension contracts
│ │ ├── PermissionMapProviderInterface.php
│ │ ├── PermissionRequirementDefinition.php
│ │ └── ProvidesPermissionMapsInterface.php
│ ├── SecurityEventContextInterface.php
│ └── TelemetryContextInterface.php
├── Infrastructure/ # Default implementations of contracts
│ └── SystemClock.php
├── Path/ # Common application path resolution utilities
│ └── AppPaths.php
├── docs/ # Architectural and integration documentation
└── composer.json # Standalone package metadata

Quick Usage

To quickly integrate the default implementations of this module into your dependency injection container:

useMaatify\SharedCommon\Bootstrap\SharedCommonBindings;
useDI\ContainerBuilder;
useMaatify\SharedCommon\Contracts\ClockInterface;
$builder = newContainerBuilder();
// Register the bindings for SharedCommon contracts
SharedCommonBindings::register($builder);
$container = $builder->build();
// Resolve the Clock/** @var ClockInterface $clock */$clock = $container->get(ClockInterface::class);
// Get the current time as a DateTimeImmutable object$now = $clock->now();
echo$now->format('Y-m-d H:i:s');

Permission Mapping Contracts

SharedCommon provides framework-neutral permission mapping contracts under:

Maatify\SharedCommon\Contracts\Security

These contracts allow independent Maatify modules to expose route-to-permission requirements without depending on AdminKernel or any application-specific security implementation.

This keeps modules reusable and decoupled while allowing the application or kernel layer to aggregate permission maps and convert them into its own authorization model.

Defining Permission Requirements

Use PermissionRequirementDefinition to describe the permission requirement for a route.

useMaatify\SharedCommon\Contracts\Security\PermissionRequirementDefinition;
$single = PermissionRequirementDefinition::single('payment_methods.list');
$anyOf = PermissionRequirementDefinition::anyOf([
'payment_methods.list',
'payment_methods.dropdown',
]);
$allOf = PermissionRequirementDefinition::allOf([
'payment_methods.update',
'payment_methods.translations.upsert',
]);
$compound = PermissionRequirementDefinition::compound(
anyOf: ['payment_methods.list', 'payment_methods.dropdown'],
allOf: ['admin.access'],
);

Providing a Permission Map from a Module

A module can expose its route permission map by implementing PermissionMapProviderInterface.

<?phpdeclare(strict_types=1);
namespaceMaatify\PaymentMethod\Security;
useMaatify\SharedCommon\Contracts\Security\PermissionMapProviderInterface;
useMaatify\SharedCommon\Contracts\Security\PermissionRequirementDefinition;
finalclass PaymentMethodPermissionMapProvider implements PermissionMapProviderInterface
{
/** * @return array<string, PermissionRequirementDefinition> */publicfunctionpermissionMap(): array
{
return [
'payment_methods.list.ui' => PermissionRequirementDefinition::single('payment_methods.list'),
'payment_methods.list.api' => PermissionRequirementDefinition::single('payment_methods.list'),
'payment_methods.dropdown.api' => PermissionRequirementDefinition::anyOf([
'payment_methods.list',
'payment_methods.dropdown',
]),
'payment_methods.create.api' => PermissionRequirementDefinition::single('payment_methods.create'),
'payment_methods.update.api' => PermissionRequirementDefinition::single('payment_methods.update'),
];
}
}

Exposing Permission Map Providers from a Package

A package or module-level entry point may implement ProvidesPermissionMapsInterface to expose one or more permission map providers.

<?phpdeclare(strict_types=1);
namespaceMaatify\PaymentMethod;
useMaatify\PaymentMethod\Security\PaymentMethodPermissionMapProvider;
useMaatify\SharedCommon\Contracts\Security\PermissionMapProviderInterface;
useMaatify\SharedCommon\Contracts\Security\ProvidesPermissionMapsInterface;
finalclass PaymentMethodPackage implements ProvidesPermissionMapsInterface
{
/** * @return list<PermissionMapProviderInterface> */publicfunctionpermissionMapProviders(): array
{
return [
newPaymentMethodPermissionMapProvider(),
];
}
}

The consuming application or kernel layer is responsible for collecting these providers and converting the neutral definitions into its own authorization objects.


Further Documentation

  • How to Use - Practical integration instructions.
  • Changelog - History and evolution of the module.

Documentation Book

Comprehensive architecture and integration guides are available in the Book:

ChapterDescription
Table of ContentsMain entry point for the documentation book.
01. OverviewThe philosophy and purpose behind SharedCommon.
02. ArchitectureLayering and separation of interfaces and infrastructure.
03. Domain ObjectsCore contracts representing the system state context.
04. Clock AbstractionWhy the ClockInterface is crucial for testability and consistency.
05. Integration PatternsReal-world DI container wiring and cross-module usage.
06. Extension PointsHow to provide application-specific context implementations.

Releases

Packages

Contributors

Languages