From 1e038cc6667bc11fc2ac12852e2e045ad0e5eee4 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Wed, 10 Aug 2016 16:57:12 +0000 Subject: [PATCH 1/3] poc --- .../Component/HttpKernel/Bundle/BundleVO.php | 103 ++++++++++++++++++ src/Symfony/Component/HttpKernel/Kernel.php | 21 +++- 2 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 src/Symfony/Component/HttpKernel/Bundle/BundleVO.php diff --git a/src/Symfony/Component/HttpKernel/Bundle/BundleVO.php b/src/Symfony/Component/HttpKernel/Bundle/BundleVO.php new file mode 100644 index 0000000000000..f0ddc66085bfd --- /dev/null +++ b/src/Symfony/Component/HttpKernel/Bundle/BundleVO.php @@ -0,0 +1,103 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Bundle; + +/** + * Bundle value object. + * + * @author Roland Franssen + */ +final class BundleVO +{ + private $name; + private $namespace; + private $className; + private $path; + private $parent; + + /** + * Constructor. + * + * @param string $name + * @param string $namespace + * @param string $className + * @param string $path + * @param BundleVO|null $parent + */ + public function __construct($name, $namespace, $className, $path, BundleVO $parent = null) + { + $this->name = $name; + $this->className = $className; + $this->path = $path; + $this->parent = $parent; + } + + /** + * Get bundle name. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Get bundle namespace. + * + * @return string + */ + public function getNamespace() + { + return $this->namespace; + } + + /** + * Get bundle class name. + * + * @return string + */ + public function getClassName() + { + return $this->className; + } + + /** + * Get bundle path. + * + * @return string + */ + public function getPath() + { + return $this->path; + } + + /** + * Get parent bundle, if any. + * + * @return BundleVO|null + */ + public function getParent() + { + return $this->parent; + } + + /** + * Get string representation. + * + * @return string + */ + public function __toString() + { + return $this->className; + } +} diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 125da81d5ca4d..5d4617dd5b239 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -26,6 +26,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Bundle\BundleInterface; +use Symfony\Component\HttpKernel\Bundle\BundleVO; use Symfony\Component\HttpKernel\Config\EnvParametersResource; use Symfony\Component\HttpKernel\Config\FileLocator; use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass; @@ -506,9 +507,22 @@ protected function initializeContainer() protected function getKernelParameters() { $bundles = array(); - foreach ($this->bundles as $name => $bundle) { - $bundles[$name] = get_class($bundle); - } + $bundleHierarchy = array(); + $numBundles = count($this->bundles); + $numProcessedBundles = 0; + do { + foreach ($this->bundles as $name => $bundle) { + $parent = $bundle->getParent(); + if (null !== $parent && !isset($bundles[$parent])) { + continue; + } + if (!isset($bundles[$name])) { + $bundles[$name] = get_class($bundle); + $bundleHierarchy[$name] = new BundleVO($name, $bundle->getNamespace(), $bundles[$name], $bundle->getPath(), isset($bundleHierarchy[$parent]) ? $bundleHierarchy[$parent] : null); + ++$numProcessedBundles; + } + } + } while ($numProcessedBundles < $numBundles); return array_merge( array( @@ -519,6 +533,7 @@ protected function getKernelParameters() 'kernel.cache_dir' => realpath($this->getCacheDir()) ?: $this->getCacheDir(), 'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(), 'kernel.bundles' => $bundles, + 'kernel.bundle_hierarchy' => $bundleHierarchy, 'kernel.charset' => $this->getCharset(), 'kernel.container_class' => $this->getContainerClass(), ), From 408972a06dc38ceb43d79f2660206aeef869f580 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Thu, 11 Aug 2016 16:15:51 +0000 Subject: [PATCH 2/3] renamed to BundleMetadata --- .../{BundleVO.php => BundleMetadata.php} | 18 +++++++++--------- src/Symfony/Component/HttpKernel/Kernel.php | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) rename src/Symfony/Component/HttpKernel/Bundle/{BundleVO.php => BundleMetadata.php} (81%) diff --git a/src/Symfony/Component/HttpKernel/Bundle/BundleVO.php b/src/Symfony/Component/HttpKernel/Bundle/BundleMetadata.php similarity index 81% rename from src/Symfony/Component/HttpKernel/Bundle/BundleVO.php rename to src/Symfony/Component/HttpKernel/Bundle/BundleMetadata.php index f0ddc66085bfd..50598d3479f62 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/BundleVO.php +++ b/src/Symfony/Component/HttpKernel/Bundle/BundleMetadata.php @@ -12,11 +12,11 @@ namespace Symfony\Component\HttpKernel\Bundle; /** - * Bundle value object. + * Value object representing bundle metadata. * * @author Roland Franssen */ -final class BundleVO +final class BundleMetadata { private $name; private $namespace; @@ -27,13 +27,13 @@ final class BundleVO /** * Constructor. * - * @param string $name - * @param string $namespace - * @param string $className - * @param string $path - * @param BundleVO|null $parent + * @param string $name + * @param string $namespace + * @param string $className + * @param string $path + * @param BundleMetadata|null $parent */ - public function __construct($name, $namespace, $className, $path, BundleVO $parent = null) + public function __construct($name, $namespace, $className, $path, BundleMetadata $parent = null) { $this->name = $name; $this->className = $className; @@ -84,7 +84,7 @@ public function getPath() /** * Get parent bundle, if any. * - * @return BundleVO|null + * @return BundleMetadata|null */ public function getParent() { diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 5d4617dd5b239..2e10360138fd0 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -26,7 +26,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Bundle\BundleInterface; -use Symfony\Component\HttpKernel\Bundle\BundleVO; +use Symfony\Component\HttpKernel\Bundle\BundleMetadata; use Symfony\Component\HttpKernel\Config\EnvParametersResource; use Symfony\Component\HttpKernel\Config\FileLocator; use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass; @@ -518,7 +518,7 @@ protected function getKernelParameters() } if (!isset($bundles[$name])) { $bundles[$name] = get_class($bundle); - $bundleHierarchy[$name] = new BundleVO($name, $bundle->getNamespace(), $bundles[$name], $bundle->getPath(), isset($bundleHierarchy[$parent]) ? $bundleHierarchy[$parent] : null); + $bundleHierarchy[$name] = new BundleMetadata($name, $bundle->getNamespace(), $bundles[$name], $bundle->getPath(), isset($bundleHierarchy[$parent]) ? $bundleHierarchy[$parent] : null); ++$numProcessedBundles; } } From 0aa08ea84b27547309e643de43ca28c80612673a Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Thu, 11 Aug 2016 16:51:22 +0000 Subject: [PATCH 3/3] try BundleMetadata[] as a service --- .../MergeExtensionConfigurationPass.php | 3 ++ src/Symfony/Component/HttpKernel/Kernel.php | 37 ++++++++++--------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php b/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php index f9e6024164c15..1fa43323e7467 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php @@ -47,6 +47,9 @@ public function process(ContainerBuilder $container) $tmpContainer = new ContainerBuilder($container->getParameterBag()); $tmpContainer->setResourceTracking($container->isTrackingResources()); $tmpContainer->addObjectResource($extension); + if ($container->has('kernel.bundles')) { + $tmpContainer->set('kernel.bundles', $container->get('kernel.bundles')); + } foreach ($exprLangProviders as $provider) { $tmpContainer->addExpressionLanguageProvider($provider); diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 2e10360138fd0..793f8ce9c7a2e 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -507,22 +507,9 @@ protected function initializeContainer() protected function getKernelParameters() { $bundles = array(); - $bundleHierarchy = array(); - $numBundles = count($this->bundles); - $numProcessedBundles = 0; - do { - foreach ($this->bundles as $name => $bundle) { - $parent = $bundle->getParent(); - if (null !== $parent && !isset($bundles[$parent])) { - continue; - } - if (!isset($bundles[$name])) { - $bundles[$name] = get_class($bundle); - $bundleHierarchy[$name] = new BundleMetadata($name, $bundle->getNamespace(), $bundles[$name], $bundle->getPath(), isset($bundleHierarchy[$parent]) ? $bundleHierarchy[$parent] : null); - ++$numProcessedBundles; - } - } - } while ($numProcessedBundles < $numBundles); + foreach ($this->bundles as $name => $bundle) { + $bundles[$name] = get_class($bundle); + } return array_merge( array( @@ -533,7 +520,6 @@ protected function getKernelParameters() 'kernel.cache_dir' => realpath($this->getCacheDir()) ?: $this->getCacheDir(), 'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(), 'kernel.bundles' => $bundles, - 'kernel.bundle_hierarchy' => $bundleHierarchy, 'kernel.charset' => $this->getCharset(), 'kernel.container_class' => $this->getContainerClass(), ), @@ -600,6 +586,23 @@ protected function buildContainer() */ protected function prepareContainer(ContainerBuilder $container) { + $bundleMetadata = array(); + $numBundles = count($this->bundles); + $numProcessedBundles = 0; + do { + foreach ($this->bundles as $name => $bundle) { + $parent = $bundle->getParent(); + if (null !== $parent && !isset($bundleMetadata[$parent])) { + continue; + } + if (!isset($bundleMetadata[$name])) { + $bundleMetadata[$name] = new BundleMetadata($name, $bundle->getNamespace(), get_class($bundle), $bundle->getPath(), isset($bundleMetadata[$parent]) ? $bundleMetadata[$parent] : null); + ++$numProcessedBundles; + } + } + } while ($numProcessedBundles < $numBundles); + $container->set('kernel.bundles', new \ArrayIterator($bundleMetadata)); + $extensions = array(); foreach ($this->bundles as $bundle) { if ($extension = $bundle->getContainerExtension()) {