From 74e9851f9f8839210e4dcb2ab0378d869e6a5bdb Mon Sep 17 00:00:00 2001 From: Ener-Getick Date: Thu, 11 Aug 2016 11:55:23 +0200 Subject: [PATCH] [RAD][HttpKernel] Added MicroBundle --- .../HttpKernel/Bundle/SimpleBundle.php | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/Symfony/Component/HttpKernel/Bundle/SimpleBundle.php diff --git a/src/Symfony/Component/HttpKernel/Bundle/SimpleBundle.php b/src/Symfony/Component/HttpKernel/Bundle/SimpleBundle.php new file mode 100644 index 0000000000000..81f0170ef51ec --- /dev/null +++ b/src/Symfony/Component/HttpKernel/Bundle/SimpleBundle.php @@ -0,0 +1,129 @@ + + * + * 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. + */ +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); + } + + /** + * {@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; + } +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy