SonataAdminExtension.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /*
  3. * This file is part of the Sonata project.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. use Symfony\Component\DependencyInjection\Definition;
  15. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  16. use Symfony\Component\Config\FileLocator;
  17. use Symfony\Component\Config\Resource\FileResource;
  18. use Symfony\Component\Config\Definition\Processor;
  19. /**
  20. * SonataAdminBundleExtension
  21. *
  22. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  23. * @author Michael Williams <michael.williams@funsational.com>
  24. */
  25. class SonataAdminExtension extends Extension
  26. {
  27. protected $configNamespaces = array(
  28. 'templates' => array(
  29. 'layout',
  30. 'ajax'
  31. )
  32. );
  33. /**
  34. *
  35. * @param array $configs An array of configuration settings
  36. * @param ContainerBuilder $container A ContainerBuilder instance
  37. */
  38. public function load(array $configs, ContainerBuilder $container)
  39. {
  40. $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  41. $loader->load('templates.xml');
  42. $loader->load('doctrine_orm.xml');
  43. $loader->load('twig.xml');
  44. $loader->load('core.xml');
  45. $loader->load('form_types.xml');
  46. $configuration = new Configuration();
  47. $processor = new Processor();
  48. $config = $processor->process($configuration->getConfigTree($container->getParameter('kernel.debug')), $configs);
  49. // setups parameters with values in config.yml, default values from external files used if not
  50. $this->configSetupTemplates($config, $container);
  51. }
  52. protected function configSetupTemplates($config, $container)
  53. {
  54. foreach ($this->configNamespaces as $ns => $params) {
  55. if (!isset($config[$ns])) {
  56. continue;
  57. }
  58. foreach ($config[$ns] as $type => $template) {
  59. if (!isset($config[$ns][$type])) {
  60. continue;
  61. }
  62. $container->setParameter(sprintf('sonata.admin.templates.%s', $type), $template);
  63. }
  64. }
  65. }
  66. /**
  67. * Returns the base path for the XSD files.
  68. *
  69. * @return string The XSD base path
  70. */
  71. public function getXsdValidationBasePath()
  72. {
  73. return __DIR__.'/../Resources/config/schema';
  74. }
  75. public function getNamespace()
  76. {
  77. return 'http://www.sonata-project.org/schema/dic/admin';
  78. }
  79. public function getAlias()
  80. {
  81. return "sonata_admin";
  82. }
  83. }