Configuration.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. ->end()
  40. ->end()
  41. ->arrayNode('handlers')
  42. ->addDefaultsIfNotSet()
  43. ->children()
  44. ->arrayNode('datetime')
  45. ->addDefaultsIfNotSet()
  46. ->canBeUnset()
  47. ->children()
  48. ->scalarNode('format')->defaultValue(\DateTime::ISO8601)->end()
  49. ->scalarNode('default_timezone')->defaultValue(date_default_timezone_get())->end()
  50. ->end()
  51. ->end()
  52. ->booleanNode('array_collection')->defaultTrue()->end()
  53. ->end()
  54. ->end()
  55. ->arrayNode('metadata')
  56. ->addDefaultsIfNotSet()
  57. ->children()
  58. ->scalarNode('cache')->defaultValue('file')->end()
  59. ->booleanNode('debug')->defaultValue($this->debug)->end()
  60. ->arrayNode('file_cache')
  61. ->addDefaultsIfNotSet()
  62. ->children()
  63. ->scalarNode('dir')->defaultValue('%kernel.cache_dir%/serializer')
  64. ->end()
  65. ->end()
  66. ->end()
  67. ->end()
  68. ->end()
  69. ->end()
  70. ;
  71. return $tb;
  72. }
  73. }