From 1e765c82af46110051eb75571fd548ecb09dd9ad Mon Sep 17 00:00:00 2001 From: WouterJ Date: Wed, 25 May 2016 12:12:27 +0200 Subject: [PATCH] Throw exception when PHP start tag is missing --- .../Component/Routing/Loader/AnnotationFileLoader.php | 5 +++++ .../Fixtures/OtherAnnotatedClasses/NoStartTagClass.php | 3 +++ .../Routing/Tests/Loader/AnnotationFileLoaderTest.php | 9 +++++++++ 3 files changed, 17 insertions(+) create mode 100644 src/Symfony/Component/Routing/Tests/Fixtures/OtherAnnotatedClasses/NoStartTagClass.php diff --git a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php index b8fc03615f..4dc41e16cd 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php @@ -92,6 +92,11 @@ class AnnotationFileLoader extends FileLoader $class = false; $namespace = false; $tokens = token_get_all(file_get_contents($file)); + + if (1 === count($tokens) && T_INLINE_HTML === $tokens[0][0]) { + throw new \InvalidArgumentException(sprintf('The file "%s" does not contain PHP code. Did you forgot to add the "loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooTrait.php'); } + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Did you forgot to add the "loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/NoStartTagClass.php'); + } + /** * @requires PHP 5.6 */