Ejemplo n.º 1
0
 /**
  * @param string $className
  * @param array  $mappingNode
  * @param string $path
  */
 protected function parseMappingNode($className, $mappingNode, $path)
 {
     if (!class_exists($className)) {
         throw new \InvalidArgumentException(sprintf('Configuration found for unknown class "%s" in "%s".', $className, $path));
     }
     $classMetadata = new ClassMetadata($className);
     $validKeys = array('uri_schema', 'conflict_resolver', 'defunct_route_handler', 'extend', 'token_providers');
     foreach ($mappingNode as $key => $value) {
         if (!in_array($key, $validKeys)) {
             throw new \InvalidArgumentException(sprintf('Invalid configuration key "%s". Valid keys are "%s"', $key, implode(',', $validKeys)));
         }
         switch ($key) {
             case 'uri_schema':
                 $classMetadata->setUriSchema($value);
                 break;
             case 'conflict_resolver':
                 $classMetadata->setConflictResolver($this->parseServiceConfig($mappingNode['conflict_resolver'], $className, $path));
                 break;
             case 'defunct_route_handler':
                 $classMetadata->setDefunctRouteHandler($this->parseServiceConfig($mappingNode['defunct_route_handler'], $className, $path));
                 break;
             case 'extend':
                 $classMetadata->setExtendedClass($mappingNode['extend']);
                 break;
             case 'token_providers':
                 foreach ($mappingNode['token_providers'] as $tokenName => $provider) {
                     $classMetadata->addTokenProvider($tokenName, $this->parseServiceConfig($provider, $className, $path));
                 }
         }
     }
     return $classMetadata;
 }
Ejemplo n.º 2
0
 /**
  * @param \DOMElement $mappingNode
  * @param string      $path
  *
  * @return ClassMetadata
  */
 protected function parseMappingNode(\DOMElement $mappingNode, $path)
 {
     $className = $this->readAttribute($mappingNode, 'class', sprintf('in "%s"', $path));
     if (!class_exists($className)) {
         throw new \InvalidArgumentException(sprintf('Configuration found for unknown class "%s" in "%s".', $className, $path));
     }
     $classMetadata = new ClassMetadata($className);
     try {
         $classMetadata->setUriSchema($this->readAttribute($mappingNode, 'uri-schema', sprintf('for "%s" in "%s"', $className, $path)));
         $classMetadata->setExtendedClass($this->readAttribute($mappingNode, 'extend', sprintf('for "%s" in "%s"', $className, $path)));
     } catch (\InvalidArgumentException $e) {
         // the extend and uri-schema attributes may be omitted
     }
     $conflictResolverNodes = $mappingNode->getElementsByTagNameNS(self::NAMESPACE_URI, 'conflict-resolver');
     $resolversLength = $conflictResolverNodes->length;
     if (1 < $resolversLength) {
         throw new \InvalidArgumentException(sprintf('There can only be one conflict resolver per mapping, %d given for "%s" in ""%s', $resolversLength, $className, $path));
     } elseif (1 === $resolversLength) {
         $this->parseConflictResolverNode($conflictResolverNodes->item(0), $classMetadata, $path);
     }
     $defunctRouteHandlerNodes = $mappingNode->getElementsByTagNameNS(self::NAMESPACE_URI, 'defunct-route-handler');
     $defunctRouteHandlerLength = $defunctRouteHandlerNodes->length;
     if (1 < $defunctRouteHandlerLength) {
         throw new \InvalidArgumentException(sprintf('There can only be one defunct route handler per mapping, %d given for "%s" in ""%s', $defunctRouteHandlerLength, $className, $path));
     } elseif (1 === $defunctRouteHandlerLength) {
         $this->parseDefunctRouteHandlerNode($defunctRouteHandlerNodes->item(0), $classMetadata, $path);
     }
     $tokenProviders = $mappingNode->getElementsByTagNameNS(self::NAMESPACE_URI, 'token-provider');
     // token providers can be omitted if the schema is constructed of
     // global token providers only
     if (0 !== count($tokenProviders)) {
         foreach ($tokenProviders as $tokenNode) {
             $this->parseTokenProviderNode($tokenNode, $classMetadata, $path);
         }
     }
     return $classMetadata;
 }
Ejemplo n.º 3
0
 /**
  * @expectedException \Symfony\Cmf\Component\RoutingAuto\Mapping\Exception\CircularReferenceException
  * @expectedExceptionMessage "Symfony\Cmf\Component\RoutingAuto\Tests\Resources\Fixtures\ChildClass"
  */
 public function testsFailsWithPhpCircularReference()
 {
     $childMetadata = new ClassMetadata('Symfony\\Cmf\\Component\\RoutingAuto\\Tests\\Resources\\Fixtures\\ChildClass');
     $childMetadata->setUriSchema('{title}');
     $parentMetadata = new ClassMetadata('Symfony\\Cmf\\Component\\RoutingAuto\\Tests\\Resources\\Fixtures\\ParentClass');
     $parentMetadata->setExtendedClass('Symfony\\Cmf\\Component\\RoutingAuto\\Tests\\Resources\\Fixtures\\ChildClass');
     $parentMetadata->addTokenProvider('title', $this->createTokenProvider('provider1'));
     $this->factory->addMetadatas(array($childMetadata, $parentMetadata));
     $this->factory->getMetadataForClass('Symfony\\Cmf\\Component\\RoutingAuto\\Tests\\Resources\\Fixtures\\ChildClass');
 }