create-policy
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "create-policy":https://skillpi.com/zh/skills/deepskill-4362a88e0d601b96363b2844af2b41d9084a1af3379f6868945d6b9292f9b3c4。安装前核对上游来源和版本: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-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
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 策略模式是PHP企业级开发中的核心设计模式,适用于授权、验证等关键业务场景
- 提供了完整的策略模式基础设施,包括接口、实现、结果对象和异常处理
- 包含单元测试生成,确保代码质量和可维护性
亮点
- 触发词精准完整,覆盖多种变体,边界清晰
- 提供了清晰的When to Use场景说明和使用示例
亮点
- Phase/步骤清晰,有出口条件,含端到端示例
- frontmatter完整,单文件≤500行
- 提供了完整的文件放置、命名约定和模板参考
亮点
- 工具来源明确,参数正确,覆盖主要异常
- 不可逆操作有确认机制
- 提供了完整的异常处理和日志记录机制
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。