create-memento
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "create-memento":https://skillpi.com/zh/skills/deepskill-840469d8736f235dd3970f73fc6eafdb76320437c94708f9376ae4d20d991342。安装前核对上游来源和版本: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-memento
description: Generates Memento pattern for PHP 8.4. Creates state capture and restoration mechanism for undo/redo functionality, with originator, memento, and caretaker components. Includes unit tests.Memento Pattern Generator
Creates Memento pattern infrastructure for capturing and restoring object state without violating encapsulation.
When to Use
| Scenario | Example |
|---|---|
| Undo/Redo functionality | Document editor, form drafts, game state |
| State snapshots | Transaction rollback, checkpoint systems |
| State history tracking | Audit trail, version history |
| Transactional operations | Multi-step processes with rollback |
Component Characteristics
Originator
- Creates memento from current state
- Restores state from memento
- Owns the state being saved
- Knows what to save/restore
Memento
- Stores originator's internal state
- Immutable snapshot (readonly)
- Protects against external access
- Returns state only to originator
Caretaker
- Manages memento history
- Requests state saves
- Triggers state restoration
- Never examines memento contents
Generation Process
Step 1: Generate Memento
Path: src/Domain/{BoundedContext}/Memento/
{Name}Memento.php— Immutable state snapshot
Step 2: Generate Originator
Path: src/Domain/{BoundedContext}/
{Name}.php— Object with createMemento() and restore() methods
Step 3: Generate Caretaker
Path: src/Application/{BoundedContext}/
{Name}History.php— Manages memento stack for undo/redo
Step 4: Generate Value Objects (Optional)
Path: src/Domain/{BoundedContext}/ValueObject/
{State}.php— State representation value object
Step 5: Generate Tests
{Name}MementoTest.php— Memento creation tests{Name}HistoryTest.php— Caretaker undo/redo tests
File Placement
| Component | Path |
|---|---|
| Memento | src/Domain/{BoundedContext}/Memento/ |
| Originator | src/Domain/{BoundedContext}/ |
| Caretaker | src/Application/{BoundedContext}/ |
| Value Objects | src/Domain/{BoundedContext}/ValueObject/ |
| Unit Tests | tests/Unit/Domain/{BoundedContext}/ |
Naming Conventions
| Component | Pattern | Example |
|---|---|---|
| Memento | {Name}Memento |
DocumentMemento |
| Originator | {Name} |
Document |
| Caretaker | {Name}History |
DocumentHistory |
| Create Method | createMemento() |
createMemento() |
| Restore Method | restore() or restoreFromMemento() |
restore() |
| Test | {ClassName}Test |
DocumentMementoTest |
Quick Template Reference
Memento
final readonly class {Name}Memento
{
public function __construct(
private {StateType} $state,
private \DateTimeImmutable $createdAt
) {}
public function state(): {StateType}
{
return $this->state;
}
public function createdAt(): \DateTimeImmutable
{
return $this->createdAt;
}
}
Originator
final class {Name}
{
private {StateType} $state;
public function createMemento(): {Name}Memento
{
return new {Name}Memento(
state: $this->state,
createdAt: new \DateTimeImmutable()
);
}
public function restore({Name}Memento $memento): void
{
$this->state = $memento->state();
}
}
Caretaker
final class {Name}History
{
private array $mementos = [];
private int $currentIndex = -1;
public function save({Name}Memento $memento): void
{
$this->mementos = array_slice($this->mementos, 0, $this->currentIndex + 1);
$this->mementos[] = $memento;
++$this->currentIndex;
}
public function undo(): ?{Name}Memento
{
if ($this->currentIndex > 0) {
--$this->currentIndex;
return $this->mementos[$this->currentIndex];
}
return null;
}
public function redo(): ?{Name}Memento
{
if ($this->currentIndex < count($this->mementos) - 1) {
++$this->currentIndex;
return $this->mementos[$this->currentIndex];
}
return null;
}
}
Usage Example
// Create originator
$document = new Document(content: 'Initial text');
// Create caretaker
$history = new DocumentHistory();
// Save initial state
$history->save($document->createMemento());
// Make changes
$document->setContent('Modified text');
$history->save($document->createMemento());
$document->setContent('Final text');
$history->save($document->createMemento());
// Undo changes
$memento = $history->undo();
if ($memento) {
$document->restore($memento); // Back to 'Modified text'
}
// Redo changes
$memento = $history->redo();
if ($memento) {
$document->restore($memento); // Forward to 'Final text'
}
Common Memento Examples
| Domain | Use Cases |
|---|---|
| Document Editor | Text content, formatting, cursor position |
| Form Management | Draft state, field values, validation state |
| Game Development | Player state, level progress, inventory |
| Order Processing | Order draft, item changes, pricing snapshots |
| Configuration | Settings snapshots, rollback points |
Anti-patterns to Avoid
| Anti-pattern | Problem | Solution |
|---|---|---|
| Mutable memento | State corruption | Use readonly classes |
| Public state access | Breaks encapsulation | Expose only via getters |
| Large state copies | Memory overhead | Store only changed fields |
| Missing timestamp | No audit trail | Include createdAt |
| Unbounded history | Memory leak | Implement history limit |
References
For complete PHP templates and examples, see:
references/templates.md— Memento, Originator, Caretaker templatesreferences/examples.md— Document, Order, Form state management with tests
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 PHP 8.4 备忘录模式的完整生成方案,适用于撤销/重做、状态快照等高频场景
- 包含三大核心组件(发起人、备忘录、负责人)及单元测试,实用性强
亮点
- 触发词精准完整,明确描述生成 Memento 模式用于撤销/重做功能,边界清晰
亮点
- 文档结构清晰,分步骤生成流程明确,含端到端示例和命名规范
- frontmatter 完整,单文件结构良好,易于理解和执行
亮点
- 提供完整的 PHP 模板代码,包含 readonly 类、异常处理和内存管理建议
- 工具来源明确,参数正确,覆盖主要异常场景
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。