acc-create-proxy
Proxy Pattern Generator
Creates Proxy pattern infrastructure for controlling access to objects.
When to Use
| Scenario | Example |
|---|---|
| Lazy initialization | Load expensive resources on first access |
| Access control | Check permissions before delegating |
| Caching | Cache results of expensive operations |
| Logging | Log calls to real subject |
Component Characteristics
Subject Interface
- Defines operations
- Shared by proxy and real subject
- Enables transparent substitution
Real Subject
- Actual implementation
- Contains business logic
- May be expensive to create
Proxy
- Implements subject interface
- Controls access to real subject
- Adds additional behavior
Generation Process
Step 1: Generate Subject Interface
Path: src/Domain/{BoundedContext}/
{Name}Interface.php— Operations contract
Step 2: Generate Proxy
Path: src/Infrastructure/{BoundedContext}/Proxy/
Lazy{Name}Proxy.php— Lazy initializationCaching{Name}Proxy.php— Result cachingAccessControl{Name}Proxy.php— Permission checksLogging{Name}Proxy.php— Call logging
Step 3: Generate Tests
{ProxyName}Test.php— Proxy behavior verification
File Placement
| Component | Path |
|---|---|
| Subject Interface | src/Domain/{BoundedContext}/ |
| Real Subject | src/Domain/ or src/Infrastructure/ |
| Proxy | src/Infrastructure/{BoundedContext}/Proxy/ |
| Unit Tests | tests/Unit/Infrastructure/{BoundedContext}/Proxy/ |
Naming Conventions
| Component | Pattern | Example |
|---|---|---|
| Subject Interface | {Name}Interface |
RepositoryInterface |
| Real Subject | {Name} |
UserRepository |
| Proxy | {Type}{Name}Proxy |
LazyUserRepositoryProxy |
| Test | {ClassName}Test |
LazyUserRepositoryProxyTest |
Quick Template Reference
Proxy
final class {Type}{Name}Proxy implements {Name}Interface
{
private ?{Name}Interface $realSubject = null;
public function __construct(
private \Closure $factory
) {}
public function {operation}({params}): {returnType}
{
{beforeBehavior}
$result = $this->getRealSubject()->{operation}({args});
{afterBehavior}
return $result;
}
private function getRealSubject(): {Name}Interface
{
if ($this->realSubject === null) {
$this->realSubject = ($this->factory)();
}
return $this->realSubject;
}
}
Usage Example
// Lazy loading proxy
$repository = new LazyUserRepositoryProxy(
fn() => new UserRepository($connection)
);
// Real subject created only on first call
$user = $repository->findById($id);
Common Proxies
| Proxy | Purpose |
|---|---|
| LazyLoadingProxy | Defer expensive object creation |
| CachingProxy | Cache method results |
| AccessControlProxy | Check permissions before execution |
| LoggingProxy | Log all method calls |
| MetricsProxy | Collect performance metrics |
| RetryProxy | Retry failed operations |
Anti-patterns to Avoid
| Anti-pattern | Problem | Solution |
|---|---|---|
| Proxy != Real Subject | Behavior differs | Proxy must be transparent |
| Heavy Proxy | Too much logic | Keep proxies focused |
| Missing Interface | Can't substitute proxy | Use shared interface |
| Leaky State | Proxy state affects behavior | Keep proxies stateless when possible |
| Multiple Responsibilities | Proxy does many things | One proxy, one concern |
References
For complete PHP templates and examples, see:
references/templates.md— Lazy loading, caching, access control proxy templatesreferences/examples.md— Repository, service proxies with unit tests
More from dykyi-roman/awesome-claude-code
psr-overview-knowledge
PHP Standards Recommendations (PSR) overview knowledge base. Provides comprehensive reference for all accepted PSRs including PSR-1,3,4,6,7,11,12,13,14,15,16,17,18,20. Use for PSR selection decisions and compliance audits.
22detect-code-smells
Detects code smells in PHP codebases. Identifies God Class, Feature Envy, Data Clumps, Long Parameter List, Long Method, Primitive Obsession, Message Chains, Inappropriate Intimacy. Generates actionable reports with refactoring recommendations.
15clean-arch-knowledge
Clean Architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Clean Architecture and Hexagonal Architecture audits.
15ddd-knowledge
DDD architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Domain-Driven Design audits.
14testing-knowledge
Testing knowledge base for PHP 8.4 projects. Provides testing pyramid, AAA pattern, naming conventions, isolation principles, DDD testing guidelines, and PHPUnit patterns.
12bug-root-cause-finder
Root cause analysis methods for PHP bugs. Provides 5 Whys technique, fault tree analysis, git bisect guidance, and stack trace parsing.
12