Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DI] generate preload.php file for PHP 7.4 in cache folder
- Loading branch information
1 parent
d6ac452
commit c4dad0d
Showing
8 changed files
with
175 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/Symfony/Component/DependencyInjection/Dumper/Preloader.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\DependencyInjection\Dumper; | ||
|
||
/** | ||
* @author Nicolas Grekas <p@tchwork.com> | ||
* | ||
* @internal | ||
*/ | ||
class Preloader | ||
{ | ||
public static function preload(array $classes) | ||
{ | ||
set_error_handler(function ($t, $m, $f, $l) { | ||
if (error_reporting() & $t) { | ||
if (__FILE__ !== $f) { | ||
throw new \ErrorException($m, 0, $t, $f, $l); | ||
} | ||
|
||
throw new \ReflectionException($m); | ||
} | ||
}); | ||
|
||
$prev = []; | ||
$preloaded = []; | ||
|
||
try { | ||
while ($prev !== $classes) { | ||
$prev = $classes; | ||
foreach ($classes as $c) { | ||
if (!isset($preloaded[$c])) { | ||
$preloaded[$c] = true; | ||
self::doPreload($c); | ||
} | ||
} | ||
$classes = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits()); | ||
} | ||
} finally { | ||
restore_error_handler(); | ||
} | ||
} | ||
|
||
private static function doPreload(string $class) | ||
{ | ||
if (\in_array($class, ['self', 'static', 'parent'], true)) { | ||
return; | ||
} | ||
|
||
try { | ||
$r = new \ReflectionClass($class); | ||
|
||
if ($r->isInternal()) { | ||
return; | ||
} | ||
|
||
$r->getConstants(); | ||
$r->getDefaultProperties(); | ||
|
||
if (\PHP_VERSION_ID >= 70400) { | ||
foreach ($r->getProperties() as $p) { | ||
if (($t = $p->getType()) && !$t->isBuiltin()) { | ||
self::doPreload($t->getName()); | ||
} | ||
} | ||
} | ||
|
||
foreach ($r->getMethods() as $m) { | ||
foreach ($m->getParameters() as $p) { | ||
if ($p->isDefaultValueAvailable() && $p->isDefaultValueConstant()) { | ||
$c = $p->getDefaultValueConstantName(); | ||
|
||
if ($i = strpos($c, '::')) { | ||
self::doPreload(substr($c, 0, $i)); | ||
} | ||
} | ||
|
||
if (($t = $p->getType()) && !$t->isBuiltin()) { | ||
self::doPreload($t->getName()); | ||
} | ||
} | ||
|
||
if (($t = $m->getReturnType()) && !$t->isBuiltin()) { | ||
self::doPreload($t->getName()); | ||
} | ||
} | ||
} catch (\ReflectionException $e) { | ||
// ignore missing classes | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.