diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 8d9b94cfff..8a8e598f12 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -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() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index d9eed7d87a..0b69d8c9c2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -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']); diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 544f2026ba..aec13c4aab 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -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 } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php index 3fdad98481..3c031d2c5b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php @@ -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('#^\s*(.*)\s*#s', '\\1', $code); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php new file mode 100644 index 0000000000..d6d7cf9a14 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -0,0 +1,78 @@ + + * + * 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')))); + } +} diff --git a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php index 494feabe58..3348456c54 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php +++ b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php @@ -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; } diff --git a/src/Symfony/Component/HttpKernel/Exception/FlattenException.php b/src/Symfony/Component/HttpKernel/Exception/FlattenException.php index b2ffb9fcfb..c42cb09baf 100644 --- a/src/Symfony/Component/HttpKernel/Exception/FlattenException.php +++ b/src/Symfony/Component/HttpKernel/Exception/FlattenException.php @@ -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(),