BaseApplicationExtension.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\Sonata\BaseApplicationBundle\Twig\Extension\BaseApplicationExtension')
  37. ->addTag('twig.extension');
  38. // registers crud action
  39. $definition = new Definition('Bundle\Sonata\BaseApplicationBundle\Admin\Pool');
  40. $definition->addMethodCall('setContainer', array(new Reference('service_container')));
  41. foreach($config['entities'] as $code => $configuration) {
  42. if(!isset($configuration['group'])) {
  43. $configuration['group'] = 'default';
  44. }
  45. if(!isset($configuration['label'])) {
  46. $configuration['label'] = $code;
  47. }
  48. $definition->addMethodCall('addConfiguration', array($code, $configuration));
  49. }
  50. $container->setDefinition('base_application.admin.pool', $definition);
  51. }
  52. /**
  53. * Returns the base path for the XSD files.
  54. *
  55. * @return string The XSD base path
  56. */
  57. public function getXsdValidationBasePath()
  58. {
  59. return __DIR__.'/../Resources/config/schema';
  60. }
  61. public function getNamespace()
  62. {
  63. return 'http://www.sonata-project.org/schema/dic/base-application';
  64. }
  65. public function getAlias()
  66. {
  67. return "base_application";
  68. }
  69. }