8000 [WIP][HttpKernel] Expose bundle hierarchy/metadata as a service by ro0NL · Pull Request #19594 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WIP][HttpKernel] Expose bundle hierarchy/metadata as a service #19594

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
103 changes: 103 additions & 0 deletions src/Symfony/Component/HttpKernel/Bundle/BundleMetadata.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?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;

/**
* Value object representing bundle metadata.
*
* @author Roland Franssen <franssen.roland@gmail.com>
*/
final class BundleMetadata
{
private $name;
private $namespace;
private $className;
private $path;
private $parent;

/**
* Constructor.
*
* @param string $name
* @param string $namespace
* @param string $className
* @param string $path
* @param BundleMetadata|null $parent
*/
public function __construct($name, $namespace, $className, $path, BundleMetadata $parent = null)
{
$this->name = $name;
$this->className = $className;
$this->path = $path;
$this->parent = $parent;
}

/**
* Get bundle name.
8000 *
* @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 BundleMetadata|null
*/
public function getParent()
{
return $this->parent;
}

/**
* Get string representation.
*
* @return string
*/
public function __toString()
{
return $this->className;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a __toString really necessary? If you want the class name, you can just call it from the getter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.. i forgot to remove it. So ignore for now.

}
18 changes: 18 additions & 0 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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\BundleMetadata;
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
use Symfony\Component\HttpKernel\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
Expand Down Expand Up @@ -585,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()) {
Expand Down
0