/** * @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; }
/** * @dataProvider provideTestMerge */ public function testMerge($parentData, $childData, $expectedData) { $parentMetadata = new ClassMetadata('Symfony\\Cmf\\Component\\RoutingAuto\\Tests\\Resources\\Fixtures\\ParentClass'); $parentMetadata->setDefunctRouteHandler($parentData['defunctRouteHandler']); $parentMetadata->setConflictResolver($parentData['conflictResolver']); $childMetadata = new ClassMetadata('Symfony\\Cmf\\Component\\RoutingAuto\\Tests\\Resources\\Fixtures\\ChildClass'); $childMetadata->setDefunctRouteHandler($childData['defunctRouteHandler']); $childMetadata->setConflictResolver($childData['conflictResolver']); $this->factory->addMetadatas(array($childMetadata, $parentMetadata)); $resolvedMetadata = $this->factory->getMetadataForClass('Symfony\\Cmf\\Component\\RoutingAuto\\Tests\\Resources\\Fixtures\\ChildClass'); $this->assertSame($expectedData['defunctRouteHandler'], $resolvedMetadata->getDefunctRouteHandler()); $this->assertSame($expectedData['conflictResolver'], $resolvedMetadata->getConflictResolver()); }
/** * @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); $this->validateNode($mappingNode, array('uri_schema', 'definitions', 'conflict_resolver', 'defunct_route_handler', 'extend', 'token_providers'), sprintf('routing auto class metadata (%s)', $className)); if (!isset($mappingNode['definitions'])) { throw new \InvalidArgumentException(sprintf('Mapping node for "%s" must define a list of auto route definitions under the `definitions` key.', $className)); } foreach ($mappingNode as $key => $value) { switch ($key) { case 'definitions': foreach ($this->getAutoRouteDefinitions($value) as $definitionName => $definition) { $classMetadata->setAutoRouteDefinition($definitionName, $definition); } 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)); } break; default: throw new \InvalidArgumentException(sprintf('Unknown mapping key "%s"', $key)); } } return $classMetadata; }
/** * @param \DOMElement $tokenNode * @param ClassMetadata $classMetadata * @param string $path */ protected function parseConflictResolverNode(\DOMElement $node, ClassMetadata $classMetadata, $path) { $name = $this->readAttribute($node, 'name', sprintf('in "%s" for "%s"', $path, $classMetadata->name)); $options = $this->parseOptionNode($node->getElementsByTagNameNS(self::NAMESPACE_URI, 'option'), $path); $classMetadata->setConflictResolver(array('name' => $name, 'options' => $options)); }