Example #1
0
 public function registerAspects(MvcEvent $event)
 {
     $application = $event->getApplication();
     $config = $application->getConfig();
     Annotations\AnnotationRegistry::registerAutoloadNamespace(__NAMESPACE__ . '\\Annotation');
     foreach ($config['aop']['aspect_class_paths'] as $path) {
         foreach (new ClassFileLocator($path) as $classInfoFile) {
             foreach ($classInfoFile->getClasses() as $class) {
                 $aspect = new $class();
                 $reader = new Annotations\AnnotationReader();
                 $reflection = new \ReflectionClass($aspect);
                 foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
                     $annotation = $reader->getMethodAnnotation($method, 'AOP\\Annotation\\Pointcut');
                     if (!$annotation) {
                         continue;
                     }
                     $advice = $method->getName();
                     $pointcuts = $annotation->rule;
                     foreach ($pointcuts as $pointcut) {
                         list($trigger, $rule) = sscanf($pointcut, "%s %s");
                         switch ($trigger) {
                             case 'before':
                                 aop_add_before($rule, array($aspect, $advice));
                                 break;
                             case 'after':
                                 aop_add_after($rule, array($aspect, $advice));
                                 break;
                             case 'around':
                                 aop_add_around($rule, array($aspect, $advice));
                                 break;
                         }
                     }
                     if ($aspect instanceof \Zend\ServiceManager\ServiceLocatorAwareInterface) {
                         $aspect->setServiceLocator($application->getServiceManager());
                     }
                 }
             }
         }
     }
 }
 /**
  * @inheritdoc
  * @see \Aop\Weaver\WeaverInterface::addAround()
  */
 public function addAround(Pointcutinterface $pointcut, AdviceInterface $advice, array $options = [])
 {
     aop_add_around($pointcut->getSelector(), $this->createBinder($pointcut, $advice, $options));
     return $this->lastIndex;
 }
Example #3
0
<?php

$iniSettings = parse_ini_file('config/listener.ini');
$functionSignatures = $iniSettings['signatures'];
foreach ($functionSignatures as $func) {
    aop_add_around($func, array('AOP_UT\\Advice\\MethodsAdvice', 'adviceAround'));
}