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

Commit2c822d0

Browse files
committed
Add MicroExtension and deprecating ConfigurableExtension
1 parent7d717b9 commit2c822d0

File tree

18 files changed

+432
-68
lines changed

18 files changed

+432
-68
lines changed

‎UPGRADE-6.1.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ HttpKernel
1717
----------
1818

1919
* Deprecate StreamedResponseListener, it's not needed anymore
20+
* Deprecate`ConfigurableExtension` class, use`MicroExtension` instead
2021

2122
Serializer
2223
----------
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Config\Definition;
13+
14+
useSymfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
15+
16+
/**
17+
* @author Yonel Ceruto <yonelceruto@gmail.com>
18+
*/
19+
interface ConfigurableInterface
20+
{
21+
/**
22+
* Generates the configuration tree builder.
23+
*/
24+
publicfunctionconfiguration(DefinitionConfigurator$definition):void;
25+
}

‎src/Symfony/Component/HttpKernel/Bundle/BundleConfiguration.php‎renamed to ‎src/Symfony/Component/Config/Definition/Configuration.php‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespaceSymfony\Component\HttpKernel\Bundle;
12+
namespaceSymfony\Component\Config\Definition;
1313

1414
useSymfony\Component\Config\Definition\Builder\TreeBuilder;
15-
useSymfony\Component\Config\Definition\ConfigurationInterface;
1615
useSymfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
1716
useSymfony\Component\Config\Definition\Loader\DefinitionFileLoader;
1817
useSymfony\Component\Config\FileLocator;
@@ -21,25 +20,25 @@
2120
/**
2221
* @author Yonel Ceruto <yonelceruto@gmail.com>
2322
*
24-
* @internal
23+
* @final
2524
*/
26-
classBundleConfigurationimplements ConfigurationInterface
25+
classConfigurationimplements ConfigurationInterface
2726
{
2827
publicfunction__construct(
29-
privateMicroBundle$bundle,
30-
privateContainerBuilder$container,
28+
privateConfigurableInterface$subject,
29+
private?ContainerBuilder$container,
3130
privatestring$alias
3231
) {
3332
}
3433

3534
publicfunctiongetConfigTreeBuilder():TreeBuilder
3635
{
3736
$treeBuilder =newTreeBuilder($this->alias);
38-
$file = (new \ReflectionObject($this->bundle))->getFileName();
37+
$file = (new \ReflectionObject($this->subject))->getFileName();
3938
$loader =newDefinitionFileLoader($treeBuilder,newFileLocator(\dirname($file)),$this->container);
4039
$configurator =newDefinitionConfigurator($treeBuilder,$loader,$file,$file);
4140

42-
$this->bundle->configuration($configurator);
41+
$this->subject->configuration($configurator);
4342

4443
return$treeBuilder;
4544
}

‎src/Symfony/Component/DependencyInjection/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* Add`$exclude` to`TaggedIterator` and`TaggedLocator` attributes
88
* Add`$exclude` to`tagged_iterator` and`tagged_locator` configurator
99
* Add an`env` function to the expression language provider
10+
* Add`MicroExtension` class for DI configuration/definition on a single file
1011

1112
6.0
1213
---
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\DependencyInjection\Extension;
13+
14+
useSymfony\Component\Config\Definition\ConfigurableInterface;
15+
useSymfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
16+
useSymfony\Component\DependencyInjection\ContainerBuilder;
17+
useSymfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
18+
19+
/**
20+
* @author Yonel Ceruto <yonelceruto@gmail.com>
21+
*/
22+
interface ConfigurableExtensionInterfaceextends ConfigurableInterface
23+
{
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
publicfunctionconfiguration(DefinitionConfigurator$definition):void;
28+
29+
/**
30+
* Allow an extension to prepend the extension configurations.
31+
*/
32+
publicfunctionprependExtension(ContainerConfigurator$container,ContainerBuilder$builder):void;
33+
34+
/**
35+
* Loads a specific configuration.
36+
*/
37+
publicfunctionloadExtension(array$config,ContainerConfigurator$container,ContainerBuilder$builder):void;
38+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\DependencyInjection\Extension;
13+
14+
useSymfony\Component\Config\Builder\ConfigBuilderGenerator;
15+
useSymfony\Component\Config\FileLocator;
16+
useSymfony\Component\Config\Loader\DelegatingLoader;
17+
useSymfony\Component\Config\Loader\LoaderResolver;
18+
useSymfony\Component\DependencyInjection\ContainerBuilder;
19+
useSymfony\Component\DependencyInjection\Loader\ClosureLoader;
20+
useSymfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
21+
useSymfony\Component\DependencyInjection\Loader\DirectoryLoader;
22+
useSymfony\Component\DependencyInjection\Loader\GlobFileLoader;
23+
useSymfony\Component\DependencyInjection\Loader\IniFileLoader;
24+
useSymfony\Component\DependencyInjection\Loader\PhpFileLoader;
25+
useSymfony\Component\DependencyInjection\Loader\XmlFileLoader;
26+
useSymfony\Component\DependencyInjection\Loader\YamlFileLoader;
27+
28+
/**
29+
* @author Yonel Ceruto <yonelceruto@gmail.com>
30+
*/
31+
trait ExtensionTrait
32+
{
33+
privatefunctionexecuteConfiguratorCallback(ContainerBuilder$container,\Closure$callback,ConfigurableExtensionInterface$subject):void
34+
{
35+
$env =$container->getParameter('kernel.environment');
36+
$loader =$this->createContainerLoader($container,$env);
37+
$file = (new \ReflectionObject($subject))->getFileName();
38+
$bundleLoader =$loader->getResolver()->resolve($file);
39+
if (!$bundleLoaderinstanceof PhpFileLoader) {
40+
thrownew \LogicException('Unable to create the ContainerConfigurator.');
41+
}
42+
$bundleLoader->setCurrentDir(\dirname($file));
43+
$instanceof = &\Closure::bind(function &() {return$this->instanceof; },$bundleLoader,$bundleLoader)();
44+
45+
try {
46+
$callback(newContainerConfigurator($container,$bundleLoader,$instanceof,$file,$file,$env));
47+
}finally {
48+
$instanceof = [];
49+
$bundleLoader->registerAliasesForSinglyImplementedInterfaces();
50+
}
51+
}
52+
53+
privatefunctioncreateContainerLoader(ContainerBuilder$container,string$env):DelegatingLoader
54+
{
55+
$buildDir =$container->getParameter('kernel.build_dir');
56+
$locator =newFileLocator();
57+
$resolver =newLoaderResolver([
58+
newXmlFileLoader($container,$locator,$env),
59+
newYamlFileLoader($container,$locator,$env),
60+
newIniFileLoader($container,$locator,$env),
61+
newPhpFileLoader($container,$locator,$env,newConfigBuilderGenerator($buildDir)),
62+
newGlobFileLoader($container,$locator,$env),
63+
newDirectoryLoader($container,$locator,$env),
64+
newClosureLoader($container,$env),
65+
]);
66+
67+
returnnewDelegatingLoader($resolver);
68+
}
69+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\DependencyInjection\Extension;
13+
14+
useSymfony\Component\Config\Definition\Configuration;
15+
useSymfony\Component\Config\Definition\ConfigurationInterface;
16+
useSymfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
17+
useSymfony\Component\DependencyInjection\ContainerBuilder;
18+
useSymfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
19+
20+
/**
21+
* An Extension that provides configuration hooks.
22+
*
23+
* @author Yonel Ceruto <yonelceruto@gmail.com>
24+
*/
25+
abstractclass MicroExtensionextends Extensionimplements ConfigurableExtensionInterface, PrependExtensionInterface
26+
{
27+
use ExtensionTrait;
28+
29+
publicfunctionconfiguration(DefinitionConfigurator$definition):void
30+
{
31+
}
32+
33+
publicfunctionprependExtension(ContainerConfigurator$container,ContainerBuilder$builder):void
34+
{
35+
}
36+
37+
publicfunctionloadExtension(array$config,ContainerConfigurator$container,ContainerBuilder$builder):void
38+
{
39+
}
40+
41+
publicfunctiongetConfiguration(array$config,ContainerBuilder$container): ?ConfigurationInterface
42+
{
43+
returnnewConfiguration($this,$container,$this->getAlias());
44+
}
45+
46+
finalpublicfunctionprepend(ContainerBuilder$container):void
47+
{
48+
$callback =function (ContainerConfigurator$configurator)use ($container) {
49+
$this->prependExtension($configurator,$container);
50+
};
51+
52+
$this->executeConfiguratorCallback($container,$callback,$this);
53+
}
54+
55+
finalpublicfunctionload(array$configs,ContainerBuilder$container):void
56+
{
57+
$config =$this->processConfiguration($this->getConfiguration([],$container),$configs);
58+
59+
$callback =function (ContainerConfigurator$configurator)use ($config,$container) {
60+
$this->loadExtension($config,$configurator,$container);
61+
};
62+
63+
$this->executeConfiguratorCallback($container,$callback,$this);
64+
}
65+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp