8000 [ClassLoader] Fix ClassCollectionLoader inlining with __halt_compiler by giosh94mhz · Pull Request #20455 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[ClassLoader] Fix ClassCollectionLoader inlining with __halt_compiler #20455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[ClassLoader] Fix ClassCollectionLoader inlining with __FILE__ and __…
…DIR__
  • Loading branch information
giosh94mhz committed Nov 15, 2016
commit 11cf77a38988a15c4e7096824d698e96dd6ec866
14 changes: 10 additions & 4 deletions src/Symfony/Component/ClassLoader/ClassCollectionLoader.php
8000
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,15 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
}
}

$c = '(?:\s*+(?:(?:#|//)[^\n]*+\n|/\*(?:(?<!\*/).)++)?+)*+';
$strictTypesRegex = str_replace('.', $c, "'^<\?php\s.declare.\(.strict_types.=.1.\).;'is");
$haltCompilerRegex = str_replace('.', $c, "'\b__halt_compiler.\(.\)'is");
$spacesRegex = '(?:\s*+(?:(?:\#|//)[^\n]*+\n|/\*(?:(?<!\*/).)++)?+)*+';
$dontInlineRegex = <<<REGEX
'(?:
^<\?php\s.declare.\(.strict_types.=.1.\).;
| \b__halt_compiler.\(.\)
| \b__(?:DIR|FILE)__\b
)'isx
REGEX;
$dontInlineRegex = str_replace('.', $spacesRegex, $dontInlineRegex);

$cacheDir = explode(DIRECTORY_SEPARATOR, $cacheDir);
$files = array();
Expand All @@ -119,7 +125,7 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
$files[] = $file = $class->getFileName();
$c = file_get_contents($file);

if (preg_match($strictTypesRegex, $c) || preg_match($haltCompilerRegex, $c)) {
if (preg_match($dontInlineRegex, $c)) {
$file = explode(DIRECTORY_SEPARATOR, $file);

for ($i = 0; isset($file[$i], $cacheDir[$i]); ++$i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public function testCommentStripping()
$strictTypes = defined('HHVM_VERSION') ? '' : "\nnamespace {require __DIR__.'/Fixtures/Namespaced/WithStrictTypes.php';}";

ClassCollectionLoader::load(
array('Namespaced\\WithComments', 'Pearlike_WithComments', 'Namespaced\\WithHaltCompiler', $strictTypes ? 'Namespaced\\WithStrictTypes' : 'Namespaced\\WithComments'),
array('Namespaced\\WithComments', 'Pearlike_WithComments', 'Namespaced\\WithDirMagic', 'Namespaced\\WithFileMagic', 'Namespaced\\WithHaltCompiler', $strictTypes ? 'Namespaced\\WithStrictTypes' : 'Namespaced\\WithComments'),
__DIR__,
'bar',
false
Expand Down Expand Up @@ -275,6 +275,8 @@ class Pearlike_WithComments
public static $loaded = true;
}
}
namespace {require __DIR__.'/Fixtures/Namespaced/WithDirMagic.php';}
namespace {require __DIR__.'/Fixtures/Namespaced/WithFileMagic.php';}
namespace {require __DIR__.'/Fixtures/Namespaced/WithHaltCompiler.php';}
EOF
.$strictTypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function getTestCreateMapTests()
'Namespaced\\WithComments' => realpath(__DIR__).'/Fixtures/Namespaced/WithComments.php',
'Namespaced\\WithStrictTypes' => realpath(__DIR__).'/Fixtures/Namespaced/WithStrictTypes.php',
'Namespaced\\WithHaltCompiler' => realpath(__DIR__).'/Fixtures/Namespaced/WithHaltCompiler.php',
'Namespaced\\WithDirMagic' => realpath(__DIR__).'/Fixtures/Namespaced/WithDirMagic.php',
'Namespaced\\WithFileMagic' => realpath(__DIR__).'/Fixtures/Namespaced/WithFileMagic.php',
)),
array(__DIR__.'/Fixtures/beta/NamespaceCollision', array(
'NamespaceCollision\\A\\B\\Bar' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Bar.php',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/*
* foo
*/

namespace Namespaced;

class WithDirMagic
{
public function getDir()
{
return __DIR__;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/*
* foo
*/

namespace Namespaced;

class WithFileMagic
{
public function getFile()
{
return __FILE__;
}
}
0