registerAdvisor() публичный Метод

Store the advisor in the container
public registerAdvisor ( Go\Aop\Advisor $advisor, string $id )
$advisor Go\Aop\Advisor Instance
$id string Key for advisor
Пример #1
0
 /**
  * Check that list of advices for fields works correctly
  */
 public function testGetSinglePropertyAdviceForClassFromAdvisor()
 {
     $propName = 'container';
     // $this->container;
     $pointcut = $this->getMock('Go\\Aop\\Pointcut');
     $pointcut->expects($this->any())->method('getClassFilter')->will($this->returnValue(TruePointFilter::getInstance()));
     $pointcut->expects($this->any())->method('matches')->will($this->returnCallback(function ($point) use($propName) {
         return $point->name === $propName;
     }));
     $pointcut->expects($this->any())->method('getKind')->will($this->returnValue(Pointcut::KIND_PROPERTY));
     $advice = $this->getMock('Go\\Aop\\Advice');
     $advisor = new DefaultPointcutAdvisor($pointcut, $advice);
     $this->container->registerAdvisor($advisor, 'test');
     $advices = $this->adviceMatcher->getAdvicesForClass(__CLASS__);
     $this->assertArrayHasKey(AspectContainer::PROPERTY_PREFIX, $advices);
     $this->assertArrayHasKey($propName, $advices[AspectContainer::PROPERTY_PREFIX]);
     $this->assertCount(1, $advices[AspectContainer::PROPERTY_PREFIX]);
 }
Пример #2
0
 /**
  * Loads and register all items of aspect in the container
  *
  * @param Aspect $aspect
  */
 public function loadAndRegister(Aspect $aspect)
 {
     $loadedItems = $this->load($aspect);
     foreach ($loadedItems as $itemId => $item) {
         if ($item instanceof Pointcut) {
             $this->container->registerPointcut($item, $itemId);
         }
         if ($item instanceof Advisor) {
             $this->container->registerAdvisor($item, $itemId);
         }
     }
     $aspectClass = get_class($aspect);
     $this->loadedAspects[$aspectClass] = $aspectClass;
 }
 /**
  * Loads definition from specific point of aspect into the container
  *
  * @param AspectContainer $container Instance of container
  * @param Aspect $aspect Instance of aspect
  * @param mixed|\ReflectionClass|\ReflectionMethod|\ReflectionProperty $reflection Reflection of point
  * @param mixed|null $metaInformation Additional meta-information
  *
  * @throws \UnexpectedValueException
  */
 public function load(AspectContainer $container, Aspect $aspect, $reflection, $metaInformation = null)
 {
     $pointcut = $this->parsePointcut($aspect, $reflection, $metaInformation);
     $propertyId = $reflection->class . '->' . $reflection->name;
     switch (true) {
         case $metaInformation instanceof Annotation\DeclareParents:
             $interface = $metaInformation->interface;
             $implement = $metaInformation->defaultImpl;
             $advice = new Framework\TraitIntroductionInfo($interface, $implement);
             $advisor = new Support\DeclareParentsAdvisor($pointcut->getClassFilter(), $advice);
             $container->registerAdvisor($advisor, $propertyId);
             break;
         case $metaInformation instanceof Annotation\DeclareError:
             $reflection->setAccessible(true);
             $message = $reflection->getValue($aspect);
             $level = $metaInformation->level;
             $advice = new Framework\DeclareErrorInterceptor($message, $level);
             $container->registerAdvisor(new Support\DefaultPointcutAdvisor($pointcut, $advice), $propertyId);
             break;
         default:
             throw new \UnexpectedValueException("Unsupported pointcut class: " . get_class($pointcut));
     }
 }
 /**
  * Loads definition from specific point of aspect into the container
  *
  * @param AspectContainer $container Instance of container
  * @param Aspect $aspect Instance of aspect
  * @param mixed|\ReflectionClass|\ReflectionMethod|\ReflectionProperty $reflection Reflection of point
  * @param mixed|null $metaInformation Additional meta-information, e.g. annotation for method
  *
  * @throws \UnexpectedValueException
  */
 public function load(AspectContainer $container, Aspect $aspect, $reflection, $metaInformation = null)
 {
     $pointcut = $this->parsePointcut($aspect, $reflection, $metaInformation);
     $methodId = get_class($aspect) . '->' . $reflection->name;
     $adviceCallback = Framework\BaseAdvice::fromAspectReflection($aspect, $reflection);
     if (isset($metaInformation->scope) && $metaInformation->scope !== 'aspect') {
         $scope = $metaInformation->scope;
         $adviceCallback = Framework\BaseAdvice::createScopeCallback($aspect, $adviceCallback, $scope);
     }
     switch (true) {
         // Register a pointcut by its name
         case $metaInformation instanceof Annotation\Pointcut:
             $container->registerPointcut($pointcut, $methodId);
             break;
         case $pointcut instanceof PointFilter:
             $advice = $this->getInterceptor($metaInformation, $adviceCallback);
             if ($pointcut->getKind() & PointFilter::KIND_DYNAMIC) {
                 $advice = new Framework\DynamicInvocationMatcherInterceptor($pointcut, $advice);
             }
             $container->registerAdvisor(new DefaultPointcutAdvisor($pointcut, $advice), $methodId);
             break;
         default:
             throw new \UnexpectedValueException("Unsupported pointcut class: " . get_class($pointcut));
     }
 }
Пример #5
0
 /**
  * Declares the error message for specific pointcut expression
  *
  * @param string $pointcutExpression Pointcut, e.g. "within(**)"
  * @param string $message Error message to show
  * @param integer $level Error level to trigger
  */
 public function declareError($pointcutExpression, $message, $level = E_USER_ERROR)
 {
     $advice = new DeclareErrorInterceptor($message, $level);
     $this->container->registerAdvisor(new LazyPointcutAdvisor($this->container, $pointcutExpression, $advice), $this->getPointcutId($pointcutExpression));
 }
Пример #6
0
 /**
  * General method to register advices
  *
  * @param string $pointcutExpression Pointcut expression string
  * @param Advice $advice Instance of advice
  */
 private function registerAdviceInContainer($pointcutExpression, Advice $advice)
 {
     $this->container->registerAdvisor(new LazyPointcutAdvisor($this->container, $pointcutExpression, $advice), $this->getPointcutId($pointcutExpression));
 }