Permalink
Browse files

Refactor the monolithic DocumentationGenerator

This will pave the way to support ways other than annotations to map classes to vocabularies. Sadly, tests are still missing.
  • Loading branch information...
lanthaler committed Nov 2, 2013
1 parent 9ada1ec commit 2b92155d026c0cbacc6f5e20b0d50f09388b8588
@@ -16,6 +16,8 @@
/**
* The documentation generator controller
*
* @author Markus Lanthaler <mail@markus-lanthaler.com>
*/
class DocumentationGeneratorController extends Controller
{
@@ -27,7 +29,7 @@ class DocumentationGeneratorController extends Controller
*/
public function indexAction()
{
$documentation = $this->get('hydra.documentation_generator')->getDocumentation();
$documentation = $this->get('hydra.api')->getDocumentation();
return $documentation;
}
@@ -40,7 +42,7 @@ public function indexAction()
*/
public function vardumpAction()
{
$documentation = $this->get('hydra.documentation_generator')->getDocumentation();
$documentation = $this->get('hydra.api')->getDocumentation();
ini_set('xdebug.var_display_max_depth', '10');
die(var_dump($documentation));
@@ -54,10 +56,10 @@ public function vardumpAction()
*/
public function vocabularyAction()
{
$hydra = $this->get('hydra.documentation_generator');
$vocab = $hydra->getVocabulary();
$hydra = $this->get('hydra.api');
$documentation = $hydra->getDocumentation();
return new JsonLdResponse($vocab);
return new JsonLdResponse($documentation);
}
/**
@@ -67,7 +69,7 @@ public function vocabularyAction()
*/
public function getContextAction($type)
{
$context = $this->get('hydra.documentation_generator')->getContext($type);
$context = $this->get('hydra.api')->getContext($type);
if (null === $context) {
$this->createNotFoundException();
@@ -11,6 +11,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;
/**
* Adds all services with the tags "hydra.datatype_normalizer" as argument
@@ -29,10 +30,11 @@ public function process(ContainerBuilder $container)
$normalizers = array();
foreach ($container->findTaggedServiceIds('hydra.datatype_normalizer') as $serviceId => $attributes) {
if (isset($attributes[0]['class'])) {
$normalizers[$attributes[0]['class']] = $serviceId;
$normalizers[$attributes[0]['class']] = new Reference($serviceId);
}
}
$container->getDefinition('hydra.documentation_generator')->replaceArgument(3, $normalizers);
$container->getDefinition('hydra.documentation_generator')->replaceArgument(4, $normalizers);
$container->getDefinition('hydra.api')->replaceArgument(2, $normalizers);
}
}
@@ -1,14 +1,25 @@
<?php
/*
* (c) Markus Lanthaler <mail@markus-lanthaler.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ML\HydraBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* This is the class that validates and merges configuration from your app/config files
* HydraBundle Configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
* Definition of the configuration settings available for the HydraBundle;
* responsible for how the different settings are normalized, validated,
* and merged.
*
* @author Markus Lanthaler <mail@markus-lanthaler.com>
*/
class Configuration implements ConfigurationInterface
{
@@ -20,9 +31,55 @@ public function getConfigTreeBuilder()
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('hydra');
// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.
// TODO Add API title, description, entrypoint, and global status code descriptions,
// perhaps also references to supported classes
$rootNode
->fixXmlConfig('mapping')
->children()
->scalarNode('auto_mapping')->defaultValue(true)->end()
->scalarNode('naming_strategy')->defaultValue('hydra.naming_strategy.default')->end()
// FIXXME Do we need this!?
// ->scalarNode('metadata_factory_class')
// ->defaultValue('ML\Hydra\Metadata\MetadataFactory')
// ->end()
->arrayNode('metadata_cache_driver')
->addDefaultsIfNotSet()
->beforeNormalization()
->ifString()
->then(function($v) { return array('type' => $v); })
->end()
->children()
->scalarNode('type')->defaultValue('array')->end()
->scalarNode('file_cache_dir')->defaultValue('%kernel.cache_dir%/hydra')->end()
->scalarNode('host')->end()
->scalarNode('port')->end()
->scalarNode('instance_class')->end()
->scalarNode('class')->end()
->scalarNode('id')->end()
->end()
->end()
->arrayNode('mappings')
->useAttributeAsKey('name')
->prototype('array')
->beforeNormalization()
->ifString()
->then(function($v) { return array('type' => $v); })
->end()
->treatNullLike(array())
->treatFalseLike(array('mapping' => false))
->performNoDeepMerging()
->children()
->scalarNode('mapping')->defaultValue(true)->end()
->scalarNode('type')->end()
->scalarNode('dir')->end()
->scalarNode('prefix')->end()
->booleanNode('is_bundle')->end()
->end()
->end()
->end()
->end()
;
return $treeBuilder;
}
Oops, something went wrong.

0 comments on commit 2b92155

Please sign in to comment.