public function translate(PointcutExpression $pointcutExpression) { if (!$this->cache->exists($pointcutExpression->getExpression())) { $className = $this->generateUniqueMatcherClassName(); $this->cache->put($pointcutExpression->getExpression(), $className); } return $this->cache->get($pointcutExpression->getExpression()); }
/** * @param ReflectionClass $reflectionClass * @param PointcutExpression $pointcutExpression * @return Joinpoint[] */ public function findJoinpoints(ReflectionClass $reflectionClass, PointcutExpression $pointcutExpression) { if (!isset($this->methodMatchers[$pointcutExpression->getExpression()])) { $matcherFQNClassName = $this->methodMatcherCompiler->compileMethodMatcher($pointcutExpression); $this->methodMatchers[$pointcutExpression->getExpression()] = new $matcherFQNClassName($this->annotationResolver); } /** @var MethodMatcher $matcher */ $matcher = $this->methodMatchers[$pointcutExpression->getExpression()]; $joinpoints = []; foreach ($reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED) as $reflectionMethod) { if ($reflectionMethod->getName() != '__construct' && $matcher->match($reflectionMethod)) { $joinpoints[] = new Joinpoint($reflectionMethod); } } return $joinpoints; }
private function doCompile(PointcutExpression $pointcutExpression, $matcherFQNClass) { $visitor = new CompileMethodMatchVisitor(); $lexer = new Lexer(new StringInputStream($pointcutExpression->getExpression())); $tree = $lexer->buildTree(); $tree->acceptVisitor($visitor); $compiledExpression = $visitor->getCompiled(); $compiled = '<?php' . "\n"; $compiled .= 'namespace ' . $this->matcherNamespace . ";\n"; $compiled .= 'class ' . $matcherFQNClass . ' implements \\' . MethodMatcher::class . " {\n"; $compiled .= ' private $annotationResolver;' . "\n"; $compiled .= ' public function __construct(\\' . AnnotationResolver::class . ' $annotationResolver) {' . "\n"; $compiled .= ' $this->annotationResolver = $annotationResolver;' . "\n"; $compiled .= ' }' . "\n"; $compiled .= ' public function match(\\ReflectionMethod $reflectionMethod) {' . "\n"; $compiled .= ' return ' . $compiledExpression . ";\n"; $compiled .= ' }' . "\n"; $compiled .= '}' . "\n"; return $compiled; }