Skip to content

Commit

Permalink
Merge branch '3.1'
Browse files Browse the repository at this point in the history
* 3.1:
  [ClassLoader] Fix ClassCollectionLoader inlining with __halt_compiler
  [Form] Fix tests to use FQCN
  • Loading branch information
nicolas-grekas committed Nov 15, 2016
2 parents e4e6380 + 6b7dd44 commit 67acdb0
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 8 deletions.
13 changes: 10 additions & 3 deletions src/Symfony/Component/ClassLoader/ClassCollectionLoader.php
Expand Up @@ -130,8 +130,15 @@ public static function inline($classes, $cache, array $excluded)
throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
}

$c = '(?:\s*+(?:(?:#|//)[^\n]*+\n|/\*(?:(?<!\*/).)++)?+)*+';
$strictTypesRegex = str_replace('.', $c, "'^<\?php\s.declare.\(.strict_types.=.1.\).;'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 @@ -145,7 +152,7 @@ public static function inline($classes, $cache, array $excluded)
$files[$class->getName()] = $file = $class->getFileName();
$c = file_get_contents($file);

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

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

ClassCollectionLoader::load(
array('Namespaced\\WithComments', 'Pearlike_WithComments', $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 @@ -270,6 +270,9 @@ 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,
str_replace(array("<?php \n", '\\\\'), array('', '/'), file_get_contents($file))
Expand Down
Expand Up @@ -76,9 +76,11 @@ public function getTestCreateMapTests()
'Namespaced\\Foo' => realpath(__DIR__).'/Fixtures/Namespaced/Foo.php',
'Namespaced\\Baz' => realpath(__DIR__).'/Fixtures/Namespaced/Baz.php',
'Namespaced\\WithComments' => realpath(__DIR__).'/Fixtures/Namespaced/WithComments.php',
'Namespaced\WithStrictTypes' => realpath(__DIR__).'/Fixtures/Namespaced/WithStrictTypes.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',
'NamespaceCollision\\A\\B\\Foo' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Foo.php',
Expand Down
@@ -0,0 +1,15 @@
<?php

/*
* foo
*/

namespace Namespaced;

class WithDirMagic
{
public function getDir()
{
return __DIR__;
}
}
@@ -0,0 +1,15 @@
<?php

/*
* foo
*/

namespace Namespaced;

class WithFileMagic
{
public function getFile()
{
return __FILE__;
}
}
@@ -0,0 +1,18 @@
<?php

/*
* foo
*/

namespace Namespaced;

class WithHaltCompiler
{
}

// the end of the script execution
__halt_compiler(); data
data
data
data
...
Expand Up @@ -223,7 +223,7 @@ public function testSubmitStringSingleTextWithoutMinutes()

public function testSubmitWithSecondsAndBrowserOmissionSeconds()
{
$form = $this->factory->create('time', null, array(
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'input' => 'string',
Expand Down

0 comments on commit 67acdb0

Please sign in to comment.