PHP code example of maatify / shared-common

1. Go to this page and download the library: Download maatify/shared-common library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

maatify / shared-common example snippets


use Maatify\SharedCommon\Bootstrap\SharedCommonBindings;
use DI\ContainerBuilder;
use Maatify\SharedCommon\Contracts\ClockInterface;

$builder = new ContainerBuilder();

// 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');

Maatify\SharedCommon\Contracts\Security

use Maatify\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'],
);



declare(strict_types=1);

namespace Maatify\PaymentMethod\Security;

use Maatify\SharedCommon\Contracts\Security\PermissionMapProviderInterface;
use Maatify\SharedCommon\Contracts\Security\PermissionRequirementDefinition;

final class PaymentMethodPermissionMapProvider implements PermissionMapProviderInterface
{
    /**
     * @return array<string, PermissionRequirementDefinition>
     */
    public function permissionMap(): 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'),
        ];
    }
}



declare(strict_types=1);

namespace Maatify\PaymentMethod;

use Maatify\PaymentMethod\Security\PaymentMethodPermissionMapProvider;
use Maatify\SharedCommon\Contracts\Security\PermissionMapProviderInterface;
use Maatify\SharedCommon\Contracts\Security\ProvidesPermissionMapsInterface;

final class PaymentMethodPackage implements ProvidesPermissionMapsInterface
{
    /**
     * @return list<PermissionMapProviderInterface>
     */
    public function permissionMapProviders(): array
    {
        return [
            new PaymentMethodPermissionMapProvider(),
        ];
    }
}
md
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