/** * Constructs a pointcut grammar with AST * * @param AspectContainer $container Instance of the container * @param RawAnnotationReader $annotationReader */ public function __construct(AspectContainer $container = null, RawAnnotationReader $annotationReader = null) { $this('empty')->is(); $this('pointcut')->is('pointcut', '||', 'pointcut')->call(function ($first, $_0, $second) { return new OrPointcut($first, $second); })->is('pointcut', '&&', 'pointcut')->call(function ($first, $_0, $second) { return new AndPointcut($first, $second); })->is('(', 'pointcut', ')')->call(function ($_0, $pointcut) { return $pointcut; })->is('!', 'pointcut')->call(function ($_0, $first) { return new NotPointcut($first); })->is('cflowbelow', '(', 'pointcut', ')')->call(function ($_0, $_1, $pointcut) { return new CFlowBelowMethodPointcut($pointcut); })->is('singlePointcut'); $this('singlePointcut')->is('execution', '(', 'memberModifiers', 'classFilter', 'methodCall', 'namePattern', '(', '*', ')', ')')->call(function ($_0, $_1, ModifierMatcherFilter $memberModifiers, PointFilter $classFilter, $methodCallType, $methodNamePattern) { if ($methodCallType === '::') { $memberModifiers->andMatch(\ReflectionMethod::IS_STATIC); } else { $memberModifiers->notMatch(\ReflectionMethod::IS_STATIC); } $filterKind = PointFilter::KIND_METHOD; $pointcut = new SignaturePointcut($filterKind, $methodNamePattern, $memberModifiers); $pointcut->setClassFilter($classFilter); return $pointcut; })->is('dynamic', '(', 'memberModifiers', 'classFilter', 'methodCall', 'namePattern', '(', '*', ')', ')')->call(function ($_0, $_1, ModifierMatcherFilter $memberModifiers, PointFilter $classFilter, $methodCallType, $methodNamePattern) { if ($methodCallType === '::') { $memberModifiers->andMatch(\ReflectionMethod::IS_STATIC); } else { $memberModifiers->notMatch(\ReflectionMethod::IS_STATIC); } $pointcut = new MagicMethodPointcut($methodNamePattern, $memberModifiers); $pointcut->setClassFilter($classFilter); return $pointcut; })->is('execution', '(', 'namespacePattern', '(', '*', ')', ')')->call(function ($_0, $_1, $namespacePattern) { $lastNsPos = strrpos($namespacePattern, '\\'); $namespace = substr($namespacePattern, 0, $lastNsPos); $funcPattern = substr($namespacePattern, $lastNsPos + 1); $nsFilter = new SimpleNamespaceFilter($namespace); $pointcut = new FunctionPointcut($funcPattern); $pointcut->setNamespaceFilter($nsFilter); return $pointcut; })->is('access', '(', 'memberModifiers', 'classFilter', '->', 'namePattern', ')')->call(function ($_0, $_1, ModifierMatcherFilter $memberModifiers, PointFilter $classFilter, $_2, $propertyNamePattern) { $filterKind = PointFilter::KIND_PROPERTY; $pointcut = new SignaturePointcut($filterKind, $propertyNamePattern, $memberModifiers); $pointcut->setClassFilter($classFilter); return $pointcut; })->is('within', '(', 'classFilter', ')')->call(function ($_0, $_1, $classFilter) { $pointcut = new TruePointcut(PointFilter::KIND_ALL); $pointcut->setClassFilter($classFilter); return $pointcut; })->is('annotation', 'access', '(', 'namespacePattern', ')')->call(function ($_0, $_1, $_2, $annotationClassName) use($annotationReader) { $kindProperty = PointFilter::KIND_PROPERTY; return new AnnotationPointcut($kindProperty, $annotationReader, $annotationClassName); })->is('annotation', 'execution', '(', 'namespacePattern', ')')->call(function ($_0, $_1, $_2, $annotationClassName) use($annotationReader) { $kindMethod = PointFilter::KIND_METHOD; return new AnnotationPointcut($kindMethod, $annotationReader, $annotationClassName); })->is('annotation', 'within', '(', 'namespacePattern', ')')->call(function ($_0, $_1, $_2, $annotationClassName) use($annotationReader) { $pointcut = new TruePointcut(PointFilter::KIND_ALL); $kindClass = PointFilter::KIND_CLASS; $classFilter = new AnnotationPointcut($kindClass, $annotationReader, $annotationClassName); $pointcut->setClassFilter($classFilter); return $pointcut; })->is('initialization', '(', 'classFilter', ')')->call(function ($_0, $_1, $classFilter) { $pointcut = new TruePointcut(PointFilter::KIND_INIT + PointFilter::KIND_CLASS); $pointcut->setClassFilter($classFilter); return $pointcut; })->is('staticinitialization', '(', 'classFilter', ')')->call(function ($_0, $_1, $classFilter) { $pointcut = new TruePointcut(PointFilter::KIND_STATIC_INIT + PointFilter::KIND_CLASS); $pointcut->setClassFilter($classFilter); return $pointcut; })->is('pointcutReference')->call(function ($pointcutName) use($container) { return $container->getPointcut($pointcutName); }); $stringConverter = $this->getNodeToStringConverter(); $this('pointcutReference')->is('namespacePattern', 'methodCall', 'namePart')->call($stringConverter); // stable $this('methodCall')->is('::')->call($stringConverter)->is('->')->call($stringConverter); $this('classFilter')->is('namespacePattern')->call(function ($pattern) { $filterKind = PointFilter::KIND_CLASS; $truePointFilter = TruePointFilter::getInstance(); return $pattern === '**' ? $truePointFilter : new SignaturePointcut($filterKind, $pattern, $truePointFilter); })->is('namespacePattern', '+')->call(function ($parentClassName) { return new InheritanceClassFilter($parentClassName); }); // stable $this('namespacePattern')->is('namePattern')->is('**')->call($stringConverter)->is('namespacePattern', 'nsSeparator', 'namespacePattern')->call($stringConverter); // stable $this('namePattern')->is('namePattern', '*')->call($stringConverter)->is('namePattern', 'namePart')->call($stringConverter)->is('namePattern', '|', 'namePart')->call($stringConverter)->is('namePart')->call($stringConverter)->is('*')->call($stringConverter); // stable $this('memberModifiers')->is('*')->call(function () { $matcher = new ModifierMatcherFilter(); return $matcher->orMatch(-1); })->is('nonEmptyMemberModifiers'); // stable $this('nonEmptyMemberModifiers')->is('memberModifier')->call(function ($modifier) { return new ModifierMatcherFilter($modifier); })->is('nonEmptyMemberModifiers', '|', 'memberModifier')->call(function (ModifierMatcherFilter $matcher, $_0, $modifier) { return $matcher->orMatch($modifier); })->is('nonEmptyMemberModifiers', 'memberModifier')->call(function (ModifierMatcherFilter $matcher, $modifier) { return $matcher->andMatch($modifier); }); // stable $converter = $this->getModifierConverter(); $this('memberModifier')->is('public')->call($converter)->is('protected')->call($converter)->is('private')->call($converter)->is('final')->call($converter); $this->resolve(Grammar::ALL); $this->start('pointcut'); }
/** * Constructs a pointcut grammar with AST * * @param AspectContainer $container Instance of the container * @param RawAnnotationReader $annotationReader */ public function __construct(AspectContainer $container = null, RawAnnotationReader $annotationReader = null) { $this('empty')->is(); $stringConverter = $this->getNodeToStringConverter(); $this('pointcutExpression')->is('pointcutExpression', '||', 'conjugatedExpression')->call(function ($first, $_0, $second) { return new OrPointcut($first, $second); })->is('conjugatedExpression'); $this('conjugatedExpression')->is('conjugatedExpression', '&&', 'negatedExpression')->call(function ($first, $_0, $second) { return new AndPointcut($first, $second); })->is('negatedExpression'); $this('negatedExpression')->is('!', 'brakedExpression')->call(function ($_0, $item) { return new NotPointcut($item); })->is('brakedExpression'); $this('brakedExpression')->is('(', 'pointcutExpression', ')')->call(function ($_0, $e, $_1) { return $e; })->is('singlePointcut'); $this('singlePointcut')->is('accessPointcut')->is('annotatedAccessPointcut')->is('executionPointcut')->is('annotatedExecutionPointcut')->is('withinPointcut')->is('annotatedWithinPointcut')->is('initializationPointcut')->is('staticInitializationPointcut')->is('cflowbelowPointcut')->is('dynamicExecutionPointcut')->is('pointcutReference'); $this('accessPointcut')->is('access', '(', 'propertyAccessReference', ')')->call(function ($_0, $_1, $propertyReference) { return $propertyReference; }); $this('executionPointcut')->is('execution', '(', 'methodExecutionReference', ')')->call(function ($_0, $_1, $methodReference) { return $methodReference; })->is('execution', '(', 'functionExecutionReference', ')')->call(function ($_0, $_1, $functionReference) { return $functionReference; }); $this('withinPointcut')->is('within', '(', 'classFilter', ')')->call(function ($_0, $_1, $classFilter) { $pointcut = new TruePointcut(PointFilter::KIND_ALL); $pointcut->setClassFilter($classFilter); return $pointcut; }); $this('annotatedAccessPointcut')->is('annotation', 'access', '(', 'namespaceName', ')')->call(function ($_0, $_1, $_2, $annotationClassName) use($annotationReader) { $kindProperty = PointFilter::KIND_PROPERTY; return new AnnotationPointcut($kindProperty, $annotationReader, $annotationClassName); }); $this('annotatedExecutionPointcut')->is('annotation', 'execution', '(', 'namespaceName', ')')->call(function ($_0, $_1, $_2, $annotationClassName) use($annotationReader) { $kindMethod = PointFilter::KIND_METHOD; return new AnnotationPointcut($kindMethod, $annotationReader, $annotationClassName); }); $this('annotatedWithinPointcut')->is('annotation', 'within', '(', 'namespaceName', ')')->call(function ($_0, $_1, $_2, $annotationClassName) use($annotationReader) { $pointcut = new TruePointcut(PointFilter::KIND_ALL); $kindClass = PointFilter::KIND_CLASS; $classFilter = new AnnotationPointcut($kindClass, $annotationReader, $annotationClassName); $pointcut->setClassFilter($classFilter); return $pointcut; }); $this('initializationPointcut')->is('initialization', '(', 'classFilter', ')')->call(function ($_0, $_1, $classFilter) { $pointcut = new TruePointcut(PointFilter::KIND_INIT + PointFilter::KIND_CLASS); $pointcut->setClassFilter($classFilter); return $pointcut; }); $this('staticInitializationPointcut')->is('staticinitialization', '(', 'classFilter', ')')->call(function ($_0, $_1, $classFilter) { $pointcut = new TruePointcut(PointFilter::KIND_STATIC_INIT + PointFilter::KIND_CLASS); $pointcut->setClassFilter($classFilter); return $pointcut; }); $this('cflowbelowPointcut')->is('cflowbelow', '(', 'executionPointcut', ')')->call(function ($_0, $_1, $pointcut) { return new CFlowBelowMethodPointcut($pointcut); }); $this('dynamicExecutionPointcut')->is('dynamic', '(', 'memberReference', '(', 'argumentList', ')', ')')->call(function ($_0, $_1, ClassMemberReference $reference) { $memberFilter = $reference->getVisibilityFilter(); $memberFilter = $memberFilter->merge($reference->getAccessTypeFilter()); $pointcut = new MagicMethodPointcut($reference->getMemberNamePattern(), $memberFilter); $pointcut->setClassFilter($reference->getClassFilter()); return $pointcut; }); $this('pointcutReference')->is('namespaceName', '->', 'namePatternPart')->call(function ($className, $_0, $name) use($container) { return new PointcutReference($container, "{$className}->{$name}"); }); $this('propertyAccessReference')->is('memberReference')->call(function (ClassMemberReference $reference) { $memberFilter = $reference->getVisibilityFilter(); $memberFilter = $memberFilter->merge($reference->getAccessTypeFilter()); $pointcut = new SignaturePointcut(PointFilter::KIND_PROPERTY, $reference->getMemberNamePattern(), $memberFilter); $pointcut->setClassFilter($reference->getClassFilter()); return $pointcut; }); $this('methodExecutionReference')->is('memberReference', '(', 'argumentList', ')')->call(function (ClassMemberReference $reference) { $memberFilter = $reference->getVisibilityFilter(); $memberFilter = $memberFilter->merge($reference->getAccessTypeFilter()); $pointcut = new SignaturePointcut(PointFilter::KIND_METHOD, $reference->getMemberNamePattern(), $memberFilter); $pointcut->setClassFilter($reference->getClassFilter()); return $pointcut; }); $this('functionExecutionReference')->is('namespacePattern', 'nsSeparator', 'namePatternPart', '(', 'argumentList', ')')->call(function ($namespacePattern, $_0, $namePattern) { $nsFilter = new SimpleNamespaceFilter($namespacePattern); $pointcut = new FunctionPointcut($namePattern); $pointcut->setNamespaceFilter($nsFilter); return $pointcut; }); $this('memberReference')->is('memberModifiers', 'classFilter', 'memberAccessType', 'namePatternPart')->call(function (ModifierMatcherFilter $memberModifiers, PointFilter $classFilter, ModifierMatcherFilter $memberAccessType, $namePattern) { $reference = new ClassMemberReference($classFilter, $memberModifiers, $memberAccessType, $namePattern); return $reference; }); $this('classFilter')->is('namespacePattern')->call(function ($pattern) { $truePointFilter = TruePointFilter::getInstance(); return $pattern === '**' ? $truePointFilter : new SignaturePointcut(PointFilter::KIND_CLASS, $pattern, $truePointFilter); })->is('namespacePattern', '+')->call(function ($parentClassName) { return new InheritanceClassFilter($parentClassName); }); $this('argumentList')->is('*'); $this('memberAccessType')->is('::')->call(function () { return new ModifierMatcherFilter(\ReflectionMethod::IS_STATIC); })->is('->')->call(function () { $modifierMatcherFilter = new ModifierMatcherFilter(); $modifierMatcherFilter->notMatch(\ReflectionMethod::IS_STATIC); return $modifierMatcherFilter; }); $this('namespacePattern')->is('**')->call($stringConverter)->is('namePatternPart')->is('namespacePattern', 'nsSeparator', 'namePatternPart')->call($stringConverter)->is('namespacePattern', 'nsSeparator', '**')->call($stringConverter); $this('namePatternPart')->is('*')->call($stringConverter)->is('namePart')->call($stringConverter)->is('namePatternPart', '*')->call($stringConverter)->is('namePatternPart', 'namePart')->call($stringConverter)->is('namePatternPart', '|', 'namePart')->call($stringConverter); $this('namespaceName')->is('namePart')->call($stringConverter)->is('namespaceName', 'nsSeparator', 'namePart')->call($stringConverter); $this('memberModifiers')->is('memberModifier', '|', 'memberModifiers')->call(function ($modifier, $_0, ModifierMatcherFilter $matcher) { return $matcher->orMatch($modifier); })->is('memberModifier', 'memberModifiers')->call(function ($modifier, ModifierMatcherFilter $matcher) { return $matcher->andMatch($modifier); })->is('memberModifier')->call(function ($modifier) { return new ModifierMatcherFilter($modifier); }); $converter = $this->getModifierConverter(); $this('memberModifier')->is('public')->call($converter)->is('protected')->call($converter)->is('private')->call($converter)->is('final')->call($converter); $this->start('pointcutExpression'); }