create-decorator
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "create-decorator" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-8d5f0086c15935f69038c64649c85331b21f568034bbad2a2ed2b2c773cc6648. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Generate a Decorator pattern implementation for PHP 8.4. Create wrapper class structures to dynamically add behavior without using inheritance, and include corresponding unit tests.
Introduction source: third_party · dykyi-roman · 0.0.1 Reference
SkillPi interpretation
- Tasks
- Generates Decorator pattern for PHP 8.4. Creates wrapper classes for dynamic behavior addition without inheritance. Includes unit tests.
- Audience
- | 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 |
- Testing
- Not tested
Browse files
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
Current listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供 PHP 装饰器模式的完整生成方案,涵盖接口、抽象装饰器、具体装饰器和单元测试
- 适用于日志、缓存、事务等常见横切关注点的动态行为添加
Highlights
- 触发描述清晰完整,明确指定 PHP 8.4 和装饰器模式生成功能
- 覆盖核心关键词,边界清晰,不易误触
Highlights
- 结构完整,包含使用场景、生成步骤、文件布局、命名规范、模板和示例
- 步骤划分清晰,有端到端代码示例和最佳实践指导
Areas to improve
-
缺少具体执行机制说明 Reported severity: Minor
文档描述了生成路径和模板,但未说明如何实际执行生成(如是否需要 CLI 工具、脚本或手动创建)
Recommendation: 补充执行方式说明,例如提供生成脚本或明确手动创建步骤
Highlights
- 文件路径和命名规范清晰,模板代码完整,便于开发者理解和实施
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.