mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-30 22:18:46 +02:00
migration symfony 5 4 (#300)
* symfony 5.4 (diff dev) * symfony 5.4 (working) * symfony 5.4 (update autoload) * symfony 5.4 (remove swiftmailer mailer implementation) * symfony 5.4 (php doc and split Global accessor class) ### Impacted packages: composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
This commit is contained in:
@@ -12,8 +12,8 @@
|
||||
namespace Symfony\Component\Config\Loader;
|
||||
|
||||
use Symfony\Component\Config\Exception\FileLoaderImportCircularReferenceException;
|
||||
use Symfony\Component\Config\Exception\FileLoaderLoadException;
|
||||
use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
|
||||
use Symfony\Component\Config\Exception\LoaderLoadException;
|
||||
use Symfony\Component\Config\FileLocatorInterface;
|
||||
use Symfony\Component\Config\Resource\FileExistenceResource;
|
||||
use Symfony\Component\Config\Resource\GlobResource;
|
||||
@@ -31,17 +31,16 @@ abstract class FileLoader extends Loader
|
||||
|
||||
private $currentDir;
|
||||
|
||||
public function __construct(FileLocatorInterface $locator)
|
||||
public function __construct(FileLocatorInterface $locator, string $env = null)
|
||||
{
|
||||
$this->locator = $locator;
|
||||
parent::__construct($env);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current directory.
|
||||
*
|
||||
* @param string $dir
|
||||
*/
|
||||
public function setCurrentDir($dir)
|
||||
public function setCurrentDir(string $dir)
|
||||
{
|
||||
$this->currentDir = $dir;
|
||||
}
|
||||
@@ -59,23 +58,32 @@ abstract class FileLoader extends Loader
|
||||
/**
|
||||
* Imports a resource.
|
||||
*
|
||||
* @param mixed $resource A Resource
|
||||
* @param string|null $type The resource type or null if unknown
|
||||
* @param bool $ignoreErrors Whether to ignore import errors or not
|
||||
* @param string|null $sourceResource The original resource importing the new resource
|
||||
* @param mixed $resource A Resource
|
||||
* @param string|null $type The resource type or null if unknown
|
||||
* @param bool $ignoreErrors Whether to ignore import errors or not
|
||||
* @param string|null $sourceResource The original resource importing the new resource
|
||||
* @param string|string[]|null $exclude Glob patterns to exclude from the import
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws FileLoaderLoadException
|
||||
* @throws LoaderLoadException
|
||||
* @throws FileLoaderImportCircularReferenceException
|
||||
* @throws FileLocatorFileNotFoundException
|
||||
*/
|
||||
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
|
||||
public function import($resource, string $type = null, bool $ignoreErrors = false, string $sourceResource = null, $exclude = null)
|
||||
{
|
||||
if (\is_string($resource) && \strlen($resource) !== $i = strcspn($resource, '*?{[')) {
|
||||
if (\is_string($resource) && \strlen($resource) !== ($i = strcspn($resource, '*?{[')) && !str_contains($resource, "\n")) {
|
||||
$excluded = [];
|
||||
foreach ((array) $exclude as $pattern) {
|
||||
foreach ($this->glob($pattern, true, $_, false, true) as $path => $info) {
|
||||
// normalize Windows slashes and remove trailing slashes
|
||||
$excluded[rtrim(str_replace('\\', '/', $path), '/')] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
$isSubpath = 0 !== $i && false !== strpos(substr($resource, 0, $i), '/');
|
||||
foreach ($this->glob($resource, false, $_, $ignoreErrors || !$isSubpath) as $path => $info) {
|
||||
$isSubpath = 0 !== $i && str_contains(substr($resource, 0, $i), '/');
|
||||
foreach ($this->glob($resource, false, $_, $ignoreErrors || !$isSubpath, false, $excluded) as $path => $info) {
|
||||
if (null !== $res = $this->doImport($path, 'glob' === $type ? null : $type, $ignoreErrors, $sourceResource)) {
|
||||
$ret[] = $res;
|
||||
}
|
||||
@@ -83,7 +91,7 @@ abstract class FileLoader extends Loader
|
||||
}
|
||||
|
||||
if ($isSubpath) {
|
||||
return isset($ret[1]) ? $ret : (isset($ret[0]) ? $ret[0] : null);
|
||||
return isset($ret[1]) ? $ret : ($ret[0] ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,12 +101,12 @@ abstract class FileLoader extends Loader
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected function glob($pattern, $recursive, &$resource = null, $ignoreErrors = false)
|
||||
protected function glob(string $pattern, bool $recursive, &$resource = null, bool $ignoreErrors = false, bool $forExclusion = false, array $excluded = [])
|
||||
{
|
||||
if (\strlen($pattern) === $i = strcspn($pattern, '*?{[')) {
|
||||
$prefix = $pattern;
|
||||
$pattern = '';
|
||||
} elseif (0 === $i || false === strpos(substr($pattern, 0, $i), '/')) {
|
||||
} elseif (0 === $i || !str_contains(substr($pattern, 0, $i), '/')) {
|
||||
$prefix = '.';
|
||||
$pattern = '/'.$pattern;
|
||||
} else {
|
||||
@@ -120,14 +128,12 @@ abstract class FileLoader extends Loader
|
||||
|
||||
return;
|
||||
}
|
||||
$resource = new GlobResource($prefix, $pattern, $recursive);
|
||||
$resource = new GlobResource($prefix, $pattern, $recursive, $forExclusion, $excluded);
|
||||
|
||||
foreach ($resource as $path => $info) {
|
||||
yield $path => $info;
|
||||
}
|
||||
yield from $resource;
|
||||
}
|
||||
|
||||
private function doImport($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
|
||||
private function doImport($resource, string $type = null, bool $ignoreErrors = false, string $sourceResource = null)
|
||||
{
|
||||
try {
|
||||
$loader = $this->resolve($resource, $type);
|
||||
@@ -161,11 +167,11 @@ abstract class FileLoader extends Loader
|
||||
} catch (\Exception $e) {
|
||||
if (!$ignoreErrors) {
|
||||
// prevent embedded imports from nesting multiple exceptions
|
||||
if ($e instanceof FileLoaderLoadException) {
|
||||
if ($e instanceof LoaderLoadException) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
throw new FileLoaderLoadException($resource, $sourceResource, null, $e, $type);
|
||||
throw new LoaderLoadException($resource, $sourceResource, 0, $e, $type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user