Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit556cfa1

Browse files
committed
Throw exception when PHP start tag is missing
1 parentc2f3b1e commit556cfa1

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

‎src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ protected function findClass($file)
9292
$class =false;
9393
$namespace =false;
9494
$tokens =token_get_all(file_get_contents($file));
95+
96+
if (1 ===count($tokens) &&T_INLINE_HTML ===$tokens[0][0]) {
97+
thrownew \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));
98+
}
99+
95100
for ($i =0;isset($tokens[$i]); ++$i) {
96101
$token =$tokens[$i];
97102

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
classNoStartTagClass
2+
{
3+
}

‎src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ public function testLoad()
3535
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
3636
}
3737

38+
/**
39+
* @expectedException \InvalidArgumentException
40+
* @expectedExceptionMessage Did you forgot to add the "<?php" start tag at the beginning of the file?
41+
*/
42+
publicfunctiontestLoadFileWithoutStartTag()
43+
{
44+
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/NoStartTagClass.php');
45+
}
46+
3847
/**
3948
* @requires PHP 5.6
4049
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp