Пример #1
0
 /**
  * {@inheritdoc}
  */
 protected function loadMetadataFromFile(\ReflectionClass $class, $file)
 {
     $config = Yaml::parse(file_get_contents($file));
     if (!isset($config[$name = $class->getName()])) {
         throw new \RuntimeException(sprintf('Expected metadata for class %s to be defined in %s.', $name, $file));
     }
     $config = $config[$name];
     $classMetadata = new ClassMetadata($name);
     $classMetadata->fileResources[] = $file;
     $classMetadata->fileResources[] = $class->getFileName();
     if (isset($config['relations'])) {
         foreach ($config['relations'] as $relation) {
             $name = $relation['rel'];
             $href = null;
             if (isset($relation['href']) && is_array($href = $relation['href']) && isset($href['route'])) {
                 $href = new Route($href['route'], isset($href['parameters']) ? $href['parameters'] : array(), isset($href['absolute']) ? $href['absolute'] : false, isset($href['generator']) ? $href['generator'] : null);
             }
             $embed = null;
             if (isset($relation['embed'])) {
                 $embed = $relation['embed'];
                 if (is_array($embed)) {
                     $embedExclusion = null;
                     if (isset($embed['exclusion'])) {
                         $embedExclusion = $this->parseExclusion($embed['exclusion']);
                     }
                     $xmlElementName = isset($embed['xmlElementName']) ? $embed['xmlElementName'] : null;
                     $embed = new Embed($embed['content'], $xmlElementName, $embedExclusion);
                 }
             }
             $attributes = isset($relation['attributes']) ? $relation['attributes'] : array();
             $exclusion = null;
             if (isset($relation['exclusion'])) {
                 $exclusion = $this->parseExclusion($relation['exclusion']);
             }
             $classMetadata->addRelation(new Relation($name, $href, $embed, $attributes, $exclusion));
         }
     }
     if (isset($config['relation_providers'])) {
         foreach ($config['relation_providers'] as $relationProvider) {
             $classMetadata->addRelationProvider(new RelationProvider($relationProvider));
         }
     }
     return $classMetadata;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 protected function loadMetadataFromFile(\ReflectionClass $class, $file)
 {
     $previous = libxml_use_internal_errors(true);
     $root = simplexml_load_file($file);
     libxml_use_internal_errors($previous);
     if (false === $root) {
         throw new XmlErrorException(libxml_get_last_error());
     }
     $name = $class->getName();
     if (!($exists = $root->xpath("./class[@name = '" . $name . "']"))) {
         throw new \RuntimeException(sprintf('Expected metadata for class %s to be defined in %s.', $name, $file));
     }
     $classMetadata = new ClassMetadata($name);
     $classMetadata->fileResources[] = $file;
     $classMetadata->fileResources[] = $class->getFileName();
     if ($exists[0]->attributes(self::NAMESPACE_URI)->providers) {
         $providers = preg_split('/\\s*,\\s*/', (string) $exists[0]->attributes(self::NAMESPACE_URI)->providers);
         foreach ($providers as $relationProvider) {
             $classMetadata->addRelationProvider(new RelationProvider($relationProvider));
         }
     }
     $elements = $exists[0]->children(self::NAMESPACE_URI);
     foreach ($elements->relation as $relation) {
         $name = (string) $relation->attributes('')->rel;
         $href = null;
         if (isset($relation->href)) {
             $href = $this->createHref($relation->href, $name);
         }
         $embedded = null;
         if (isset($relation->embedded)) {
             $embedded = $this->createEmbedded($relation->embedded);
         }
         $attributes = array();
         foreach ($relation->attribute as $attribute) {
             $attributes[(string) $attribute->attributes('')->name] = (string) $attribute->attributes('')->value;
         }
         $exclusion = isset($relation->exclusion) ? $this->parseExclusion($relation->exclusion) : null;
         $classMetadata->addRelation(new Relation($name, $href, $embedded, $attributes, $exclusion));
     }
     return $classMetadata;
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 protected function loadMetadataFromFile(\ReflectionClass $class, $file)
 {
     $config = Yaml::parse(file_get_contents($file));
     if (!isset($config[$name = $class->getName()])) {
         throw new \RuntimeException(sprintf('Expected metadata for class %s to be defined in %s.', $name, $file));
     }
     $config = $config[$name];
     $classMetadata = new ClassMetadata($name);
     $classMetadata->fileResources[] = $file;
     $classMetadata->fileResources[] = $class->getFileName();
     if (isset($config['relations'])) {
         foreach ($config['relations'] as $relation) {
             $classMetadata->addRelation(new Relation($relation['rel'], $this->createHref($relation), $this->createEmbedded($relation), isset($relation['attributes']) ? $relation['attributes'] : array(), $this->createExclusion($relation)));
         }
     }
     if (isset($config['relation_providers'])) {
         foreach ($config['relation_providers'] as $relationProvider) {
             $classMetadata->addRelationProvider(new RelationProvider($relationProvider));
         }
     }
     return $classMetadata;
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass(\ReflectionClass $class)
 {
     $annotations = $this->reader->getClassAnnotations($class);
     if (0 === count($annotations)) {
         return null;
     }
     $classMetadata = new ClassMetadata($class->getName());
     $classMetadata->fileResources[] = $class->getFilename();
     foreach ($annotations as $annotation) {
         if ($annotation instanceof Annotation\Relation) {
             $classMetadata->addRelation(new Relation($annotation->name, $this->createHref($annotation->href), $this->createEmbedded($annotation->embedded), $annotation->attributes ?: array(), $this->createExclusion($annotation->exclusion)));
         } elseif ($annotation instanceof Annotation\RelationProvider) {
             $classMetadata->addRelationProvider(new RelationProvider($annotation->name));
         }
     }
     if (0 === count($classMetadata->getRelations()) && 0 === count($classMetadata->getRelationProviders())) {
         return null;
     }
     return $classMetadata;
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass(\ReflectionClass $class)
 {
     $annotations = $this->reader->getClassAnnotations($class);
     if (0 === count($annotations)) {
         return null;
     }
     $classMetadata = new ClassMetadata($class->getName());
     $classMetadata->fileResources[] = $class->getFilename();
     foreach ($annotations as $annotation) {
         if ($annotation instanceof Annotation\Relation) {
             $href = $annotation->href;
             if ($href instanceof Annotation\Route) {
                 $href = new Route($href->name, $href->parameters, $href->absolute, $href->generator);
             }
             $embed = $annotation->embed;
             if ($embed instanceof Annotation\Embed) {
                 $embedExclusion = $embed->exclusion;
                 if (null !== $embedExclusion) {
                     $embedExclusion = $this->parseExclusion($embedExclusion);
                 }
                 $embed = new Embed($embed->content, $embed->xmlElementName, $embedExclusion);
             }
             $exclusion = $annotation->exclusion;
             if (null !== $exclusion) {
                 $exclusion = $this->parseExclusion($exclusion);
             }
             $classMetadata->addRelation(new Relation($annotation->name, $href, $embed, $annotation->attributes ?: array(), $exclusion));
         } elseif ($annotation instanceof Annotation\RelationProvider) {
             $classMetadata->addRelationProvider(new RelationProvider($annotation->name));
         }
     }
     if (0 === count($classMetadata->getRelations()) && 0 === count($classMetadata->getRelationProviders())) {
         return null;
     }
     return $classMetadata;
 }