-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[RAD][HttpKernel] Create a MicroBundle base class #19596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpKernel\Bundle; | ||
|
||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\Config\Loader\DelegatingLoader; | ||
use Symfony\Component\Config\Loader\LoaderResolver; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\DependencyInjection\Container; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
use Symfony\Component\DependencyInjection\Loader\IniFileLoader; | ||
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; | ||
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader; | ||
use Symfony\Component\DependencyInjection\Loader\ClosureLoader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
/** | ||
* An implementation of a simple all-in-one {@link BundleInterface} and | ||
* configurable {@link Extension}. | ||
* | ||
* @author Guilhem N. <egetick@gmail.com> | ||
*/ | ||
abstract class SimpleBundle extends Bundle implements ConfigurationInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
final public function getContainerExtension() | ||
{ | ||
if (null === $this->extension) { | ||
$this->extension = new SimpleExtension($this); | ||
} | ||
|
||
return $this->extension; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
final public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
$rootNode = $treeBuilder->root($this->getContainerExtension()->getAlias()); | ||
|
||
$this->buildConfiguration($rootNode); | ||
|
||
return $treeBuilder; | ||
} | ||
|
||
protected function buildConfiguration(ArrayNodeDefinition $rootNode) | ||
{ | ||
} | ||
|
||
protected function load(array $config, ContainerBuilder $container, LoaderInterface $loader) | ||
{ | ||
} | ||
} | ||
|
||
/** | ||
* Simple {@link Extension} supporting {@link SimpleBundle}. | ||
* | ||
* @internal | ||
*/ | ||
final class SimpleExtension extends Extension | ||
{ | ||
private $bundle; | ||
|
||
public function __construct(SimpleBundle $bundle) | ||
{ | ||
$this->bundle = $bundle; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAlias() | ||
{ | ||
// check naming convention | ||
$basename = preg_replace('/Bundle$/', '', $this->bundle->getName()); | ||
|
||
return Container::underscore($basename); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should definitely add tests... But i'd like the symfony members' point of view before spending too much time on them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understand, i already planned taking it (if you're ok with it ;-)) and it's not accepted (hence the review :)). Perhaps create a composer gist then? Anyway.. hope this gets excepted 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem, that's made to be reused ;) |
||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$config = $this->processConfiguration($this->bundle, $configs); | ||
|
||
// Loader | ||
$locator = new FileLocator($this->bundle->getPath().'/Resources/config'); | ||
$resolver = new LoaderResolver(array( | ||
new XmlFileLoader($container, $locator), | ||
new YamlFileLoader($container, $locator), | ||
new IniFileLoader($container, $locator), | ||
new PhpFileLoader($container, $locator), | ||
new DirectoryLoader($container, $locator), | ||
new ClosureLoader($container), | ||
)); | ||
$loader = new DelegatingLoader($resolver); | ||
|
||
call_user_func(\Closure::bind(function () use ($config, $container, $loader) { | ||
$this->load($config, $container, $loader); | ||
}, $this->bundle, SimpleBundle::class)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getConfiguration(array $config, ContainerBuilder $container) | ||
{ | ||
return $this->bundle; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it :D