Beispiel #1
0
 public function testIssueWithNamespacesOrImports()
 {
     $docblock = "@Entity";
     $parser = new \Doctrine\Common\Annotations\DocParser();
     $annots = $parser->parse($docblock);
     $this->assertEquals(1, count($annots));
     $this->assertInstanceOf("Entity", $annots[0]);
     $this->assertEquals(1, count($annots));
 }
Beispiel #2
0
 public function testIssueGlobalNamespace()
 {
     $docblock = "@Entity";
     $parser = new \Doctrine\Common\Annotations\DocParser();
     $parser->setImports(array("__NAMESPACE__" => "Doctrine\\Tests\\Common\\Annotations\\Ticket\\Doctrine\\ORM\\Mapping"));
     $annots = $parser->parse($docblock);
     $this->assertEquals(1, count($annots));
     $this->assertInstanceOf("Doctrine\\Tests\\Common\\Annotations\\Ticket\\Doctrine\\ORM\\Mapping\\Entity", $annots[0]);
 }
 /**
  * Collects parsing metadata for a given class
  *
  * @param ReflectionClass $class
  */
 private function collectParsingMetadata(ReflectionClass $class)
 {
     $ignoredAnnotationNames = self::$globalIgnoredNames;
     $annotations = $this->preParser->parse($class->getDocComment(), 'class ' . $class->name);
     foreach ($annotations as $annotation) {
         if ($annotation instanceof IgnoreAnnotation) {
             foreach ($annotation->names as $annot) {
                 $ignoredAnnotationNames[$annot] = true;
             }
         }
     }
     $name = $class->getName();
     $this->imports[$name] = array_merge(self::$globalImports, $this->phpParser->parseClass($class), array('__NAMESPACE__' => $class->getNamespaceName()));
     $this->ignoredAnnotationNames[$name] = $ignoredAnnotationNames;
 }
 /**
  * Collects parsing metadata for a given class
  *
  * @param ReflectionClass $class
  */
 private function collectParsingMetadata(ReflectionClass $class)
 {
     $imports = self::$globalImports;
     $ignoredAnnotationNames = self::$globalIgnoredNames;
     if ($this->enablePhpImports) {
         $annotations = $this->preParser->parse($class->getDocComment());
         foreach ($annotations as $annotation) {
             if ($annotation instanceof IgnoreAnnotation) {
                 foreach ($annotation->names as $annot) {
                     $ignoredAnnotationNames[$annot] = true;
                 }
             }
         }
     }
     $name = $class->getName();
     $this->imports[$name] = array_merge(self::$globalImports, $this->enablePhpImports ? $this->phpParser->parseClass($class) : array(), $this->enablePhpImports ? array('__NAMESPACE__' => $class->getNamespaceName()) : array());
     if ($this->defaultAnnotationNamespace) {
         $this->imports[$name]['__DEFAULT__'] = $this->defaultAnnotationNamespace;
     }
     $this->ignoredAnnotationNames[$name] = $ignoredAnnotationNames;
 }
