Upgrade framework
This commit is contained in:
54
vendor/symfony/routing/Loader/PhpFileLoader.php
vendored
54
vendor/symfony/routing/Loader/PhpFileLoader.php
vendored
@@ -13,6 +13,7 @@ namespace Symfony\Component\Routing\Loader;
|
||||
|
||||
use Symfony\Component\Config\Loader\FileLoader;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
/**
|
||||
@@ -21,23 +22,33 @@ use Symfony\Component\Routing\RouteCollection;
|
||||
* The file must return a RouteCollection instance.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Nicolas grekas <p@tchwork.com>
|
||||
* @author Jules Pietri <jules@heahprod.com>
|
||||
*/
|
||||
class PhpFileLoader extends FileLoader
|
||||
{
|
||||
/**
|
||||
* Loads a PHP file.
|
||||
*
|
||||
* @param string $file A PHP file path
|
||||
* @param string|null $type The resource type
|
||||
*
|
||||
* @return RouteCollection A RouteCollection instance
|
||||
*/
|
||||
public function load($file, $type = null)
|
||||
public function load(mixed $file, string $type = null): RouteCollection
|
||||
{
|
||||
$path = $this->locator->locate($file);
|
||||
$this->setCurrentDir(dirname($path));
|
||||
$this->setCurrentDir(\dirname($path));
|
||||
|
||||
// the closure forbids access to the private scope in the included file
|
||||
$loader = $this;
|
||||
$load = \Closure::bind(static function ($file) use ($loader) {
|
||||
return include $file;
|
||||
}, null, ProtectedPhpFileLoader::class);
|
||||
|
||||
$result = $load($path);
|
||||
|
||||
if (\is_object($result) && \is_callable($result)) {
|
||||
$collection = $this->callConfigurator($result, $path, $file);
|
||||
} else {
|
||||
$collection = $result;
|
||||
}
|
||||
|
||||
$collection = self::includeFile($path, $this);
|
||||
$collection->addResource(new FileResource($path));
|
||||
|
||||
return $collection;
|
||||
@@ -46,21 +57,24 @@ class PhpFileLoader extends FileLoader
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports($resource, $type = null)
|
||||
public function supports(mixed $resource, string $type = null): bool
|
||||
{
|
||||
return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'php' === $type);
|
||||
return \is_string($resource) && 'php' === pathinfo($resource, \PATHINFO_EXTENSION) && (!$type || 'php' === $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Safe include. Used for scope isolation.
|
||||
*
|
||||
* @param string $file File to include
|
||||
* @param PhpFileLoader $loader the loader variable is exposed to the included file below
|
||||
*
|
||||
* @return RouteCollection
|
||||
*/
|
||||
private static function includeFile($file, PhpFileLoader $loader)
|
||||
protected function callConfigurator(callable $result, string $path, string $file): RouteCollection
|
||||
{
|
||||
return include $file;
|
||||
$collection = new RouteCollection();
|
||||
|
||||
$result(new RoutingConfigurator($collection, $this, $path, $file, $this->env));
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class ProtectedPhpFileLoader extends PhpFileLoader
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user