Throw exception when PHP start tag is missing
This commit is contained in:
parent
052c314bd0
commit
1e765c82af
@ -92,6 +92,11 @@ class AnnotationFileLoader extends FileLoader
|
|||||||
$class = false;
|
$class = false;
|
||||||
$namespace = false;
|
$namespace = false;
|
||||||
$tokens = token_get_all(file_get_contents($file));
|
$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 "<?php" start tag at the beginning of the file?', $file));
|
||||||
|
}
|
||||||
|
|
||||||
for ($i = 0; isset($tokens[$i]); ++$i) {
|
for ($i = 0; isset($tokens[$i]); ++$i) {
|
||||||
$token = $tokens[$i];
|
$token = $tokens[$i];
|
||||||
|
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
class NoStartTagClass
|
||||||
|
{
|
||||||
|
}
|
@ -45,6 +45,15 @@ class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
|
|||||||
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooTrait.php');
|
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooTrait.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
* @expectedExceptionMessage Did you forgot to add the "<?php" start tag at the beginning of the file?
|
||||||
|
*/
|
||||||
|
public function testLoadFileWithoutStartTag()
|
||||||
|
{
|
||||||
|
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/NoStartTagClass.php');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @requires PHP 5.6
|
* @requires PHP 5.6
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user