Beispiel #5
0
 /**
  * Collects parsing metadata for a given annotation class
  *
  * @param   string $name        The annotation name
  */
 private function collectAnnotationMetadata($name)
 {
     if (self::$metadataParser == null) {
         self::$metadataParser = new self();
         self::$metadataParser->setTarget(Target::TARGET_CLASS);
         self::$metadataParser->setIgnoreNotImportedAnnotations(true);
         self::$metadataParser->setImports(array('target' => 'Doctrine\\Common\\Annotations\\Annotation\\Target', 'attribute' => 'Doctrine\\Common\\Annotations\\Annotation\\Attribute', 'attributes' => 'Doctrine\\Common\\Annotations\\Annotation\\Attributes'));
         AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Target.php');
         AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Attribute.php');
         AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Attributes.php');
     }
     $class = new \ReflectionClass($name);
     $docComment = $class->getDocComment();
     // Sets default values for annotation metadata
     $metadata = array('default_property' => null, 'has_constructor' => null !== ($constructor = $class->getConstructor()) && $constructor->getNumberOfParameters() > 0, 'properties' => array(), 'property_types' => array(), 'attribute_types' => array(), 'targets_literal' => null, 'targets' => Target::TARGET_ALL, 'is_annotation' => false !== strpos($docComment, '@Annotation'));
     // verify that the class is really meant to be an annotation
     if ($metadata['is_annotation']) {
         foreach (self::$metadataParser->parse($docComment, 'class @' . $name) as $annotation) {
             if ($annotation instanceof Target) {
                 $metadata['targets'] = $annotation->targets;
                 $metadata['targets_literal'] = $annotation->literal;
             } elseif ($annotation instanceof Attributes) {
                 foreach ($annotation->value as $attrib) {
                     // handle internal type declaration
                     $type = isset(self::$typeMap[$attrib->type]) ? self::$typeMap[$attrib->type] : $attrib->type;
                     // handle the case if the property type is mixed
                     if ('mixed' !== $type) {
                         // Checks if the property has array<type>
                         if (false !== ($pos = strpos($type, '<'))) {
                             $arrayType = substr($type, $pos + 1, -1);
                             $type = 'array';
                             if (isset(self::$typeMap[$arrayType])) {
                                 $arrayType = self::$typeMap[$arrayType];
                             }
                             $metadata['attribute_types'][$attrib->name]['array_type'] = $arrayType;
                         }
                         $metadata['attribute_types'][$attrib->name]['type'] = $type;
                         $metadata['attribute_types'][$attrib->name]['value'] = $attrib->type;
                         $metadata['attribute_types'][$attrib->name]['required'] = $attrib->required;
                     }
                 }
             }
         }
         // if not has a constructor will inject values into public properties
         if (false === $metadata['has_constructor']) {
             // collect all public properties
             foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
                 $metadata['properties'][$property->name] = $property->name;
                 // checks if the property has @var annotation
                 if (false !== ($propertyComment = $property->getDocComment()) && false !== strpos($propertyComment, '@var') && preg_match('/@var\\s+([^\\s]+)/', $propertyComment, $matches)) {
                     // literal type declaration
                     $value = $matches[1];
                     // handle internal type declaration
                     $type = isset(self::$typeMap[$value]) ? self::$typeMap[$value] : $value;
                     // handle the case if the property type is mixed
                     if ('mixed' !== $type) {
                         // Checks if the property has @var array<type> annotation
                         if (false !== ($pos = strpos($type, '<'))) {
                             $arrayType = substr($type, $pos + 1, -1);
                             $type = 'array';
                             if (isset(self::$typeMap[$arrayType])) {
                                 $arrayType = self::$typeMap[$arrayType];
                             }
                             $metadata['attribute_types'][$property->name]['array_type'] = $arrayType;
                         }
                         $metadata['attribute_types'][$property->name]['type'] = $type;
                         $metadata['attribute_types'][$property->name]['value'] = $value;
                         $metadata['attribute_types'][$property->name]['required'] = false !== strpos($propertyComment, '@Required');
                     }
                 }
             }
             // choose the first property as default property
             $metadata['default_property'] = reset($metadata['properties']);
         }
     }
     self::$annotationMetadata[$name] = $metadata;
 }
 /**
  * Gets the 'jms_translation.updater' service.
  *
  * This service is shared.
  * This method always returns the same instance of the service.
  *
  * @return \JMS\TranslationBundle\Translation\Updater A JMS\TranslationBundle\Translation\Updater instance
  */
 protected function getJmsTranslation_UpdaterService()
 {
     $a = $this->get('logger');
     $b = $this->get('jms_translation.file_source_factory');
     $c = $this->get('twig');
     $d = new \Doctrine\Common\Annotations\DocParser();
     $d->setImports(array('desc' => 'JMS\\TranslationBundle\\Annotation\\Desc', 'meaning' => 'JMS\\TranslationBundle\\Annotation\\Meaning', 'ignore' => 'JMS\\TranslationBundle\\Annotation\\Ignore'));
     $d->setIgnoreNotImportedAnnotations(true);
     $e = new \JMS\TranslationBundle\Translation\Dumper\XliffDumper();
     $e->setSourceLanguage('en');
     $f = new \JMS\TranslationBundle\Translation\Dumper\XliffDumper();
     $f->setSourceLanguage('en');
     return $this->services['jms_translation.updater'] = new \JMS\TranslationBundle\Translation\Updater($this->get('jms_translation.loader_manager'), new \JMS\TranslationBundle\Translation\ExtractorManager(new \JMS\TranslationBundle\Translation\Extractor\FileExtractor($c, $a, array(0 => new \JMS\TranslationBundle\Translation\Extractor\File\DefaultPhpFileExtractor($d, $b), 1 => new \JMS\TranslationBundle\Translation\Extractor\File\FormExtractor($d, $b), 2 => new \JMS\TranslationBundle\Translation\Extractor\File\TranslationContainerExtractor(), 3 => new \JMS\TranslationBundle\Translation\Extractor\File\TwigFileExtractor($c, $b), 4 => new \JMS\TranslationBundle\Translation\Extractor\File\ValidationExtractor($this->get('validator')), 5 => new \JMS\TranslationBundle\Translation\Extractor\File\AuthenticationMessagesExtractor($d, $b))), $a, array()), $a, new \JMS\TranslationBundle\Translation\FileWriter(array('php' => new \JMS\TranslationBundle\Translation\Dumper\PhpDumper(), 'xlf' => $e, 'po' => new \JMS\TranslationBundle\Translation\Dumper\SymfonyDumperAdapter($this->get('translation.dumper.po'), 'po'), 'mo' => new \JMS\TranslationBundle\Translation\Dumper\SymfonyDumperAdapter($this->get('translation.dumper.mo'), 'mo'), 'yml' => new \JMS\TranslationBundle\Translation\Dumper\YamlDumper(), 'ts' => new \JMS\TranslationBundle\Translation\Dumper\SymfonyDumperAdapter($this->get('translation.dumper.qt'), 'ts'), 'csv' => new \JMS\TranslationBundle\Translation\Dumper\SymfonyDumperAdapter($this->get('translation.dumper.csv'), 'csv'), 'ini' => new \JMS\TranslationBundle\Translation\Dumper\SymfonyDumperAdapter($this->get('translation.dumper.ini'), 'ini'), 'json' => new \JMS\TranslationBundle\Translation\Dumper\SymfonyDumperAdapter($this->get('translation.dumper.json'), 'json'), 'res' => new \JMS\TranslationBundle\Translation\Dumper\SymfonyDumperAdapter($this->get('translation.dumper.res'), 'res'), 'xliff' => $f)));
 }