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 1 commit
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
Next Next commit
poc
  • Loading branch information
ro0NL committed Aug 10, 2016
commit 1e038cc6667bc11fc2ac12852e2e045ad0e5eee4
103 changes: 103 additions & 0 deletions src/Symfony/Component/HttpKernel/Bundle/BundleVO.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;

/**
* Bundle value object.
*
* @author Roland Franssen <franssen.roland@gmail.com>
*/
final class BundleVO
Copy link
Contributor

Choose a reason for hiding this comment

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

BundleMetadata?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Will do.

{
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;
}
}
21 changes: 18 additions & 3 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\BundleVO;
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
use Symfony\Component\HttpKernel\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
Expand Down Expand Up @@ -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(
Expand All @@ -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(),
),
Expand Down
0