Merge branch '2.0' into 2.1

* 2.0:
  Added comment
  [FrameworkBundle] Added tests for trusted_proxies configuration.
  [FrameworkBundle] Added a check on file mime type for CodeHelper::fileExcerpt()
  checked for a potentially missing key
  [FrameworkBundle] used the new method for trusted proxies
  remove realpath call

Conflicts:
	src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
This commit is contained in:
Fabien Potencier 2012-12-15 17:44:57 +01:00
commit aca311e077
7 changed files with 105 additions and 5 deletions

View File

@ -61,7 +61,15 @@ class Configuration implements ConfigurationInterface
})
->end()
->end()
->scalarNode('trust_proxy_headers')->defaultFalse()->end()
->scalarNode('trust_proxy_headers')->defaultFalse()->end() // @deprecated, to be removed in 2.3
->arrayNode('trusted_proxies')
->prototype('scalar')
->validate()
->ifTrue(function($v) { return !filter_var($v, FILTER_VALIDATE_IP); })
->thenInvalid('Invalid proxy IP "%s"')
->end()
->end()
->end()
->scalarNode('secret')->isRequired()->end()
->scalarNode('ide')->defaultNull()->end()
->booleanNode('test')->end()

View File

@ -61,6 +61,9 @@ class FrameworkExtension extends Extension
$container->setParameter('kernel.secret', $config['secret']);
$container->setParameter('kernel.trusted_proxies', $config['trusted_proxies']);
// @deprecated, to be removed in 2.3
$container->setParameter('kernel.trust_proxy_headers', $config['trust_proxy_headers']);
$container->setParameter('kernel.default_locale', $config['default_locale']);

View File

@ -40,8 +40,10 @@ class FrameworkBundle extends Bundle
{
public function boot()
{
if ($this->container->getParameter('kernel.trust_proxy_headers')) {
Request::trustProxyData();
if ($trustedProxies = $this->container->getParameter('kernel.trusted_proxies')) {
Request::setTrustedProxies($trustedProxies);
} elseif ($this->container->getParameter('kernel.trust_proxy_headers')) {
Request::trustProxyData(); // @deprecated, to be removed in 2.3
}
}

View File

@ -122,6 +122,15 @@ class CodeHelper extends Helper
public function fileExcerpt($file, $line)
{
if (is_readable($file)) {
if (extension_loaded('fileinfo')) {
$finfo = new \Finfo();
// Check if the file is an application/octet-stream (eg. Phar file) because hightlight_file cannot parse these files
if ('application/octet-stream' === $finfo->file($file, FILEINFO_MIME_TYPE)) {
return;
}
}
$code = highlight_file($file, true);
// remove main code/span tags
$code = preg_replace('#^<code.*?>\s*<span.*?>(.*)</span>\s*</code>#s', '\\1', $code);

View File

@ -0,0 +1,78 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration;
use Symfony\Component\Config\Definition\Processor;
class ConfigurationTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider getTestConfigTreeData
*/
public function testConfigTree($options, $results)
{
$processor = new Processor();
$configuration = new Configuration(array());
$config = $processor->processConfiguration($configuration, array($options));
$this->assertEquals($results, $config);
}
public function getTestConfigTreeData()
{
return array(
array(array('secret' => 's3cr3t'), array('secret' => 's3cr3t', 'trusted_proxies' => array(), 'trust_proxy_headers' => false, 'ide' => NULL, 'annotations' => array('cache' => 'file', 'file_cache_dir' => '%kernel.cache_dir%/annotations', 'debug' => false))),
);
}
/**
* @dataProvider getTestValidTrustedProxiesData
*/
public function testValidTrustedProxies($options, $results)
{
$processor = new Processor();
$configuration = new Configuration(array());
$config = $processor->processConfiguration($configuration, array($options));
$this->assertEquals($results, $config);
}
public function getTestValidTrustedProxiesData()
{
return array(
array(array('secret' => 's3cr3t', 'trusted_proxies' => array('127.0.0.1')), array('secret' => 's3cr3t', 'trusted_proxies' => array('127.0.0.1'), 'trust_proxy_headers' => false, 'ide' => NULL, 'annotations' => array('cache' => 'file', 'file_cache_dir' => '%kernel.cache_dir%/annotations', 'debug' => false))),
array(array('secret' => 's3cr3t', 'trusted_proxies' => array('::1')), array('secret' => 's3cr3t', 'trusted_proxies' => array('::1'), 'trust_proxy_headers' => false, 'ide' => NULL, 'annotations' => array('cache' => 'file', 'file_cache_dir' => '%kernel.cache_dir%/annotations', 'debug' => false))),
array(array('secret' => 's3cr3t', 'trusted_proxies' => array('127.0.0.1', '::1')), array('secret' => 's3cr3t', 'trusted_proxies' => array('127.0.0.1', '::1'), 'trust_proxy_headers' => false, 'ide' => NULL, 'annotations' => array('cache' => 'file', 'file_cache_dir' => '%kernel.cache_dir%/annotations', 'debug' => false))),
);
}
/**
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidTypeException
*/
public function testInvalidTypeTrustedProxies()
{
$processor = new Processor();
$configuration = new Configuration(array());
$config = $processor->processConfiguration($configuration, array(array('secret' => 's3cr3t', 'trusted_proxies' => 'Not an IP address')));
}
/**
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
*/
public function testInvalidValueTrustedProxies()
{
$processor = new Processor();
$configuration = new Configuration(array());
$config = $processor->processConfiguration($configuration, array(array('secret' => 's3cr3t', 'trusted_proxies' => array('Not an IP address'))));
}
}

View File

@ -172,7 +172,7 @@ abstract class Bundle extends ContainerAware implements BundleInterface
*/
public function registerCommands(Application $application)
{
if (!$dir = realpath($this->getPath().'/Command')) {
if (!is_dir($dir = $this->getPath().'/Command')) {
return;
}

View File

@ -195,7 +195,7 @@ class FlattenException
'short_class' => $class,
'class' => isset($entry['class']) ? $entry['class'] : '',
'type' => isset($entry['type']) ? $entry['type'] : '',
'function' => $entry['function'],
'function' => isset($entry['function']) ? $entry['function'] : null,
'file' => isset($entry['file']) ? $entry['file'] : null,
'line' => isset($entry['line']) ? $entry['line'] : null,
'args' => isset($entry['args']) ? $this->flattenArgs($entry['args']) : array(),