Documentation

No matching pages.

API

Config

Facade

Lifecycle

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 uses content-addressed bodies and per-class pointers; a matching source signature skips 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 pointer 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 or no methods are advised. Used by tooling to locate or warm the exact cache file.

Parameters

Name Type Default Description
$ref ReflectionClass -

Return value

  • Type: string|null
  • Description: Absolute path, or null.

pointerFileFor() ·

public function pointerFileFor(ReflectionClass $ref): string|null

Return the target class's pointer file, or null without a cache directory.

Each class keeps one pointer until self::prune() removes it.

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

prune() ·

public function prune(int $olderThanSeconds = 0): array

Remove unreferenced proxy bodies and dangling pointers.

All pointers in the directory define the live set, so pruning works from a cold CLI and across applications. Only Proxy_<hex>.php files are candidates; invalidate OPcache before deleting bodies. Keep uncertain files.

Parameters

Name Type Default Description
$olderThanSeconds int 0 Skip files modified more recently than this.

Return value

  • Type: array

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


Back to the Index