create-policy
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-policy" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-4362a88e0d601b96363b2844af2b41d9084a1af3379f6868945d6b9292f9b3c4. 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 policy-pattern implementations for PHP 8.4. Create encapsulated business rules for authorization, validation, and domain constraints, and include unit tests.
Introduction source: third_party · dykyi-roman · 0.0.1 Reference
SkillPi interpretation
- Tasks
- Generates Policy pattern for PHP 8.4. Creates encapsulated business rules for authorization, validation, and domain constraints. Includes unit tests.
- Audience
- | Scenario | Example | |----------|---------| | Authorization checks | Can user cancel order? | | Business rule validation | Is discount applicable? | | Complex conditions | Multiple rules combined | | Auditable decisions | Log why access denied |
- Testing
- Not tested
Browse files
Frontmatter
name: create-policy
description: Generates Policy pattern for PHP 8.4. Creates encapsulated business rules for authorization, validation, and domain constraints. Includes unit tests.Policy Pattern Generator
Creates Policy pattern infrastructure for encapsulating business rules and authorization logic.
When to Use
| Scenario | Example |
|---|---|
| Authorization checks | Can user cancel order? |
| Business rule validation | Is discount applicable? |
| Complex conditions | Multiple rules combined |
| Auditable decisions | Log why access denied |
Component Characteristics
PolicyInterface
- Single responsibility rule
- Returns authorization result
- Provides denial reasons
Policy Implementation
- Encapsulates one business rule
- Stateless evaluation
- Composable with other policies
PolicyResult
- Success/failure status
- Denial reasons
- Metadata for logging
Generation Process
Step 1: Generate Shared Components
Path: src/Domain/Shared/Policy/
PolicyResult.php— Result value object with and/or compositionCompositionMode.php— Enum for AllMustPass/AnyMustPass
Step 2: Generate Policy Interface
Path: src/Domain/{BoundedContext}/Policy/
{Name}PolicyInterface.php— Policy contract
Step 3: Generate Concrete Policies
Path: src/Domain/{BoundedContext}/Policy/
{Rule1}Policy.php— First rule implementation{Rule2}Policy.php— Second rule implementation{Name}Policy.php— Composite policy combining rules
Step 4: Generate Exception
Path: src/Domain/Shared/Exception/
PolicyViolationException.php— Exception with policy context
Step 5: Generate Tests
{Rule}PolicyTest.php— Individual rule tests{Name}PolicyTest.php— Composite policy testsPolicyResultTest.php— Result composition tests
File Placement
| Component | Path |
|---|---|
| Policy Interface | src/Domain/{BoundedContext}/Policy/ |
| Policy Implementation | src/Domain/{BoundedContext}/Policy/ |
| PolicyResult | src/Domain/Shared/Policy/ |
| Exception | src/Domain/Shared/Exception/ |
| Unit Tests | tests/Unit/Domain/{BoundedContext}/Policy/ |
Naming Conventions
| Component | Pattern | Example |
|---|---|---|
| Interface | {Name}PolicyInterface |
OrderCancellationPolicyInterface |
| Implementation | {Rule}Policy |
OrderOwnershipPolicy |
| Composite | {Name}Policy |
OrderCancellationPolicy |
| Result | PolicyResult |
PolicyResult |
| Exception | PolicyViolationException |
PolicyViolationException |
| Test | {ClassName}Test |
OrderOwnershipPolicyTest |
Quick Template Reference
PolicyInterface
interface {Name}PolicyInterface
{
public function evaluate({SubjectType} $subject, {ResourceType} $resource): PolicyResult;
public function getRuleName(): string;
}
PolicyResult
final readonly class PolicyResult
{
public static function allow(): self;
public static function deny(string $reason, array $metadata = []): self;
public function isAllowed(): bool;
public function isDenied(): bool;
public function and(self $other): self; // Both must pass
public function or(self $other): self; // Either can pass
}
Policy Implementation
final readonly class {Rule}Policy implements {Name}PolicyInterface
{
public function evaluate({Subject} $subject, {Resource} $resource): PolicyResult
{
if ({condition}) {
return PolicyResult::allow();
}
return PolicyResult::deny('{reason}', ['context' => 'data']);
}
public function getRuleName(): string
{
return '{rule_name}';
}
}
Composite Policy
final readonly class {Name}Policy implements {Name}PolicyInterface
{
public function evaluate({Subject} $subject, {Resource} $resource): PolicyResult
{
return $this->rule1Policy->evaluate($subject, $resource)
->and($this->rule2Policy->evaluate($subject, $resource))
->and($this->rule3Policy->evaluate($subject, $resource));
}
}
Usage Example
// In UseCase
$result = $this->cancellationPolicy->evaluate($user, $order);
if ($result->isDenied()) {
throw new PolicyViolationException(
$this->cancellationPolicy->getRuleName(),
$result->getReason(),
$result->metadata
);
}
$order->cancel($reason);
Anti-patterns to Avoid
| Anti-pattern | Problem | Solution |
|---|---|---|
| Side Effects | Policy modifies state | Keep evaluation pure |
| Boolean Returns | No denial reason | Use PolicyResult |
| Fat Policies | Too many rules | Split into composable policies |
| Hardcoded Values | Can't configure | Inject thresholds |
| No Logging Context | Can't debug | Include metadata |
References
For complete PHP templates and examples, see:
references/templates.md— Policy, composite, result templatesreferences/examples.md— Order cancellation policies and tests
Current listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 策略模式是PHP企业级开发中的核心设计模式,适用于授权、验证等关键业务场景
- 提供了完整的策略模式基础设施,包括接口、实现、结果对象和异常处理
- 包含单元测试生成,确保代码质量和可维护性
Highlights
- 触发词精准完整,覆盖多种变体,边界清晰
- 提供了清晰的When to Use场景说明和使用示例
Highlights
- Phase/步骤清晰,有出口条件,含端到端示例
- frontmatter完整,单文件≤500行
- 提供了完整的文件放置、命名约定和模板参考
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.