Bundle.php in Zircon Profile 8
File
vendor/symfony/http-kernel/Bundle/Bundle.php
View source
<?php
namespace Symfony\Component\HttpKernel\Bundle;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Console\Application;
use Symfony\Component\Finder\Finder;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
abstract class Bundle extends ContainerAware implements BundleInterface {
protected $name;
protected $extension;
protected $path;
public function boot() {
}
public function shutdown() {
}
public function build(ContainerBuilder $container) {
}
public function getContainerExtension() {
if (null === $this->extension) {
$class = $this
->getContainerExtensionClass();
if (class_exists($class)) {
$extension = new $class();
if (!$extension instanceof ExtensionInterface) {
throw new \LogicException(sprintf('Extension %s must implement Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface.', $class));
}
$basename = preg_replace('/Bundle$/', '', $this
->getName());
$expectedAlias = Container::underscore($basename);
if ($expectedAlias != $extension
->getAlias()) {
throw new \LogicException(sprintf('Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.', $expectedAlias, $extension
->getAlias()));
}
$this->extension = $extension;
}
else {
$this->extension = false;
}
}
if ($this->extension) {
return $this->extension;
}
}
public function getNamespace() {
$class = get_class($this);
return substr($class, 0, strrpos($class, '\\'));
}
public function getPath() {
if (null === $this->path) {
$reflected = new \ReflectionObject($this);
$this->path = dirname($reflected
->getFileName());
}
return $this->path;
}
public function getParent() {
}
public final function getName() {
if (null !== $this->name) {
return $this->name;
}
$name = get_class($this);
$pos = strrpos($name, '\\');
return $this->name = false === $pos ? $name : substr($name, $pos + 1);
}
public function registerCommands(Application $application) {
if (!is_dir($dir = $this
->getPath() . '/Command')) {
return;
}
$finder = new Finder();
$finder
->files()
->name('*Command.php')
->in($dir);
$prefix = $this
->getNamespace() . '\\Command';
foreach ($finder as $file) {
$ns = $prefix;
if ($relativePath = $file
->getRelativePath()) {
$ns .= '\\' . strtr($relativePath, '/', '\\');
}
$class = $ns . '\\' . $file
->getBasename('.php');
if ($this->container) {
$alias = 'console.command.' . strtolower(str_replace('\\', '_', $class));
if ($this->container
->has($alias)) {
continue;
}
}
$r = new \ReflectionClass($class);
if ($r
->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r
->isAbstract() && !$r
->getConstructor()
->getNumberOfRequiredParameters()) {
$application
->add($r
->newInstance());
}
}
}
protected function getContainerExtensionClass() {
$basename = preg_replace('/Bundle$/', '', $this
->getName());
return $this
->getNamespace() . '\\DependencyInjection\\' . $basename . 'Extension';
}
}
Classes
Name |
Description |
Bundle |
An implementation of BundleInterface that adds a few conventions
for DependencyInjection extensions and Console commands. |