Ver código fonte

restored default config options for DateTimeHandler

Johannes M. Schmitt 12 anos atrás
pai
commit
ccc9f1e937

+ 19 - 0
DependencyInjection/Configuration.php

@@ -44,6 +44,7 @@ class Configuration implements ConfigurationInterface
                 ->children()
         ;
 
+        $this->addHandlersSection($root);
         $this->addSerializersSection($root);
         $this->addMetadataSection($root);
         $this->addVisitorsSection($root);
@@ -51,6 +52,24 @@ class Configuration implements ConfigurationInterface
         return $tb;
     }
 
+    private function addHandlersSection(NodeBuilder $builder)
+    {
+        $builder
+            ->arrayNode('handlers')
+                ->addDefaultsIfNotSet()
+                ->children()
+                    ->arrayNode('datetime')
+                        ->addDefaultsIfNotSet()
+                        ->children()
+                            ->scalarNode('default_format')->defaultValue(\DateTime::ISO8601)->end()
+                            ->scalarNode('default_timezone')->defaultValue(date_default_timezone_get())->end()
+                        ->end()
+                   ->end()
+                ->end()
+            ->end()
+        ;
+    }
+
     private function addSerializersSection(NodeBuilder $builder)
     {
         $builder

+ 5 - 0
DependencyInjection/JMSSerializerExtension.php

@@ -34,6 +34,11 @@ class JMSSerializerExtension extends ConfigurableExtension
                         __DIR__.'/../Resources/config/')));
         $loader->load('services.xml');
 
+        // Built-in handlers.
+        $container->getDefinition('jms_serializer.datetime_handler')
+            ->addArgument($config['handlers']['datetime']['default_format'])
+            ->addArgument($config['handlers']['datetime']['default_timezone']);
+
         // property naming
         $container
             ->getDefinition('jms_serializer.camel_case_naming_strategy')

+ 22 - 0
UPGRADING.md

@@ -14,3 +14,25 @@ Upgrading From 0.9 to 1.0
 
     Please see the documentation for how to set-uup one of these.
 
+- Configuration
+
+    Most of the configuration under ``jms_serializer.handlers`` is gone. The order is not
+    important anymore as a handler can only be registered for one specific type.
+
+    You can still configure the built-in ``datetime`` handler though:
+
+    ```
+    jms_serializer:
+        handlers:
+            datetime:
+                default_format: DateTime::ISO8601
+                default_timzone: UTC
+    ```
+
+    This is not necessary anymore though as you can now specify the format each time when
+    you use a DateTime by using the @Type annotation:
+
+    ```
+    /** @Type("DateTime<'Y-m-d', 'UTC'>") */
+    private $createdAt;
+    ```