|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\DependencyInjection\Loader;
|
13 | 13 |
|
| 14 | +use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException; |
| 15 | +use Symfony\Component\Config\Exception\LoaderLoadException; |
14 | 16 | use Symfony\Component\Config\FileLocatorInterface;
|
15 | 17 | use Symfony\Component\Config\Loader\FileLoader as BaseFileLoader;
|
| 18 | +use Symfony\Component\Config\Loader\Loader; |
16 | 19 | use Symfony\Component\Config\Resource\GlobResource;
|
17 | 20 | use Symfony\Component\DependencyInjection\ChildDefinition;
|
18 | 21 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
@@ -41,6 +44,42 @@ public function __construct(ContainerBuilder $container, FileLocatorInterface $l
|
41 | 44 | parent::__construct($locator);
|
42 | 45 | }
|
43 | 46 |
|
| 47 | + /** |
| 48 | + * {@inheritdoc} |
| 49 | + * |
| 50 | + * @param bool|string $ignoreErrors Whether errors should be ignored; pass "not_found" to ignore only when the loaded resource is not found |
| 51 | + * @param string|string[]|null $exclude Glob patterns to exclude from the import |
| 52 | + */ |
| 53 | + public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null/*, $exclude = null*/) |
| 54 | + { |
| 55 | + $args = \func_get_args(); |
| 56 | + |
| 57 | + if ($ignoreNotFound = 'not_found' === $ignoreErrors) { |
| 58 | + $args[2] = false; |
| 59 | + } elseif (!\is_bool($ignoreErrors)) { |
| 60 | + @trigger_error(sprintf('Invalid argument $ignoreErrors provided to %s::import(): boolean or "not_found" expected, %s given.', \get_class($this), \gettype($ignoreErrors)), E_USER_DEPRECATED); |
| 61 | + $args[2] = (bool) $ignoreErrors; |
| 62 | + } |
| 63 | + |
| 64 | + try { |
| 65 | + parent::import(...$args); |
| 66 | + } catch (LoaderLoadException $e) { |
| 67 | + if (!$ignoreNotFound || !($prev = $e->getPrevious()) instanceof FileLocatorFileNotFoundException) { |
| 68 | + throw $e; |
| 69 | + } |
| 70 | + |
| 71 | + foreach ($prev->getTrace() as $frame) { |
| 72 | + if ('import' === ($frame['function'] ?? null) && is_a($frame['class'] ?? '', Loader::class, true)) { |
| 73 | + break; |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + if ($args !== $frame['args']) { |
| 78 | + throw $e; |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + |
44 | 83 | /**
|
45 | 84 | * Registers a set of classes as services using PSR-4 for discovery.
|
46 | 85 | *
|
|
0 commit comments