Download the PHP package sotvokun/webman-aop without Composer
On this page you can find all versions of the php package sotvokun/webman-aop. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package webman-aop
Webman AOP
sotvokun/webman-aop integrates Ray.Aop with Webman and provides an Illuminate-based container. Mark a public service method with an Aspect Attribute and the interceptor is applied automatically when the service is resolved from the container.
Requirements
- PHP 8.3+
- Webman 2.1+
Installation
Webman automatically exports the plugin configuration to config/plugin/sotvokun/webman-aop/ during installation.
Configure the generated proxy directory and directories to scan in config/plugin/sotvokun/webman-aop/app.php:
Create or replace the container in config/container.php with the package container:
Define an Aspect
An Aspect is a PHP Attribute extending Sotvokun\Webman\Aop\Aspect. Its interceptors() method returns interceptor instances or class names.
An interceptor implements Sotvokun\Webman\Aop\MethodInterceptor:
Apply the Aspect to a service method located in a configured scan directory:
Resolve OrderService through Webman's container or constructor injection as usual. No factory call is needed:
Dependency Injection in Interceptors
When interceptors() returns a class name, the package creates it through the Webman container. Constructor dependencies are therefore injected normally:
Returning new ExampleInterceptor() bypasses container construction for that interceptor.
Lazy Injection
Mark a class-typed constructor dependency with #[Sotvokun\Webman\Aop\Attribute\Lazy]. The container injects a proxy and resolves the real service only when its state is first accessed:
The dependency type must be an instantiable, user-defined class with at least one non-static, non-virtual instance property (an inherited property also qualifies). Interfaces, union types, internal classes and their subclasses, and classes with no backed instance property are rejected immediately with a LogicException. Although PHP permits stdClass, it has no declared backed property and is therefore also rejected by this container.
PHP initializes a lazy proxy when its state is observed or changed. A method call that does not access object state does not initialize it. The factory must return a non-lazy instance of the proxy's class (or a compatible parent); the container guarantees this for normal services and for generated Ray.Aop classes.
The consuming service may use AOP attributes. The proxy is injected while the consuming service is constructed, and ReportService remains lazy:
Lazy AOP services
#[Lazy] can be used on a dependency whose public methods have AOP attributes. The container first generates Ray.Aop's child class, then creates the PHP lazy proxy from that generated class. When the service is first initialized, the real object therefore has the same class as its lazy proxy and interceptors remain active:
Constraints
- Only classes under
scan_dirsare considered. - Target classes must be non-final and instantiable.
- Intercepted methods must be
public, non-static, and non-final. - Services must be resolved by the container. Direct
new OrderService()calls bypass AOP. - Ray.Aop writes generated proxy classes to
class_path.
Generated Proxy Cache
Each worker writes proxy classes to class_path/<worker-pid>. When a worker reloads, its replacement has a new PID and generates fresh proxy classes without affecting running workers. Bootstrap clears the entire class_path once per Webman restart, protected by a file lock so multiple workers do not clear it concurrently.
All versions of webman-aop with dependencies
ray/aop Version ^2.20
composer/class-map-generator Version ^1.7
workerman/webman-framework Version ^2.1