定制 maatify/shared-common 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

maatify/shared-common

Composer 安装命令:

composer require maatify/shared-common

包简介

Fundamental contracts and shared abstractions for Maatify modules, including clock and telemetry interfaces.

README 文档

README

Latest Version PHP Version License

PHPStan

Changelog Security

Monthly Downloads Total 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:

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

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.

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

Providing a Permission Map from a Module

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

<?php

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'),
        ];
    }
}

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.

<?php

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(),
        ];
    }
}

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:

Chapter Description
Table of Contents Main entry point for the documentation book.
01. Overview The philosophy and purpose behind SharedCommon.
02. Architecture Layering and separation of interfaces and infrastructure.
03. Domain Objects Core contracts representing the system state context.
04. Clock Abstraction Why the ClockInterface is crucial for testability and consistency.
05. Integration Patterns Real-world DI container wiring and cross-module usage.
06. Extension Points How to provide application-specific context implementations.

maatify/shared-common 适用场景与选型建议

maatify/shared-common 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.13k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 03 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「security」 「common」 「shared」 「clock」 「telemetry」 「contracts」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 maatify/shared-common 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 maatify/shared-common 我们能提供哪些服务?
定制开发 / 二次开发

基于 maatify/shared-common 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.13k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 14
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-11