Class: ProxyFactory
Full name: Azera\Aop\ProxyFactory
Builds proxies that run advised methods through interceptor pipelines.
A proxy extends the target and is the service instance. Overridden methods
delegate to parent::method(); unadvised methods remain inherited.
buildProxyClass() memoizes by namespace and target class before reflection,
then checks for a loaded class before file I/O. Disk caching keeps one file per
class whose metadata header lets a warm load skip generation.
Deterministic class names allow OPcache reuse (see loadCachedProxyClass()).
With no interceptors registered, no proxy is built. An unadvised class costs one attribute check; an advised class with no advised methods costs one reflection scan and returns the raw target.
Public methods
register() ·
public function register(string $adviceClass, Azera\Aop\InterceptorInterface $interceptor): void
Register the interceptor for one advice class, replacing any previous one.
The resolved map is published to AopRuntime so generated proxies can
resolve their precomposed chains without holding a factory reference.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$adviceClass |
string | - | |
$interceptor |
InterceptorInterface | - |
Return value
- Type:
void
namespaceFor() ·
public static function namespaceFor(string|null $dir): string
The namespace a factory publishing from $dir will use.
Static and single-sourced: the namespace is baked into generated source and keys the proxy files, so a caller reasoning about a directory it has no factory for (a maintenance command) must derive exactly the same string. Normalisation lives here, not in each caller.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$dir |
string|null | - | Cache directory, or null for eval(). |
Return value
- Type:
string
namespace() ·
public function namespace(): string
The namespace this factory publishes under.
Lazily derived so register() before setCacheDir() still lands somewhere
sane, and so setCacheDir() can move a factory to its final namespace.
AppContext::proxyFactory() sets the directory first, then registers.
Return value
- Type:
string
setCacheDir() ·
public function setCacheDir(string|null $dir): void
Set the cache directory for file-based proxy generation.
When set, proxy classes are written to disk as PHP files and required,
allowing OPcache to cache them. When null (default), eval() is used.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$dir |
string|null | - | Cache directory, or null to use eval(). |
Return value
- Type:
void
getCacheDir() ·
public function getCacheDir(): string|null
Return value
- Type:
string|null
hasInterceptors() ·
public function hasInterceptors(): bool
Return value
- Type:
bool
proxyPath() ·
public function proxyPath(ReflectionClass $ref): string|null
Return the proxy file path, or null when disk caching is disabled.
The path depends on the namespace and target class only, so tooling can locate or warm the exact cache file without generating anything.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$ref |
ReflectionClass | - |
Return value
- Type:
string|null
buildProxyClass() ·
public function buildProxyClass(ReflectionClass $ref): string|null
Build a proxy class, or return null if no methods need interception.
Disk-backed proxies are required from file for OPcache; eval mode creates an anonymous class.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$ref |
ReflectionClass | - |
Return value
- Type:
string|null
isCurrentProxyFile() ·
public static function isCurrentProxyFile(string $path): bool
Return whether a proxy file carries a header this generator can read.
A file without one was written by an earlier layout and will be replaced in
place the next time its class is proxied; nothing reads it. Exposed so
cache:status counts those leftovers from a cold CLI, without reimplementing
the header format or needing a class list.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$path |
string | - |
Return value
- Type:
bool
getInterceptor() ·
public function getInterceptor(string $adviceClass): Azera\Aop\InterceptorInterface
Return the interceptor registered for an advice class.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$adviceClass |
string | - |
Return value
- Type: InterceptorInterface