diff --git a/src/Symfony/Component/Routing/Loader/PhpFileLoader.php b/src/Symfony/Component/Routing/Loader/PhpFileLoader.php index b4ba5fbc7f8ba..038cb21034de0 100644 --- a/src/Symfony/Component/Routing/Loader/PhpFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/PhpFileLoader.php @@ -61,6 +61,12 @@ public function supports($resource, $type = null) */ private static function includeFile($file, PhpFileLoader $loader) { - return include $file; + $collection = include $file; + + if (!$collection instanceof RouteCollection) { + throw new \UnexpectedValueException(sprintf('PHP routing configuration must return a RouteCollection, got "%s" in "%s".', is_object($collection) ? get_class($collection) : gettype($collection), $file)); + } + + return $collection; } } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/invalid_return.php b/src/Symfony/Component/Routing/Tests/Fixtures/invalid_return.php new file mode 100644 index 0000000000000..d8fed16db42be --- /dev/null +++ b/src/Symfony/Component/Routing/Tests/Fixtures/invalid_return.php @@ -0,0 +1,3 @@ +load('invalid_return.php'); + } } diff --git a/src/Symfony/Component/Translation/Loader/PhpFileLoader.php b/src/Symfony/Component/Translation/Loader/PhpFileLoader.php index a52e0bb611105..e3855e4c68abf 100644 --- a/src/Symfony/Component/Translation/Loader/PhpFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/PhpFileLoader.php @@ -37,6 +37,10 @@ public function load($resource, $locale, $domain = 'messages') $messages = require $resource; + if (!is_array($messages)) { + throw new \UnexpectedValueException(sprintf('PHP translation files must return an array, got "%s" in "%s".', is_object($messages) ? get_class($messages) : gettype($messages), $resource)); + } + $catalogue = parent::load($messages, $locale, $domain); if (class_exists('Symfony\Component\Config\Resource\FileResource')) { diff --git a/src/Symfony/Component/Translation/Tests/Loader/PhpFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/PhpFileLoaderTest.php index 9fc83e34f99ad..50bbae441152f 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/PhpFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/PhpFileLoaderTest.php @@ -47,4 +47,14 @@ public function testLoadThrowsAnExceptionIfFileNotLocal() $resource = 'http://example.com/resources.php'; $loader->load($resource, 'en', 'domain1'); } + + /** + * @expectedException \UnexpectedValueException + * @expectedExceptionMessageRegExp /^PHP translation files must return an array, got "stdClass" in ".+invalid-return\.php"\.$/ + */ + public function testInvalidReturn() + { + $loader = new PhpFileLoader(); + $loader->load(__DIR__.'/../fixtures/invalid-return.php', 'en'); + } } diff --git a/src/Symfony/Component/Translation/Tests/fixtures/invalid-return.php b/src/Symfony/Component/Translation/Tests/fixtures/invalid-return.php new file mode 100644 index 0000000000000..488bf694bb1bc --- /dev/null +++ b/src/Symfony/Component/Translation/Tests/fixtures/invalid-return.php @@ -0,0 +1,3 @@ +