定制 monkeyscloud/monkeyslegion-core 二次开发

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

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

monkeyscloud/monkeyslegion-core

Composer 安装命令:

composer require monkeyscloud/monkeyslegion-core

包简介

High-performance framework kernel with typed config, service providers, pipeline, and PHP 8.4 primitives for the MonkeysLegion framework.

README 文档

README

High-performance framework kernel with typed config, service providers, pipeline, and PHP 8.4 primitives for the MonkeysLegion framework.

Features

Feature Status
PHP 8.4 Native Property hooks, backed enums, readonly classes, new in initializers
3 Attributes #[Provider], #[BootAfter], #[Config]
Application Kernel Provider registration, topological boot ordering, lifecycle hooks
Generic Pipeline Immutable, zero-reflection, multi-pipe-type support
Exception Handler Environment-aware: full debug local, sanitized in production
Error Rendering Error Renderer contract + implementation for CLI/debug output
Typed Config Dot-notation, O(1) cached lookups, type-safe getters
Arr Utilities dot/undot, flatten, pluck, groupBy, sortBy, first/last
Str Utilities camel/snake/kebab/studly, slug, UUID/ULID, mask, random (CSPRNG)
Benchmark hrtime precision, memory measurement, comparison
Once (Memoization) Rust-inspired call-once with keyed caching
PSR-20 Clock Testable system clock
20+ Helper Functions env, paths, retry, rescue, tap, value, blank/filled

Requirements

  • PHP 8.4 or higher
  • psr/container ^2.0
  • psr/log ^3.0
  • psr/clock ^1.0

Installation

composer require monkeyscloud/monkeyslegion-core:dev-2.0.0

Architecture

src/
├── Attribute/          # #[Provider], #[BootAfter], #[Config]
├── Clock/              # PSR-20 SystemClock
├── Config/             # Typed ConfigRepository with dot-notation
├── Contract/           # Bootable, Deferrable, ExceptionRendererInterface
├── Environment/        # Backed enum + detector
├── Error/              # Error renderers (interface + plain-text renderer)
├── Exception/          # Handler + HttpException with factories
├── Kernel/             # Application kernel with lifecycle hooks
├── Pipeline/           # Generic pipeline (Laravel parity)
├── Provider/           # ServiceProviderInterface + AbstractProvider
└── Support/            # Arr, Str, Benchmark, Once, helpers.php

Quick Start

Kernel Boot

use MonkeysLegion\Core\Kernel\Kernel;
use MonkeysLegion\Core\Environment\Environment;

$kernel = new Kernel(
    container: $container,
    environment: Environment::Production,
);

$kernel->register(new DatabaseProvider());
$kernel->register(new AuthProvider());
$kernel->boot();

// ... handle request ...

$kernel->terminate();

Service Providers

use MonkeysLegion\Core\Attribute\Provider;
use MonkeysLegion\Core\Attribute\BootAfter;
use MonkeysLegion\Core\Contract\Bootable;
use MonkeysLegion\Core\Provider\AbstractProvider;

#[Provider(priority: 10)]
#[BootAfter(DatabaseProvider::class)]
final class AuthProvider extends AbstractProvider implements Bootable
{
    public function register(): void
    {
        // Register bindings
    }

    public function boot(): void
    {
        // Boot after DatabaseProvider
    }
}

Pipeline

use MonkeysLegion\Core\Pipeline\Pipeline;

$result = (new Pipeline())
    ->send($request)
    ->through([
        TrimStrings::class,
        ValidateInput::class,
        AuthenticateUser::class,
    ])
    ->then(fn($req) => $handler->handle($req));

Config

use MonkeysLegion\Core\Config\ConfigRepository;

$config = new ConfigRepository([
    'database' => [
        'host' => 'localhost',
        'port' => 5432,
    ],
]);

$host = $config->string('database.host');       // 'localhost'
$port = $config->int('database.port');           // 5432
$ssl  = $config->bool('database.ssl', false);    // false

Exception Handling

use MonkeysLegion\Core\Exception\Handler;
use MonkeysLegion\Core\Exception\HttpException;

// In production: generic messages, no stack traces
$handler = new Handler(Environment::Production, $logger);

try {
    throw HttpException::notFound('User not found');
} catch (\Throwable $e) {
    $handler->report($e);
    $response = $handler->render($e);
    // { error: true, status: 404, message: "User not found" }
}

Utilities

use MonkeysLegion\Core\Support\{Arr, Str, Benchmark, Once};

// Arrays
Arr::get($data, 'user.address.city', 'Unknown');
Arr::dot(['a' => ['b' => 1]]);  // ['a.b' => 1]

// Strings
Str::uuid();                    // 'f47ac10b-58cc-...'
Str::slug('Hello World!');      // 'hello-world'
Str::mask('secret123', '*', 3); // 'sec******'
Str::random(32);                // CSPRNG-backed

// Benchmark
$ms = Benchmark::measure(fn() => expensiveQuery(), iterations: 100);

// Memoization
$value = Once::callKeyed('config', fn() => loadConfig());

Performance & Security

Performance

  • ConfigRepository: O(1) cached dot-notation lookups after first access
  • Pipeline: Zero reflection, no container resolution overhead
  • Kernel: Topological sort (Kahn's algorithm) runs once during boot
  • Benchmark: hrtime() for nanosecond precision
  • Arr/Str: Static methods with zero state, minimal allocations

Security

  • Exception Handler: Never exposes stack traces, file paths, or internal details in production
  • Str::random(): CSPRNG-backed via random_int()
  • Str::uuid()/ulid(): CSPRNG-backed via random_bytes()
  • env(): Only reads from server environment, never from user input
  • HttpException: Client-safe messages; internal details via $previous
  • Kernel::terminate(): Catches all exceptions to prevent information leaks
  • Str::mask(): Safely hides sensitive data (tokens, API keys)

Testing

vendor/bin/phpunit --testdox

114 tests, 238 assertions — 100% passing.

License

MIT License. See LICENSE file for details.

monkeyscloud/monkeyslegion-core 适用场景与选型建议

monkeyscloud/monkeyslegion-core 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.51k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 monkeyscloud/monkeyslegion-core 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-10