Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit419a9b5

Browse files
pulzarraidernicolas-grekas
authored andcommitted
[DependencyInjection] Added optionignore_errors: not_found while importing config files
1 parentba07cda commit419a9b5

14 files changed

+140
-5
lines changed

‎src/Symfony/Component/Config/Loader/FileLoader.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function getLocator()
7373
*/
7474
publicfunctionimport($resource,$type =null,$ignoreErrors =false,$sourceResource =null/*, $exclude = null*/)
7575
{
76-
if (\func_num_args() <5 &&__CLASS__ !==\get_class($this) &&__CLASS__ !== (new \ReflectionMethod($this,__FUNCTION__))->getDeclaringClass()->getName() && !$thisinstanceof \PHPUnit\Framework\MockObject\MockObject && !$thisinstanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
76+
if (\func_num_args() <5 &&__CLASS__ !==\get_class($this) &&0 !==strpos(\get_class($this),'Symfony\Component\\') &&__CLASS__ !== (new \ReflectionMethod($this,__FUNCTION__))->getDeclaringClass()->getName() && !$thisinstanceof \PHPUnit\Framework\MockObject\MockObject && !$thisinstanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
7777
@trigger_error(sprintf('The "%s()" method will have a new "$exclude = null" argument in version 5.0, not defining it is deprecated since Symfony 4.4.',__METHOD__),E_USER_DEPRECATED);
7878
}
7979
$exclude =\func_num_args() >=5 ?func_get_arg(4) :null;

‎src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ final public function extension(string $namespace, array $config)
6060
$this->container->loadFromExtension($namespace,static::processValue($config));
6161
}
6262

63-
finalpublicfunctionimport(string$resource,string$type =null,bool$ignoreErrors =false)
63+
finalpublicfunctionimport(string$resource,string$type =null,$ignoreErrors =false)
6464
{
6565
$this->loader->setCurrentDir(\dirname($this->path));
6666
$this->loader->import($resource,$type,$ignoreErrors,$this->file);

‎src/Symfony/Component/DependencyInjection/Loader/FileLoader.php‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespaceSymfony\Component\DependencyInjection\Loader;
1313

14+
useSymfony\Component\Config\Exception\FileLocatorFileNotFoundException;
15+
useSymfony\Component\Config\Exception\LoaderLoadException;
1416
useSymfony\Component\Config\FileLocatorInterface;
1517
useSymfony\Component\Config\Loader\FileLoaderasBaseFileLoader;
1618
useSymfony\Component\Config\Resource\GlobResource;
@@ -41,6 +43,42 @@ public function __construct(ContainerBuilder $container, FileLocatorInterface $l
4143
parent::__construct($locator);
4244
}
4345

46+
/**
47+
* {@inheritdoc}
48+
*
49+
* @param bool|string $ignoreErrors Whether errors should be ignored; pass "not_found" to ignore only when the loaded resource is not found
50+
* @param string|string[]|null $exclude Glob patterns to exclude from the import
51+
*/
52+
publicfunctionimport($resource,$type =null,$ignoreErrors =false,$sourceResource =null/*, $exclude = null*/)
53+
{
54+
$args =\func_get_args();
55+
56+
if ($ignoreNotFound ='not_found' ===$ignoreErrors) {
57+
$args[2] =false;
58+
}elseif (!\is_bool($ignoreErrors)) {
59+
@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);
60+
$args[2] = (bool)$ignoreErrors;
61+
}
62+
63+
try {
64+
parent::import(...$args);
65+
}catch (LoaderLoadException$e) {
66+
if (!$ignoreNotFound || !($prev =$e->getPrevious())instanceof FileLocatorFileNotFoundException) {
67+
throw$e;
68+
}
69+
70+
foreach ($prev->getTrace()as$frame) {
71+
if ('import' === ($frame['function'] ??null) && BaseFileLoader::class === ($frame['class'] ??null)) {
72+
break;
73+
}
74+
}
75+
76+
if ($args !==$frame['args']) {
77+
throw$e;
78+
}
79+
}
80+
}
81+
4482
/**
4583
* Registers a set of classes as services using PSR-4 for discovery.
4684
*

‎src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private function parseImports(\DOMDocument $xml, string $file)
105105
$defaultDirectory =\dirname($file);
106106
foreach ($importsas$import) {
107107
$this->setCurrentDir($defaultDirectory);
108-
$this->import($import->getAttribute('resource'), XmlUtils::phpize($import->getAttribute('type')) ?:null,(bool)XmlUtils::phpize($import->getAttribute('ignore-errors')),$file);
108+
$this->import($import->getAttribute('resource'), XmlUtils::phpize($import->getAttribute('type')) ?:null, XmlUtils::phpize($import->getAttribute('ignore-errors')) ?:false,$file);
109109
}
110110
}
111111

‎src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ private function parseImports(array $content, string $file)
191191
}
192192

193193
$this->setCurrentDir($defaultDirectory);
194-
$this->import($import['resource'],isset($import['type']) ?$import['type'] :null,isset($import['ignore_errors']) ? (bool)$import['ignore_errors'] :false,$file);
194+
$this->import($import['resource'],$import['type'] ??null,$import['ignore_errors'] ??false,$file);
195195
}
196196
}
197197

‎src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
]]></xsd:documentation>
7979
</xsd:annotation>
8080
<xsd:attributename="resource"type="xsd:string"use="required" />
81-
<xsd:attributename="ignore-errors"type="boolean" />
81+
<xsd:attributename="ignore-errors"type="ignore_errors" />
8282
<xsd:attributename="type"type="xsd:string" />
8383
</xsd:complexType>
8484

@@ -273,6 +273,12 @@
273273
</xsd:restriction>
274274
</xsd:simpleType>
275275

276+
<xsd:simpleTypename="ignore_errors">
277+
<xsd:restrictionbase="xsd:string">
278+
<xsd:patternvalue="(true|false|not_found)" />
279+
</xsd:restriction>
280+
</xsd:simpleType>
281+
276282
<xsd:simpleTypename="invalid_sequence">
277283
<xsd:restrictionbase="xsd:string">
278284
<xsd:enumerationvalue="null" />
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" ?>
2+
3+
<containerxmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
6+
<imports>
7+
<importresource="foo_fake.xml"ignore-errors="not_found" />
8+
</imports>
9+
</container>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" ?>
2+
3+
<containerxmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
6+
<imports>
7+
<importresource="nonvalid.xml"ignore-errors="not_found" />
8+
</imports>
9+
</container>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" ?>
2+
3+
<containerxmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
6+
<imports>
7+
<importresource="foo_fake.xml" />
8+
</imports>
9+
</container>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
imports:
2+
-{ resource: foo_fake.yml, ignore_errors: not_found }

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp