Пример #1
0
 /**
  * This will give you the name of a proxy class as a string. The class will
  * already exist in the vm.
  *
  * @return string
  */
 public function create($class, IDispatcher $dispatcher)
 {
     $subject = $this->reflectionFactory->getClass($class);
     $proxyClassName = 'Proxy' . str_replace('\\', '', $subject->getName());
     $cacheKey = $proxyClassName . '.proxy';
     $result = false;
     $src = $this->cache->fetch($cacheKey, $result);
     if (!$result) {
         $src = $this->createClass($proxyClassName, $dispatcher->getMethodsIntercepted(), $subject);
         $this->cache->store($cacheKey, $src);
     }
     eval($src);
     $proxyClassName::setDispatcher($dispatcher);
     $proxyClassName::setReflectionFactory($this->reflectionFactory);
     return $proxyClassName;
 }
Пример #2
0
 /**
  * Will inject into the given dispatcher the necessary information to
  * aspects will be run correctly.
  *
  * @throws BeanFactoryException
  * @return void
  */
 private function _applyAspect($targetClass, AspectDefinition $aspectDefinition, IDispatcher $dispatcher)
 {
     $rClass = $this->_reflectionFactory->getClass($targetClass);
     $aspect = $this->getBean($aspectDefinition->getBeanName());
     foreach ($aspectDefinition->getPointcuts() as $pointcutName) {
         $pointcut = $this->_aspectManager->getPointcut($pointcutName);
         if ($pointcut === false) {
             throw new BeanFactoryException('Could not find pointcut: ' . $pointcutName);
         }
         $expression = $pointcut->getExpression();
         foreach ($rClass->getMethods() as $method) {
             $methodName = $method->getName();
             if (preg_match('/' . $expression . '/', $methodName) === 0) {
                 continue;
             }
             if ($aspectDefinition->getType() == AspectDefinition::ASPECT_METHOD) {
                 $dispatcher->addMethodInterceptor($methodName, $aspect, $pointcut->getMethod());
             } else {
                 $dispatcher->addExceptionInterceptor($methodName, $aspect, $pointcut->getMethod());
             }
         }
     }
 }