Пример #1
0
 /**
  * {@inheritdoc}
  * @param ParsedReflectionFileNamespace|string $ns
  */
 public function matches($ns)
 {
     $isNamespaceIsObject = $ns === (object) $ns;
     if ($isNamespaceIsObject && !$ns instanceof ParsedReflectionFileNamespace) {
         return false;
     }
     $nsName = $isNamespaceIsObject ? $ns->getName() : $ns;
     return $nsName === $this->nsName || (bool) preg_match("/^(?:{$this->regexp})\$/", $nsName);
 }
Пример #2
0
 /**
  * Adds a namespace part from a file.
  *
  * @param \TokenReflection\ReflectionFileNamespace $namespace Namespace part
  * @return \TokenReflection\ReflectionNamespace
  * @throws \TokenReflection\Exception\FileProcessingException If one of classes, functions or constants form the namespace are already defined
  */
 public function addFileNamespace(ReflectionFileNamespace $namespace)
 {
     $errors = array();
     foreach ($namespace->getClasses() as $className => $reflection) {
         if ($reflection instanceof Invalid\ReflectionClass) {
             $errors = array_merge($errors, $reflection->getReasons());
         }
         if (isset($this->classes[$className])) {
             if (!$this->classes[$className] instanceof Invalid\ReflectionClass) {
                 $this->classes[$className] = new Invalid\ReflectionClass($className, $this->classes[$className]->getFileName(), $this->getBroker());
             }
             $error = new Exception\RuntimeException(sprintf('Class %s was redeclared (previously declared in file %s).', $className, $this->classes[$className]->getFileName()), Exception\RuntimeException::ALREADY_EXISTS, $reflection);
             $errors[] = $error;
             $this->classes[$className]->addReason($error);
             if ($reflection instanceof Invalid\ReflectionClass) {
                 foreach ($reflection->getReasons() as $reason) {
                     $this->classes[$className]->addReason($reason);
                 }
             }
         } else {
             $this->classes[$className] = $reflection;
         }
     }
     foreach ($namespace->getFunctions() as $functionName => $reflection) {
         if ($reflection instanceof Invalid\ReflectionFunction) {
             $errors = array_merge($errors, $reflection->getReasons());
         }
         if (isset($this->functions[$functionName])) {
             if (!$this->functions[$functionName] instanceof Invalid\ReflectionFunction) {
                 $this->functions[$functionName] = new Invalid\ReflectionFunction($functionName, $this->functions[$functionName]->getFileName(), $this->getBroker());
             }
             $error = new Exception\RuntimeException(sprintf('Function %s was redeclared (previousy declared in file %s).', $functionName, $this->functions[$functionName]->getFileName()), Exception\RuntimeException::ALREADY_EXISTS, $reflection);
             $errors[] = $error;
             $this->functions[$functionName]->addReason($error);
             if ($reflection instanceof Invalid\ReflectionFunction) {
                 foreach ($reflection->getReasons() as $reason) {
                     $this->functions[$functionName]->addReason($reason);
                 }
             }
         } else {
             $this->functions[$functionName] = $reflection;
         }
     }
     foreach ($namespace->getConstants() as $constantName => $reflection) {
         if ($reflection instanceof Invalid\ReflectionConstant) {
             $errors = array_merge($errors, $reflection->getReasons());
         }
         if (isset($this->constants[$constantName])) {
             if (!$this->constants[$constantName] instanceof Invalid\ReflectionConstant) {
                 $this->constants[$constantName] = new Invalid\ReflectionConstant($constantName, $this->constants[$constantName]->getFileName(), $this->getBroker());
             }
             $error = new Exception\RuntimeException(sprintf('Constant %s was redeclared (previuosly declared in file %s).', $constantName, $this->constants[$constantName]->getFileName()), Exception\RuntimeException::ALREADY_EXISTS, $reflection);
             $errors[] = $error;
             $this->constants[$constantName]->addReason($error);
             if ($reflection instanceof Invalid\ReflectionConstant) {
                 foreach ($reflection->getReasons() as $reason) {
                     $this->constants[$constantName]->addReason($reason);
                 }
             }
         } else {
             $this->constants[$constantName] = $reflection;
         }
     }
     if (!empty($errors)) {
         throw new Exception\FileProcessingException($errors, null);
     }
     return $this;
 }
Пример #3
0
 /**
  * Returns list of function advices for specific namespace
  *
  * @param ReflectionFileNamespace $namespace
  * @param Aop\PointcutAdvisor $advisor Advisor for class
  * @param string $advisorId Identifier of advisor
  * @param Aop\PointFilter $pointcut Filter for points
  *
  * @return array
  */
 private function getFunctionAdvicesFromAdvisor($namespace, $advisor, $advisorId, $pointcut)
 {
     $functions = array();
     $advices = array();
     if (!$functions) {
         $listOfGlobalFunctions = get_defined_functions();
         foreach ($listOfGlobalFunctions['internal'] as $functionName) {
             $functions[$functionName] = new NamespacedReflectionFunction($functionName, $namespace->getName());
         }
     }
     foreach ($functions as $functionName => $function) {
         if ($pointcut->matches($function)) {
             $advices[AspectContainer::FUNCTION_PREFIX][$functionName][$advisorId] = $advisor->getAdvice();
         }
     }
     return $advices;
 }