These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace ProxyManager\Factory; |
||
6 | |||
7 | use Closure; |
||
8 | use OutOfBoundsException; |
||
9 | use ProxyManager\Configuration; |
||
10 | use ProxyManager\Proxy\AccessInterceptorInterface; |
||
11 | use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator; |
||
12 | use ProxyManager\ProxyGenerator\ProxyGeneratorInterface; |
||
13 | use ProxyManager\Signature\Exception\InvalidSignatureException; |
||
14 | use ProxyManager\Signature\Exception\MissingSignatureException; |
||
15 | use function get_class; |
||
16 | |||
17 | /** |
||
18 | * Factory responsible of producing proxy objects |
||
19 | */ |
||
20 | class AccessInterceptorScopeLocalizerFactory extends AbstractBaseFactory |
||
21 | { |
||
22 | private AccessInterceptorScopeLocalizerGenerator $generator; |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
23 | |||
24 | public function __construct(?Configuration $configuration = null) |
||
25 | { |
||
26 | parent::__construct($configuration); |
||
27 | |||
28 | $this->generator = new AccessInterceptorScopeLocalizerGenerator(); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * @param object $instance the object to be localized within the access interceptor |
||
33 | * @param Closure[] $prefixInterceptors an array (indexed by method name) of interceptor closures to be called |
||
34 | 2 | * before method logic is executed |
|
35 | * @param Closure[] $suffixInterceptors an array (indexed by method name) of interceptor closures to be called |
||
36 | * after method logic is executed |
||
37 | * |
||
38 | * @throws InvalidSignatureException |
||
39 | 2 | * @throws MissingSignatureException |
|
40 | * @throws OutOfBoundsException |
||
41 | 2 | */ |
|
42 | public function createProxy( |
||
43 | object $instance, |
||
44 | array $prefixInterceptors = [], |
||
45 | array $suffixInterceptors = [] |
||
46 | ) : AccessInterceptorInterface { |
||
47 | 1 | $proxyClassName = $this->generateProxy(get_class($instance)); |
|
48 | |||
49 | 1 | return $proxyClassName::staticProxyConstructor($instance, $prefixInterceptors, $suffixInterceptors); |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * {@inheritDoc} |
||
54 | */ |
||
55 | protected function getGenerator() : ProxyGeneratorInterface |
||
56 | { |
||
57 | return $this->generator; |
||
58 | } |
||
59 | } |
||
60 |