merged branch fabpot/charset-fix (PR #4716)

Commits
-------

d9439ab made the charset overridable (closes #2072)

Discussion
----------

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';
    }

---------------------------------------------------------------------------

by fabpot at 2012-07-03T07:26:04Z

See #2072 for the previous attempts to fix this issue.
This commit is contained in:
Fabien Potencier 2012-07-03 10:43:15 +02:00
commit bf59b8677c
8 changed files with 39 additions and 7 deletions

View File

@ -46,7 +46,21 @@ class Configuration implements ConfigurationInterface
$rootNode
->children()
->scalarNode('charset')->info('general configuration')->end()
->scalarNode('charset')
->defaultNull()
->beforeNormalization()
->ifTrue(function($v) { return null !== $v; })
->then(function($v) {
$message = 'The charset setting is deprecated. Just remove it from your configuration file.';
if ('UTF-8' !== $v) {
$messages .= sprintf(' You need to define a getCharset() method in your Application Kernel class that returns "%s".', $v);
}
throw new \RuntimeException($message);
})
->end()
->end()
->scalarNode('trust_proxy_headers')->defaultFalse()->end()
->scalarNode('secret')->isRequired()->end()
->scalarNode('ide')->defaultNull()->end()

View File

@ -60,9 +60,6 @@ class FrameworkExtension extends Extension
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
if (isset($config['charset'])) {
$container->setParameter('kernel.charset', $config['charset']);
}
$container->setParameter('kernel.secret', $config['secret']);
$container->setParameter('kernel.trust_proxy_headers', $config['trust_proxy_headers']);

View File

@ -21,6 +21,7 @@
<xsd:element name="annotations" type="annotations" minOccurs="0" maxOccurs="1" />
</xsd:all>
<!-- charset is deprecated and will be removed in 2.2 -->
<xsd:attribute name="charset" type="xsd:string" />
<xsd:attribute name="trust-proxy-headers" type="xsd:string" />
<xsd:attribute name="ide" type="xsd:string" />

View File

@ -1,5 +1,4 @@
framework:
charset: UTF-8
secret: test
csrf_protection:
enabled: true

View File

@ -1,5 +1,4 @@
framework:
charset: UTF-8
secret: test
csrf_protection:
enabled: true

View File

@ -4,6 +4,7 @@ CHANGELOG
2.1.0
-----
* [BC BREAK] the charset is now configured via the Kernel::getCharset() method
* [BC BREAK] the current locale for the user is not stored anymore in the session
* added the HTTP method to the profiler storage
* updated all listeners to implement EventSubscriberInterface

View File

@ -467,6 +467,18 @@ abstract class Kernel implements KernelInterface, TerminableInterface
return $this->rootDir.'/logs';
}
/**
* Gets the charset of the application.
*
* @return string The charset
*
* @api
*/
public function getCharset()
{
return 'UTF-8';
}
/**
* Initializes the data structures related to the bundle management.
*
@ -601,7 +613,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface
'kernel.cache_dir' => $this->getCacheDir(),
'kernel.logs_dir' => $this->getLogDir(),
'kernel.bundles' => $bundles,
'kernel.charset' => 'UTF-8',
'kernel.charset' => $this->getCharset(),
'kernel.container_class' => $this->getContainerClass(),
),
$this->getEnvParameters()

View File

@ -196,4 +196,13 @@ interface KernelInterface extends HttpKernelInterface, \Serializable
* @api
*/
function getLogDir();
/**
* Gets the charset of the application.
*
* @return string The charset
*
* @api
*/
function getCharset();
}