create-prototype
Generates Prototype pattern implementations for PHP 8.4. Creates deep/shallow copy, clone customization, prototype registries, and immutable object duplication.
Best use case
create-prototype is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Generates Prototype pattern implementations for PHP 8.4. Creates deep/shallow copy, clone customization, prototype registries, and immutable object duplication.
Teams using create-prototype should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/create-prototype/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How create-prototype Compares
| Feature / Agent | create-prototype | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Generates Prototype pattern implementations for PHP 8.4. Creates deep/shallow copy, clone customization, prototype registries, and immutable object duplication.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Prototype Pattern Generator
Generate Prototype pattern implementations for PHP 8.4 with proper deep/shallow copy semantics.
## Pattern Overview
Prototype creates new objects by cloning existing instances, avoiding costly construction and enabling runtime object configuration.
## Generation Templates
### 1. Basic Prototype with Clone
```php
<?php
declare(strict_types=1);
namespace {Namespace}\Domain\{Context};
final class {Name} implements \Cloneable
{
public function __construct(
private readonly {IdType} $id,
private string $title,
private array $metadata,
private \DateTimeImmutable $createdAt,
) {}
public function __clone(): void
{
// Deep copy mutable objects
$this->createdAt = clone $this->createdAt;
// Arrays are copied by value (shallow), but nested objects need cloning
$this->metadata = array_map(
fn (mixed $item) => is_object($item) ? clone $item : $item,
$this->metadata,
);
}
public function withTitle(string $title): self
{
$clone = clone $this;
$clone->title = $title;
return $clone;
}
public function withMetadata(array $metadata): self
{
$clone = clone $this;
$clone->metadata = $metadata;
return $clone;
}
}
```
### 2. Prototype Registry
```php
<?php
declare(strict_types=1);
namespace {Namespace}\Domain\{Context};
final class {Name}PrototypeRegistry
{
/** @var array<string, {Name}> */
private array $prototypes = [];
public function register(string $key, {Name} $prototype): void
{
$this->prototypes[$key] = $prototype;
}
public function create(string $key): {Name}
{
if (!isset($this->prototypes[$key])) {
throw new \InvalidArgumentException(
sprintf('Prototype "%s" not registered. Available: %s', $key, implode(', ', array_keys($this->prototypes))),
);
}
return clone $this->prototypes[$key];
}
public function has(string $key): bool
{
return isset($this->prototypes[$key]);
}
/** @return list<string> */
public function keys(): array
{
return array_keys($this->prototypes);
}
}
```
### 3. Immutable Value Object Prototype
```php
<?php
declare(strict_types=1);
namespace {Namespace}\Domain\{Context}\ValueObject;
final readonly class {Name}
{
public function __construct(
private string $currency,
private int $amount,
private string $locale,
) {}
// Immutable "clone" via named constructors
public function withAmount(int $amount): self
{
return new self(
currency: $this->currency,
amount: $amount,
locale: $this->locale,
);
}
public function withCurrency(string $currency): self
{
return new self(
currency: $currency,
amount: $this->amount,
locale: $this->locale,
);
}
// Factory from prototype
public static function fromPrototype(self $prototype, int $amount): self
{
return new self(
currency: $prototype->currency,
amount: $amount,
locale: $prototype->locale,
);
}
}
```
### 4. Deep Clone with Object Graph
```php
<?php
declare(strict_types=1);
namespace {Namespace}\Domain\{Context};
final class {Name}
{
/** @var list<{ChildType}> */
private array $children;
public function __construct(
private readonly {IdType} $id,
private {ConfigType} $config,
array $children = [],
) {
$this->children = $children;
}
public function __clone(): void
{
// Deep clone config object
$this->config = clone $this->config;
// Deep clone collection of children
$this->children = array_map(
fn ({ChildType} $child): {ChildType} => clone $child,
$this->children,
);
}
public function duplicate({IdType} $newId): self
{
$clone = clone $this;
// Use reflection for readonly property if needed
$ref = new \ReflectionProperty($clone, 'id');
$ref->setValue($clone, $newId);
return $clone;
}
}
```
## Detection Patterns (Audit)
```bash
# Missing __clone on classes with mutable properties
Grep: "class.*\{" --glob "**/Domain/**/*.php"
# Then check for mutable object properties without __clone
# Shallow copy issues (clone without __clone)
Grep: "clone \$this" --glob "**/*.php"
Grep: "function __clone" --glob "**/*.php"
# Manual copy-paste construction (prototype candidate)
Grep: "new self\(.*\$this->" --glob "**/*.php"
# Prototype registry candidates
Grep: "array.*prototype|registry.*clone" --glob "**/*.php"
```
## Anti-Patterns to Avoid
```php
// BAD: Serialization for deep copy (slow, breaks resources)
$clone = unserialize(serialize($original));
// BAD: No __clone with mutable objects
$clone = clone $original;
$clone->getAddress()->setCity('New'); // Modifies original!
// BAD: Clone readonly object without proper handling
final readonly class Order
{
// Cannot modify properties after clone!
// Use "with" methods returning new instances instead
}
```
## Output Format
```markdown
### Prototype Pattern: {Name}
**Files Generated:**
- `src/Domain/{Context}/{Name}.php` — Prototype with __clone
- `src/Domain/{Context}/{Name}PrototypeRegistry.php` — Registry (if needed)
**Clone Strategy:**
- Deep copy: [list mutable properties]
- Shallow copy: [list immutable/scalar properties]
- Readonly: [list readonly properties — use with* methods]
```Related Skills
create-visitor
Generates Visitor pattern for PHP 8.4. Creates operations on object structures without modifying element classes, with visitor interface, concrete visitors, and visitable elements. Includes unit tests.
create-value-object
Generates DDD Value Objects for PHP 8.4. Creates immutable, self-validating objects with equality comparison. Includes unit tests.
create-use-case
Generates Application Use Cases for PHP 8.4. Creates orchestration services that coordinate domain objects, handle transactions, and dispatch events. Includes unit tests.
create-unit-test
Generates PHPUnit unit tests for PHP 8.4. Creates isolated tests with AAA pattern, proper naming, attributes, and one behavior per test. Supports Value Objects, Entities, Services.
create-unit-of-work
Generates Unit of Work pattern components for PHP 8.4. Creates transactional consistency infrastructure with aggregate tracking, flush/rollback, domain event collection, and unit tests.
create-timeout
Generates Timeout pattern components for PHP 8.4. Creates execution time limit infrastructure with configurable timeouts, fallback support, stream timeouts, and unit tests.
create-test-double
Generates test doubles (Mocks, Stubs, Fakes, Spies) for PHP 8.4. Creates appropriate double type based on testing needs with PHPUnit MockBuilder patterns.
create-test-builder
Generates Test Data Builder and Object Mother patterns for PHP 8.4. Creates fluent builders with sensible defaults and factory methods for test data creation.
create-template-method
Generates Template Method pattern for PHP 8.4. Creates abstract algorithm skeleton with customizable steps, allowing subclasses to override specific parts without changing structure. Includes unit tests.
create-structured-logger
Generates Structured Logger for PHP 8.4. Creates PSR-3 structured logging setup with Monolog processors, correlation ID propagation, and context middleware. Includes unit tests.
create-strategy
Generates Strategy pattern for PHP 8.4. Creates interchangeable algorithm families with context class, strategy interface, and concrete implementations. Includes unit tests.
create-state
Generates State pattern for PHP 8.4. Creates state machines with context, state interface, and concrete states for behavior changes. Includes unit tests.