create-memento
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-memento" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-840469d8736f235dd3970f73fc6eafdb76320437c94708f9376ae4d20d991342. 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 Memento pattern implementation for PHP 8.4. Create state capture and restoration mechanisms for undo/redo functionality, including the originator, memento, and caretaker components. Includes unit tests.
Introduction source: third_party · dykyi-roman · 0.0.1 Reference
SkillPi interpretation
- Tasks
- 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.
- Audience
- | 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 |
- Testing
- Not tested
Browse files
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
Current listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供 PHP 8.4 备忘录模式的完整生成方案,适用于撤销/重做、状态快照等高频场景
- 包含三大核心组件(发起人、备忘录、负责人)及单元测试,实用性强
Highlights
- 触发词精准完整,明确描述生成 Memento 模式用于撤销/重做功能,边界清晰
Highlights
- 文档结构清晰,分步骤生成流程明确,含端到端示例和命名规范
- frontmatter 完整,单文件结构良好,易于理解和执行
Highlights
- 提供完整的 PHP 模板代码,包含 readonly 类、异常处理和内存管理建议
- 工具来源明确,参数正确,覆盖主要异常场景
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.