Configuration.php 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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\SerializerBundle\DependencyInjection;
  18. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  19. use Symfony\Component\Config\Definition\ConfigurationInterface;
  20. class Configuration implements ConfigurationInterface
  21. {
  22. private $debug;
  23. public function __construct($debug = false)
  24. {
  25. $this->debug = $debug;
  26. }
  27. public function getConfigTreeBuilder()
  28. {
  29. $tb = new TreeBuilder();
  30. $tb
  31. ->root('jms_serializer', 'array')
  32. ->children()
  33. ->arrayNode('property_naming')
  34. ->addDefaultsIfNotSet()
  35. ->children()
  36. ->scalarNode('id')->cannotBeEmpty()->end()
  37. ->scalarNode('separator')->defaultValue('_')->end()
  38. ->booleanNode('lower_case')->defaultTrue()->end()
  39. ->booleanNode('enable_cache')->defaultTrue()->end()
  40. ->end()
  41. ->end()
  42. ->arrayNode('handlers')
  43. ->addDefaultsIfNotSet()
  44. ->children()
  45. ->booleanNode('object_based_custom')->defaultTrue()->end()
  46. ->arrayNode('datetime')
  47. ->addDefaultsIfNotSet()
  48. ->canBeUnset()
  49. ->children()
  50. ->scalarNode('format')->defaultValue(\DateTime::ISO8601)->end()
  51. ->scalarNode('default_timezone')->defaultValue(date_default_timezone_get())->end()
  52. ->end()
  53. ->end()
  54. ->booleanNode('array_collection')->defaultTrue()->end()
  55. ->booleanNode('form_error')->defaultTrue()->end()
  56. ->booleanNode('constraint_violation')->defaultTrue()->end()
  57. ->end()
  58. ->end()
  59. ->arrayNode('metadata')
  60. ->addDefaultsIfNotSet()
  61. ->fixXmlConfig('directory', 'directories')
  62. ->children()
  63. ->scalarNode('cache')->defaultValue('file')->end()
  64. ->booleanNode('debug')->defaultValue($this->debug)->end()
  65. ->arrayNode('file_cache')
  66. ->addDefaultsIfNotSet()
  67. ->children()
  68. ->scalarNode('dir')->defaultValue('%kernel.cache_dir%/serializer')->end()
  69. ->end()
  70. ->end()
  71. ->booleanNode('auto_detection')->defaultTrue()->end()
  72. ->arrayNode('directories')
  73. ->prototype('array')
  74. ->children()
  75. ->scalarNode('path')->isRequired()->end()
  76. ->scalarNode('namespace_prefix')->defaultValue('')->end()
  77. ->end()
  78. ->end()
  79. ->end()
  80. ->end()
  81. ->end()
  82. ->end()
  83. ->end()
  84. ;
  85. return $tb;
  86. }
  87. }