Configuration.php 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /*
  3. * Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. namespace JMS\DiExtraBundle\DependencyInjection;
  18. use Doctrine\Common\Version;
  19. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  20. use Symfony\Component\Config\Definition\ConfigurationInterface;
  21. class Configuration implements ConfigurationInterface
  22. {
  23. public function getConfigTreeBuilder()
  24. {
  25. $tb = new TreeBuilder();
  26. $tb
  27. ->root('jms_di_extra', 'array')
  28. ->children()
  29. ->arrayNode('locations')
  30. ->addDefaultsIfNotSet()
  31. ->children()
  32. ->booleanNode('all_bundles')->defaultFalse()->end()
  33. ->arrayNode('bundles')
  34. ->beforeNormalization()
  35. ->ifString()
  36. ->then(function($v) {
  37. return preg_split('/\s*,\s*/', $v);
  38. })
  39. ->end()
  40. ->prototype('scalar')->end()
  41. ->end()
  42. ->arrayNode('directories')
  43. ->beforeNormalization()
  44. ->ifString()
  45. ->then(function($v) {
  46. return preg_split('/\s*,\s*/', $v);
  47. })
  48. ->end()
  49. ->prototype('scalar')->end()
  50. ->end()
  51. ->end()
  52. ->end()
  53. ->scalarNode('cache_dir')->defaultValue('%kernel.cache_dir%/jms_diextra')->end()
  54. ->arrayNode('metadata')
  55. ->addDefaultsIfNotSet()
  56. ->children()
  57. ->scalarNode('cache')->defaultValue('file')->cannotBeEmpty()->end()
  58. ->end()
  59. ->end()
  60. ->arrayNode('automatic_controller_injections')
  61. ->info('Allows you to configure automatic injections for controllers. '
  62. .'This is most useful for commonly needed services in controllers which then do not need to be annotated anymore.')
  63. ->fixXmlConfig('property')
  64. ->fixXmlConfig('method_call')
  65. ->children()
  66. ->arrayNode('properties')
  67. ->useAttributeAsKey('name')
  68. ->prototype('scalar')->end()
  69. ->end()
  70. ->arrayNode('method_calls')
  71. ->useAttributeAsKey('name')
  72. ->prototype('array')
  73. ->beforeNormalization()
  74. ->ifString()
  75. ->then(function($v) {
  76. return preg_split('/\s*,\s*/', $v);
  77. })
  78. ->end()
  79. ->prototype('scalar')->end()
  80. ->end()
  81. ->end()
  82. ->end()
  83. ->end()
  84. ->booleanNode('doctrine_integration')
  85. ->validate()
  86. ->always(function($v) {
  87. if ($v && !class_exists('Doctrine\ORM\EntityManager')) {
  88. throw new \Exception('Doctrine integration is only available for the Doctrine ORM at the moment.');
  89. }
  90. return $v;
  91. })
  92. ->end()
  93. ->defaultValue(class_exists('Doctrine\ORM\EntityManager'))->end()
  94. ->end()
  95. ->end();
  96. return $tb;
  97. }
  98. }