private function getProxyListFixtures() { $serviceReflectionClass = new ReflectionClass(FooService::class); $aspectReflectionClass = new ReflectionClass(FooAspect::class); $proxyList = new ProxyList(); $joinpoint = new Joinpoint($serviceReflectionClass->getMethod('foo')); $advice = new Advice(new BeforePointcut(new PointcutExpression('\\AOP\\Before')), new InterceptingMethod($aspectReflectionClass->getMethod('fooAdvice'))); $aspectDefinition = new ArrayServiceDefinition(array('serviceId' => 'fooService', 'class' => FooAspect::class)); $joinpointsAdvices = new Map(); $joinpointsAdvices->put($joinpoint, new ArrayList()); $joinpointsAdvices->getValue($joinpoint)->put([$advice, $aspectDefinition]); $proxyList->addProxy(new Proxy($joinpointsAdvices, new ArrayServiceDefinition(array('serviceId' => 'fooService', 'class' => '\\FooService')))); return $proxyList; }
/** * @param ServiceDefinition[] $aspectDefinitions * @param ServiceDefinition[] $targetDefinitions * @return ProxyList */ public function findProxies(array $aspectDefinitions, array $targetDefinitions) { $proxyList = new ProxyList(); foreach ($targetDefinitions as $targetDefinition) { $advicesJoinpoints = new Map(); foreach ($aspectDefinitions as $aspectDefinition) { $aspect = $this->aspectReflection->getAspect(new ReflectionClass($aspectDefinition->getClassName())); $advices = $aspect->getAdvices(); foreach ($advices as $advice) { $pointcutExpression = $advice->getPointcut()->getPointcutExpression(); $joinpoints = $this->pointcutExpressionResolver->findJoinpoints(new ReflectionClass($targetDefinition->getClassName()), $pointcutExpression); if (count($joinpoints)) { $advicesJoinpoints->put($advice, [$joinpoints, $aspectDefinition]); } } } $groupedJoinpoints = $this->groupByJoinpoints($advicesJoinpoints); if (count($groupedJoinpoints)) { $proxyList->addProxy(new Proxy($groupedJoinpoints, $targetDefinition)); } } return $proxyList; }
/** * @return ProxyList */ private function getExpectedProxyList() { $reflectionClass = new ReflectionClass(FooAspect::class); $reflectionMethod = $reflectionClass->getMethod('fooAdvice'); $joinpoint = new Joinpoint($reflectionMethod); $advice = new Advice(new Pointcut($this->getPointcutExpressionFixtures()), new InterceptingMethod(new ReflectionMethod(FooAspect::class, 'fooAdvice'))); $adviceDefinition = new ArrayServiceDefinition(array('serviceId' => 'fooAspect', 'class' => FooAspect::class)); $joinpointsAdvices = new Map(); $joinpointsAdvices->put($joinpoint, new ArrayList()); $joinpointsAdvices->getValue($joinpoint)->put([$advice, $adviceDefinition]); $targetDefinition = new ArrayServiceDefinition(array('serviceId' => 'fooService', 'class' => FooService::class)); $proxyList = new ProxyList(); $proxyList->addProxy(new Proxy($joinpointsAdvices, $targetDefinition)); return $proxyList; }