Skip to content
This repository
Browse code

made the charset overridable (closes #2072)

The charset was configurable in a configuration file but it never worked:

    framework:
        charset: ISO-8859-1

Now, like for the cache and log dirs, you can configure the charset by
overriding the getCharset() method in the app kernel:

    public function getCharset()
    {
        return 'ISO-8859-1';
    }
  • Loading branch information...
commit d9439aba718f9ed2a9809cbbc9b800dc3cb57ea5 1 parent 81fe2ff
Fabien Potencier authored July 03, 2012
16  src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
@@ -46,7 +46,21 @@ public function getConfigTreeBuilder()
46 46
 
47 47
         $rootNode
48 48
             ->children()
49  
-                ->scalarNode('charset')->info('general configuration')->end()
  49
+                ->scalarNode('charset')
  50
+                    ->defaultNull()
  51
+                    ->beforeNormalization()
  52
+                        ->ifTrue(function($v) { return null !== $v; })
  53
+                        ->then(function($v) {
  54
+                            $message = 'The charset setting is deprecated. Just remove it from your configuration file.';
  55
+
  56
+                            if ('UTF-8' !== $v) {
  57
+                                $messages .= sprintf(' You need to define a getCharset() method in your Application Kernel class that returns "%s".', $v);
  58
+                            }
  59
+
  60
+                            throw new \RuntimeException($message);
  61
+                        })
  62
+                    ->end()
  63
+                ->end()
50 64
                 ->scalarNode('trust_proxy_headers')->defaultFalse()->end()
51 65
                 ->scalarNode('secret')->isRequired()->end()
52 66
                 ->scalarNode('ide')->defaultNull()->end()
3  src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
@@ -60,9 +60,6 @@ public function load(array $configs, ContainerBuilder $container)
60 60
         $configuration = $this->getConfiguration($configs, $container);
61 61
         $config = $this->processConfiguration($configuration, $configs);
62 62
 
63  
-        if (isset($config['charset'])) {
64  
-            $container->setParameter('kernel.charset', $config['charset']);
65  
-        }
66 63
         $container->setParameter('kernel.secret', $config['secret']);
67 64
 
68 65
         $container->setParameter('kernel.trust_proxy_headers', $config['trust_proxy_headers']);
1  src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
@@ -21,6 +21,7 @@
21 21
             <xsd:element name="annotations" type="annotations" minOccurs="0" maxOccurs="1" />
22 22
         </xsd:all>
23 23
 
  24
+        <!-- charset is deprecated and will be removed in 2.2 -->
24 25
         <xsd:attribute name="charset" type="xsd:string" />
25 26
         <xsd:attribute name="trust-proxy-headers" type="xsd:string" />
26 27
         <xsd:attribute name="ide" type="xsd:string" />
1  src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml
... ...
@@ -1,5 +1,4 @@
1 1
 framework:
2  
-    charset:       UTF-8
3 2
     secret:        test
4 3
     csrf_protection:
5 4
         enabled: true
1  src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/framework.yml
... ...
@@ -1,5 +1,4 @@
1 1
 framework:
2  
-    charset:       UTF-8
3 2
     secret:        test
4 3
     csrf_protection:
5 4
         enabled: true
1  src/Symfony/Component/HttpKernel/CHANGELOG.md
Source Rendered
@@ -4,6 +4,7 @@ CHANGELOG
4 4
 2.1.0
5 5
 -----
6 6
 
  7
+ * [BC BREAK] the charset is now configured via the Kernel::getCharset() method
7 8
  * [BC BREAK] the current locale for the user is not stored anymore in the session
8 9
  * added the HTTP method to the profiler storage
9 10
  * updated all listeners to implement EventSubscriberInterface
14  src/Symfony/Component/HttpKernel/Kernel.php
@@ -468,6 +468,18 @@ public function getLogDir()
468 468
     }
469 469
 
470 470
     /**
  471
+     * Gets the charset of the application.
  472
+     *
  473
+     * @return string The charset
  474
+     *
  475
+     * @api
  476
+     */
  477
+    public function getCharset()
  478
+    {
  479
+        return 'UTF-8';
  480
+    }
  481
+
  482
+    /**
471 483
      * Initializes the data structures related to the bundle management.
472 484
      *
473 485
      *  - the bundles property maps a bundle name to the bundle instance,
@@ -601,7 +613,7 @@ protected function getKernelParameters()
601 613
                 'kernel.cache_dir'       => $this->getCacheDir(),
602 614
                 'kernel.logs_dir'        => $this->getLogDir(),
603 615
                 'kernel.bundles'         => $bundles,
604  
-                'kernel.charset'         => 'UTF-8',
  616
+                'kernel.charset'         => $this->getCharset(),
605 617
                 'kernel.container_class' => $this->getContainerClass(),
606 618
             ),
607 619
             $this->getEnvParameters()
9  src/Symfony/Component/HttpKernel/KernelInterface.php
@@ -196,4 +196,13 @@ function getCacheDir();
196 196
      * @api
197 197
      */
198 198
     function getLogDir();
  199
+
  200
+    /**
  201
+     * Gets the charset of the application.
  202
+     *
  203
+     * @return string The charset
  204
+     *
  205
+     * @api
  206
+     */
  207
+    function getCharset();
199 208
 }

0 notes on commit d9439ab

Please sign in to comment.
Something went wrong with that request. Please try again.