8000 Merge branch '2.7' into 2.8 · src-run/symfony@f0a6ed8 · GitHub
[go: up one dir, main page]

Skip to content

Commit f0a6ed8

Browse files
Merge branch '2.7' into 2.8
* 2.7: [ClassLoader] Fix ClassCollectionLoader inlining with __halt_compiler
2 parents 29bf662 + e24cedb commit f0a6ed8

File tree

6 files changed

+67
-7
lines changed

6 files changed

+67
-7
lines changed

src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,15 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
104104
}
105105
}
106106

107-
$c = '(?:\s*+(?:(?:#|//)[^\n]*+\n|/\*(?:(?<!\*/).)++)?+)*+';
108-
$strictTypesRegex = str_replace('.', $c, "'^<\?php\s.declare.\(.strict_types.=.1.\).;'is");
107+
$spacesRegex = '(?:\s*+(?:(?:\#|//)[^\n]*+\n|/\*(?:(?<!\*/).)++)?+)*+';
108+
$dontInlineRegex = <<<REGEX
109+
'(?:
110+
^<\?php\s.declare.\(.strict_types.=.1.\).;
111+
| \b__halt_compiler.\(.\)
112+
| \b__(?:DIR|FILE)__\b
113+
)'isx
114+
REGEX;
115+
$dontInlineRegex = str_replace('.', $spacesRegex, $dontInlineRegex);
109116

110117
$cacheDir = explode(DIRECTORY_SEPARATOR, $cacheDir);
111118
$files = array();
@@ -118,7 +125,7 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
118125
$files[] = $file = $class->getFileName();
119126
$c = file_get_contents($file);
120127

121-
if (preg_match($strictTypesRegex, $c)) {
128+
if (preg_match($dontInlineRegex, $c)) {
122129
$file = explode(DIRECTORY_SEPARATOR, $file);
123130

124131
for ($i = 0; isset($file[$i], $cacheDir[$i]); ++$i) {

src/Symfony/Component/ClassLoader/Tests/ClassCollectionLoaderTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public function testCommentStripping()
235235
$strictTypes = defined('HHVM_VERSION') ? '' : "\nnamespace {require __DIR__.'/Fixtures/Namespaced/WithStrictTypes.php';}";
236236

237237
ClassCollectionLoader::load(
238-
array('Namespaced\\WithComments', 'Pearlike_WithComments', $strictTypes ? 'Namespaced\\WithStrictTypes' : 'Namespaced\\WithComments'),
238+
array('Namespaced\\WithComments', 'Pearlike_WithComments', 'Namespaced\\WithDirMagic', 'Namespaced\\WithFileMagic', 'Namespaced\\WithHaltCompiler', $strictTypes ? 'Namespaced\\WithStrictTypes' : 'Namespaced\\WithComments'),
239239
__DIR__,
240240
'bar',
241241
false
@@ -275,6 +275,9 @@ class Pearlike_WithComments
275275
public static $loaded = true;
276276
}
277277
}
278+
namespace {require __DIR__.'/Fixtures/Namespaced/WithDirMagic.php';}
279+
namespace {require __DIR__.'/Fixtures/Namespaced/WithFileMagic.php';}
280+
namespace {require __DIR__.'/Fixtures/Namespaced/WithHaltCompiler.php';}
278281
EOF
279282
.$strictTypes,
280283
str_replace(array("<?php \n", '\\\\'), array('', '/'), file_get_contents($file))

src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ public function getTestCreateMapTests()
7676
'Namespaced\\Foo' => realpath(__DIR__).'/Fixtures/Namespaced/Foo.php',
7777
'Namespaced\\Baz' => realpath(__DIR__).'/Fixtures/Namespaced/Baz.php',
7878
'Namespaced\\WithComments' => realpath(__DIR__).'/Fixtures/Namespaced/WithComments.php',
79-
'Namespaced\WithStrictTypes' => realpath(__DIR__).'/Fixtures/Namespaced/WithStrictTypes.php',
80-
),
81-
),
79+
'Namespaced\\WithStrictTypes' => realpath(__DIR__).'/Fixtures/Namespaced/WithStrictTypes.php',
80+
'Namespaced\\WithHaltCompiler' => realpath(__DIR__).'/Fixtures/Namespaced/WithHaltCompiler.php',
81+
'Namespaced\\WithDirMagic' => realpath(__DIR__).'/Fixtures/Namespaced/WithDirMagic.php',
82+
'Namespaced\\WithFileMagic' => realpath(__DIR__).'/Fixtures/Namespaced/WithFileMagic.php',
83+
)),
8284
array(__DIR__.'/Fixtures/beta/NamespaceCollision', array(
8385
'NamespaceCollision\\A\\B\\Bar' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Bar.php',
8486
'NamespaceCollision\\A\\B\\Foo' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Foo.php',
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/*
4+
* foo
5+
*/
6+
7+
namespace Namespaced;
8+
9+
class WithDirMagic
10+
{
11+
public function getDir()
12+
{
13+
return __DIR__;
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/*
4+
* foo
5+
*/
6+
7+
namespace Namespaced;
8+
9+
class WithFileMagic
10+
{
11+
public function getFile()
12+
{
13+
return __FILE__;
14+
}
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* foo
5+
*/
6+
7+
namespace Namespaced;
8+
9+
class WithHaltCompiler
10+
{
11+
}
12+
13+
// the end of the script execution
14+
__halt_compiler(); data
15+
data
16+
data
17+
data
18+
...

0 commit comments

Comments
 (0)
0