create-object-pool

为 PHP 8.4 生成对象池模式实现。用于为连接等昂贵资源创建可重用的对象容器,提升资源复用并减少创建开销。包含单元测试。

仓库最近推送
GitHub Stars
109
Forks
26
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "create-object-pool":https://skillpi.com/zh/skills/deepskill-450e95a0aec7c6117fda248cddb2ec7e918ac9fe277c1061586d05a1ae9155d4。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

为 PHP 8.4 生成对象池模式实现。用于为连接等昂贵资源创建可重用的对象容器,提升资源复用并减少创建开销。包含单元测试。

0 下载

介绍来源: third_party · dykyi-roman · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
适合谁
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: create-object-pool
description: Generates Object Pool pattern for PHP 8.4. Creates reusable object containers for expensive resources like connections. Includes unit tests.

Object Pool Pattern Generator

Creates Object Pool pattern infrastructure for managing reusable expensive objects.

When to Use

Scenario Example
Expensive creation Database connections
Limited resources HTTP client handles
Connection reuse Socket connections
Memory management Large object caching

Component Characteristics

PoolInterface

  • Acquire/release semantics
  • Pool lifecycle management
  • Capacity configuration

Pool Implementation

  • Manages available objects
  • Creates on demand
  • Recycles returned objects

Poolable Objects

  • Resettable state
  • Validate before reuse
  • Track usage metrics

Generation Process

Step 1: Generate Core Pool Components

Path: src/Infrastructure/Pool/

  1. PoolInterface.php — Generic pool contract with acquire/release
  2. PoolConfig.php — Configuration value object (min/max size, timeouts)
  3. PoolableInterface.php — Contract for poolable objects (reset, isValid, close)
  4. ObjectPool.php — Generic pool implementation
  5. PooledObject.php — Wrapper tracking usage metrics
  6. PoolExhaustedException.php — Exception for exhausted pool
  7. InvalidPoolObjectException.php — Exception for invalid objects

Step 2: Generate Specialized Pool (if needed)

Path: src/Infrastructure/{Domain}/

  1. {Type}Pool.php — Specialized pool (ConnectionPool, HttpClientPool)
  2. Poolable{Type}.php — Poolable implementation for specific resource

Step 3: Generate Tests

Path: tests/Unit/Infrastructure/Pool/

  1. ObjectPoolTest.php — Core pool functionality tests
  2. {Type}PoolTest.php — Specialized pool tests

File Placement

Component Path
Pool Interface src/Infrastructure/Pool/
Pool Implementation src/Infrastructure/Pool/
Specialized Pools src/Infrastructure/{Domain}/
Unit Tests tests/Unit/Infrastructure/Pool/

Naming Conventions

Component Pattern Example
Interface PoolInterface PoolInterface
Implementation ObjectPool ObjectPool
Poolable Interface PoolableInterface PoolableInterface
Config PoolConfig PoolConfig
Wrapper PooledObject PooledObject
Specialized Pool {Type}Pool ConnectionPool
Test {ClassName}Test ObjectPoolTest

Quick Template Reference

PoolInterface

/**
 * @template T
 */
interface PoolInterface
{
    /** @return T */
    public function acquire(): mixed;
    /** @param T $object */
    public function release(mixed $object): void;
    public function getAvailableCount(): int;
    public function getActiveCount(): int;
    public function getMaxSize(): int;
    public function clear(): void;
}

PoolableInterface

interface PoolableInterface
{
    public function reset(): void;
    public function isValid(): bool;
    public function close(): void;
}

PoolConfig

final readonly class PoolConfig
{
    public function __construct(
        public int $minSize = 0,
        public int $maxSize = 10,
        public int $maxWaitTimeMs = 5000,
        public int $idleTimeoutSeconds = 300,
        public bool $validateOnAcquire = true,
        public bool $validateOnRelease = false
    );

    public static function default(): self;
    public static function forDatabase(): self;
    public static function forHttpClients(): self;
}

Usage Example

// Create pool
$pool = new ObjectPool(
    name: 'database',
    factory: fn() => $connectionFactory->create(),
    config: PoolConfig::forDatabase(),
    logger: $logger
);

// Acquire and release
$connection = $pool->acquire();
try {
    $result = $connection->query('SELECT ...');
} finally {
    $pool->release($connection);
}

// Or use helper
$result = $connectionPool->execute(fn($conn) => $conn->query('SELECT ...'));

Anti-patterns to Avoid

Anti-pattern Problem Solution
No Validation Returning broken objects Validate on acquire
No Reset State leaks between uses Call reset() on release
No Timeout Infinite wait Set maxWaitTime
Unbounded Pool Memory exhaustion Set maxSize
Not Releasing Pool exhaustion Use try/finally
Wrong Scope Per-request pools Use singleton/shared pool

References

For complete PHP templates and examples, see:

  • references/templates.md — All component templates
  • references/examples.md — ConnectionPool, HttpClientPool examples and tests

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值85/100

亮点

  • 提供完整的 PHP 8.4 对象池模式生成方案,包含接口、实现、配置、异常处理和单元测试
  • 适用于数据库连接、HTTP 客户端等昂贵资源管理,具有明确的实用价值和广泛适用性
触发精准95/100

亮点

  • description 明确描述了功能目标和核心用途,触发词精准完整,边界清晰
结构规范95/100

亮点

  • 文档结构清晰完整,包含使用场景、组件特性、生成步骤、文件布局、命名规范、模板参考、使用示例和反模式等多个维度
  • 步骤划分明确,有端到端示例,frontmatter 完整规范
执行可靠85/100

待提升项

  • 缺少具体执行入口 原报告严重程度:轻微

    文档提供了完整的代码模板和生成路径,但未明确说明如何实际执行生成(缺少具体命令或入口点)

    改进建议:建议补充具体的执行命令或入口点说明,如 CLI 命令、API 调用方式等

亮点

  • 提供了完整的 PoolConfig 参数配置,覆盖主要异常情况处理
  • 包含使用示例和最佳实践指导,确保正确使用
证据可验 (前四项均值)90/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。