create-decorator
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "create-decorator":https://skillpi.com/zh/skills/deepskill-8d5f0086c15935f69038c64649c85331b21f568034bbad2a2ed2b2c773cc6648。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
为 PHP 8.4 生成装饰器模式实现。创建用于在不使用继承的情况下动态添加行为的包装类结构;同时包含相应的单元测试。
介绍来源: third_party · dykyi-roman · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 适合谁
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: create-decorator
description: Generates Decorator pattern for PHP 8.4. Creates wrapper classes for dynamic behavior addition without inheritance. Includes unit tests.Decorator Pattern Generator
Creates Decorator pattern infrastructure for dynamically adding behavior to objects.
When to Use
| Scenario | Example |
|---|---|
| Cross-cutting concerns | Logging, caching, metrics |
| Transparent wrapping | Add behavior without changing interface |
| Stackable features | Multiple decorators combined |
| Runtime behavior | Dynamic feature addition |
Component Characteristics
Component Interface
- Defines core operations
- Shared by concrete and decorators
- Enables transparent wrapping
Abstract Decorator
- Wraps component
- Delegates to wrapped object
- Base for concrete decorators
Concrete Decorators
- Add specific behavior
- Before/after wrapped call
- Can be stacked
Generation Process
Step 1: Generate Component Interface
Path: src/Domain/{BoundedContext}/
{Name}Interface.php— Core operations contract
Step 2: Generate Abstract Decorator
Path: src/Domain/{BoundedContext}/Decorator/
Abstract{Name}Decorator.php— Base decorator with delegation
Step 3: Generate Concrete Decorators
Path: src/Infrastructure/{BoundedContext}/Decorator/
Logging{Name}Decorator.php— Logging behaviorCaching{Name}Decorator.php— Caching behaviorMetrics{Name}Decorator.php— Performance metricsTransactional{Name}Decorator.php— Transaction wrapping
Step 4: Generate Factory (Optional)
Path: src/Infrastructure/{BoundedContext}/
{Name}Factory.php— Stack decorators in correct order
Step 5: Generate Tests
{Feature}{Name}DecoratorTest.php— Individual decorator tests
File Placement
| Component | Path |
|---|---|
| Interface | src/Domain/{BoundedContext}/ |
| Abstract Decorator | src/Domain/{BoundedContext}/Decorator/ |
| Infrastructure Decorators | src/Infrastructure/{BoundedContext}/Decorator/ |
| Factory | src/Infrastructure/{BoundedContext}/ |
| Unit Tests | tests/Unit/Infrastructure/{BoundedContext}/Decorator/ |
Naming Conventions
| Component | Pattern | Example |
|---|---|---|
| Interface | {Name}Interface |
OrderServiceInterface |
| Abstract Decorator | Abstract{Name}Decorator |
AbstractOrderServiceDecorator |
| Concrete Decorator | {Feature}{Name}Decorator |
LoggingOrderServiceDecorator |
| Factory | {Name}Factory |
OrderServiceFactory |
| Test | {ClassName}Test |
LoggingOrderServiceDecoratorTest |
Quick Template Reference
Why the base is not a readonly class. readonly on a class is inherited-mandatory: every
subclass must also be readonly, and a readonly class cannot hold mutable state. That would forbid
the stateful decorators listed under Common Decorators below — Retry needs an attempt counter,
CircuitBreaker needs open/closed state. So the immutability is applied to the injected
$wrapped property instead, which is where it actually matters. Do not "fix" this by promoting
readonly to the class: final readonly class X extends Abstract…Decorator is a fatal error while
the base is not readonly, and making the base readonly breaks Retry and CircuitBreaker.
Abstract Decorator
abstract class Abstract{Name}Decorator implements {Name}Interface
{
public function __construct(
protected readonly {Name}Interface $wrapped
) {}
public function {operation}({params}): {returnType}
{
return $this->wrapped->{operation}({args});
}
}
Concrete Decorator
final class {Feature}{Name}Decorator extends Abstract{Name}Decorator
{
public function __construct(
{Name}Interface $wrapped,
private {Dependency} $dependency
) {
parent::__construct($wrapped);
}
public function {operation}({params}): {returnType}
{
{beforeBehavior}
$result = parent::{operation}({args});
{afterBehavior}
return $result;
}
}
Usage Example
// Stack decorators in order
$service = new TransactionalOrderServiceDecorator(
new CachingOrderServiceDecorator(
new MetricsOrderServiceDecorator(
new LoggingOrderServiceDecorator(
$baseService,
$logger
),
$metrics
),
$cache
),
$transaction
);
// Use normally - all decorators execute
$order = $service->create($command);
Common Decorators
| Decorator | Purpose |
|---|---|
| Logging | Log method calls and results |
| Caching | Cache expensive operations |
| Metrics | Collect performance metrics |
| Transaction | Wrap in database transaction |
| Retry | Retry failed operations |
| CircuitBreaker | Protect from cascading failures |
| Validation | Validate inputs before execution |
Anti-patterns to Avoid
| Anti-pattern | Problem | Solution |
|---|---|---|
| Missing Interface | Can't swap decorators | Use shared interface |
| Leaky Abstraction | Decorator-specific methods | Keep interface clean |
| Order Dependency | Wrong stacking order | Document decorator order |
| Heavy Decorators | Too much logic | Keep decorators focused |
| No Abstract | Code duplication | Create abstract decorator |
References
For complete PHP templates and examples, see:
references/templates.md— Abstract Decorator, Concrete Decorator, Interface templatesreferences/examples.md— Logging, Caching, Metrics, Transaction decorators and tests
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 PHP 装饰器模式的完整生成方案,涵盖接口、抽象装饰器、具体装饰器和单元测试
- 适用于日志、缓存、事务等常见横切关注点的动态行为添加
亮点
- 触发描述清晰完整,明确指定 PHP 8.4 和装饰器模式生成功能
- 覆盖核心关键词,边界清晰,不易误触
亮点
- 结构完整,包含使用场景、生成步骤、文件布局、命名规范、模板和示例
- 步骤划分清晰,有端到端代码示例和最佳实践指导
待提升项
-
缺少具体执行机制说明 原报告严重程度:轻微
文档描述了生成路径和模板,但未说明如何实际执行生成(如是否需要 CLI 工具、脚本或手动创建)
改进建议:补充执行方式说明,例如提供生成脚本或明确手动创建步骤
亮点
- 文件路径和命名规范清晰,模板代码完整,便于开发者理解和实施
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。