Skip to content

Commit 6b7dd44

Browse files
Merge branch '2.8' into 3.1
* 2.8: [ClassLoader] Fix ClassCollectionLoader inlining with __halt_compiler [Form] Fix tests to use FQCN
2 parents 61fea5a + f0a6ed8 commit 6b7dd44

File tree

7 files changed

+68
-8
lines changed

7 files changed

+68
-8
lines changed

src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,15 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
9898
$declared = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
9999
}
100100

101-
$c = '(?:\s*+(?:(?:#|//)[^\n]*+\n|/\*(?:(?<!\*/).)++)?+)*+';
102-
$strictTypesRegex = str_replace('.', $c, "'^<\?php\s.declare.\(.strict_types.=.1.\).;'is");
101+
$spacesRegex = '(?:\s*+(?:(?:\#|//)[^\n]*+\n|/\*(?:(?<!\*/).)++)?+)*+';
102+
$dontInlineRegex = <<<REGEX
103+
'(?:
104+
^<\?php\s.declare.\(.strict_types.=.1.\).;
105+
| \b__halt_compiler.\(.\)
106+
| \b__(?:DIR|FILE)__\b
107+
)'isx
108+
REGEX;
109+
$dontInlineRegex = str_replace('.', $spacesRegex, $dontInlineRegex);
103110

104111
$cacheDir = explode(DIRECTORY_SEPARATOR, $cacheDir);
105112
$files = array();
@@ -112,7 +119,7 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
112119
$files[] = $file = $class->getFileName();
113120
$c = file_get_contents($file);
114121

115-
if (preg_match($strictTypesRegex, $c)) {
122+
if (preg_match($dontInlineRegex, $c)) {
116123
$file = explode(DIRECTORY_SEPARATOR, $file);
117124

118125
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
@@ -228,7 +228,7 @@ public function testCommentStripping()
228228
$strictTypes = defined('HHVM_VERSION') ? '' : "\nnamespace {require __DIR__.'/Fixtures/Namespaced/WithStrictTypes.php';}";
229229

230230
ClassCollectionLoader::load(
231-
array('Namespaced\\WithComments', 'Pearlike_WithComments', $strictTypes ? 'Namespaced\\WithStrictTypes' : 'Namespaced\\WithComments'),
231+
array('Namespaced\\WithComments', 'Pearlike_WithComments', 'Namespaced\\WithDirMagic', 'Namespaced\\WithFileMagic', 'Namespaced\\WithHaltCompiler', $strictTypes ? 'Namespaced\\WithStrictTypes' : 'Namespaced\\WithComments'),
232232
__DIR__,
233233
'bar',
234234
false
@@ -268,6 +268,9 @@ class Pearlike_WithComments
268268
public static $loaded = true;
269269
}
270270
}
271+
namespace {require __DIR__.'/Fixtures/Namespaced/WithDirMagic.php';}
272+
namespace {require __DIR__.'/Fixtures/Namespaced/WithFileMagic.php';}
273+
namespace {require __DIR__.'/Fixtures/Namespaced/WithHaltCompiler.php';}
271274
EOF
272275
.$strictTypes,
273276
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+
...

src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public function testSubmitStringSingleTextWithoutMinutes()
223223

224224
public function testSubmitWithSecondsAndBrowserOmissionSeconds()
225225
{
226-
$form = $this->factory->create('time', null, array(
226+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
227227
'model_timezone' => 'UTC',
228228
'view_timezone' => 'UTC',
229229
'input' => 'string',

0 commit comments

Comments
 (0)