registerPointcut() public method

Store the pointcut in the container
public registerPointcut ( Go\Aop\Pointcut $pointcut, string $id )
$pointcut Go\Aop\Pointcut Instance
$id string Key for pointcut
コード例 #1
0
 /**
  * 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));
     }
 }
コード例 #2
0
ファイル: AspectLoader.php プロジェクト: goaop/framework
 /**
  * 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;
 }