Exemplo n.º 1
0
 private function parseType($annotations, TokenReflectionClass $tokenizedClass)
 {
     $currentNamespace = $tokenizedClass->getNamespaceName();
     $currentNamespaceAliases = $tokenizedClass->getNamespaceAliases();
     foreach ($annotations as $annotation) {
         preg_match(self::TYPE_REGEXP, $annotation, $matches);
         if (!empty($matches[0])) {
             list($parsedNamespace, $parsedClassName) = $this->parseClass($matches[0]);
             if ($this->isIgnoredType($parsedClassName)) {
                 continue;
             }
             if (empty($parsedNamespace) && isset($currentNamespaceAliases[$parsedClassName])) {
                 return $currentNamespaceAliases[$parsedClassName];
             } else {
                 if (isset($currentNamespaceAliases[$parsedNamespace])) {
                     return $currentNamespaceAliases[$parsedNamespace] . '\\' . $parsedClassName;
                 } else {
                     if (class_exists($currentNamespace . '\\' . $parsedClassName)) {
                         return $currentNamespace . '\\' . $parsedClassName;
                     } else {
                         if (class_exists($parsedClassName)) {
                             return $parsedClassName;
                         }
                     }
                 }
             }
         }
     }
     return null;
 }
Exemplo n.º 2
0
 /**
  * @param ParsedReflectionClass|ParsedReflectionMethod|ParsedReflectionProperty $point
  * {@inheritdoc}
  */
 public function matches($point)
 {
     $expectedClass = $this->expectedClass;
     if (!$point instanceof $expectedClass) {
         return false;
     }
     $aliases = $point->getNamespaceAliases();
     $this->annotationReader->setImports($aliases);
     $annotation = $this->annotationReader->{$this->annotationMethod}($point, $this->annotationName);
     return (bool) $annotation;
 }
Exemplo n.º 3
0
 /**
  * Save AOP proxy to the separate file anr returns the php source code for inclusion
  *
  * @param ParsedClass $class Original class reflection
  * @param string|ClassProxy $child
  *
  * @return string
  */
 private function saveProxyToCache($class, $child)
 {
     // Without cache we should rewrite original file
     if (empty($this->options['cacheDir'])) {
         return $child;
     }
     $cacheDirSuffix = '/_proxies/';
     $cacheDir = $this->options['cacheDir'] . $cacheDirSuffix;
     $fileName = str_replace('\\', '/', $class->getName()) . '.php';
     $proxyFileName = $cacheDir . $fileName;
     $dirname = dirname($proxyFileName);
     if (!file_exists($dirname)) {
         mkdir($dirname, 0770, true);
     }
     $body = '<?php' . PHP_EOL;
     $namespace = $class->getNamespaceName();
     if ($namespace) {
         $body .= "namespace {$namespace};" . PHP_EOL . PHP_EOL;
     }
     foreach ($class->getNamespaceAliases() as $alias => $fqdn) {
         $body .= "use {$fqdn} as {$alias};" . PHP_EOL;
     }
     $body .= $child;
     file_put_contents($proxyFileName, $body);
     return 'include_once AOP_CACHE_DIR . ' . var_export($cacheDirSuffix . $fileName, true) . ';' . PHP_EOL;
 }
Exemplo n.º 4
0
 /**
  * Checks the class for possible component and register it in the container if needed
  *
  * @param ReflectionClass $class Instance of class reflection
  * @param ContainerBuilder $container
  *
  * @return bool True if component is registered
  */
 protected function checkAndRegisterComponent(ReflectionClass $class, ContainerBuilder $container)
 {
     $this->reader->setImports($class->getNamespaceAliases());
     $serviceName = str_replace('\\', '.', $class->getName());
     $annotation = $this->reader->getClassAnnotation($class, self::ANNOTATION_CLASS);
     if (!$annotation) {
         return false;
     }
     $definition = $container->register($serviceName, $class->getName());
     $constructor = $class->getConstructor();
     if ($constructor) {
         $this->bindConstructorArgs($constructor, $definition, $container);
     }
     if ((string) $annotation) {
         // Make an alias for annotation
         $container->setAlias($annotation, $serviceName);
     }
     return true;
 }