BaseApplicationExtension.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 Bundle\Sonata\BaseApplicationBundle\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  12. use Symfony\Component\DependencyInjection\Resource\FileResource;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. use Symfony\Component\DependencyInjection\Definition;
  16. use Symfony\Component\DependencyInjection\Extension\Extension;
  17. use Symfony\Component\Finder\Finder;
  18. /**
  19. * BaseApplicationExtension
  20. *
  21. *
  22. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  23. */
  24. class BaseApplicationExtension extends Extension
  25. {
  26. /**
  27. * Loads the url shortener configuration.
  28. *
  29. * @param array $config An array of configuration settings
  30. * @param ContainerBuilder $container A ContainerBuilder instance
  31. */
  32. public function configLoad($config, ContainerBuilder $container)
  33. {
  34. // register the twig extension
  35. $container
  36. ->register('twig.extension.base_application', 'Bundle\BaseApplicationBundle\Twig\Extension\BaseApplicationExtension')
  37. ->addMethodCall('setTemplating', array(new Reference('templating')))
  38. ->addTag('twig.extension');
  39. // registers crud action
  40. $definition = new Definition('Bundle\\BaseApplicationBundle\\Admin\\Pool');
  41. $definition->addMethodCall('setContainer', array(new Reference('service_container')));
  42. foreach($config['entities'] as $code => $configuration) {
  43. if(!isset($configuration['group'])) {
  44. $configuration['group'] = 'default';
  45. }
  46. if(!isset($configuration['label'])) {
  47. $configuration['label'] = $code;
  48. }
  49. $definition->addMethodCall('addConfiguration', array($code, $configuration));
  50. }
  51. $container->setDefinition('base_application.admin.pool', $definition);
  52. }
  53. /**
  54. * Returns the base path for the XSD files.
  55. *
  56. * @return string The XSD base path
  57. */
  58. public function getXsdValidationBasePath()
  59. {
  60. return __DIR__.'/../Resources/config/schema';
  61. }
  62. public function getNamespace()
  63. {
  64. return 'http://www.sonata-project.org/schema/dic/base-application';
  65. }
  66. public function getAlias()
  67. {
  68. return "base_application";
  69. }
  70. }