This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/HttpKernel/Bundle/Bundle.php

170 lines
4.5 KiB
PHP
Raw Normal View History

<?php
removed Symfony\Framework Things have been moved to Symfony\Component\HttpKernel and Symfony\Bundle\FrameworkBundle The kernel configuration namespace was removed and merged with the main web configuration namespace (kernel:config => web:config, kernel:test => web:test, and kernel:session => web:session): Before: <kernel:config charset="UTF-8" error_handler="null" /> <web:config csrf-secret="xxxxxxxxxx"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> After: <web:config csrf-secret="xxxxxxxxxx" charset="UTF-8" error-handler="null"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> Renamed classes: Symfony\{Framework => Bundle\FrameworkBundle}\Cache\Cache Symfony\{Framework => Bundle\FrameworkBundle}\Client Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcher Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcherTraceableInterface Symfony\{Framework => Bundle\FrameworkBundle}\EventDispatcher Symfony\{Framework => Component\HttpFoundation}\UniversalClassLoader Symfony\{Framework => Component\HttpKernel}\Bundle\Bundle Symfony\{Framework => Component\HttpKernel}\Bundle\BundleInterface Symfony\{Framework => Component\HttpKernel}\ClassCollectionLoader Symfony\{Framework => Component\HttpKernel}\Debug\ErrorException Symfony\{Framework => Component\HttpKernel}\Debug\ErrorHandler Symfony\{Bundle\FrameworkBundle => Component\HttpKernel}\Debug\ExceptionListener Symfony\{Framework => Component\HttpKernel}\Kernel
2010-09-15 19:49:16 +01:00
namespace Symfony\Component\HttpKernel\Bundle;
2010-08-28 08:39:04 +01:00
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Finder\Finder;
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
2010-10-12 11:54:14 +01:00
* An implementation of the BundleInterface that follows a few conventions
* for the DependencyInjection extensions and the Console commands.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
2010-08-28 08:39:04 +01:00
abstract class Bundle extends ContainerAware implements BundleInterface
{
2010-05-19 09:24:36 +01:00
protected $name;
protected $namespace;
2010-05-19 09:24:36 +01:00
protected $path;
protected $reflection;
2010-08-10 15:59:12 +01:00
/**
* Boots the Bundle.
*/
public function boot()
{
}
2010-05-19 09:24:36 +01:00
/**
* Shutdowns the Bundle.
*/
2010-08-10 15:59:12 +01:00
public function shutdown()
{
}
2010-05-19 09:24:36 +01:00
/**
* Gets the Bundle name.
*
* @return string The Bundle name
*/
public function getName()
{
if (null === $this->name) {
$this->initReflection();
}
return $this->name;
}
/**
* Gets the Bundle namespace.
2010-05-19 09:24:36 +01:00
*
* @return string The Bundle namespace
2010-05-19 09:24:36 +01:00
*/
public function getNamespaceName()
2010-05-19 09:24:36 +01:00
{
if (null === $this->name) {
$this->initReflection();
}
return $this->namespace;
2010-05-19 09:24:36 +01:00
}
/**
* Gets the Bundle absolute path.
*
* @return string The Bundle absolute path
*/
public function getPath()
{
if (null === $this->name) {
$this->initReflection();
}
return $this->path;
}
/**
* Gets the Bundle Reflection instance.
*
* @return \ReflectionObject A \ReflectionObject instance for the Bundle
*/
public function getReflection()
{
if (null === $this->name) {
$this->initReflection();
}
return $this->reflection;
}
/**
* Finds and registers Dependency Injection Container extensions.
*
* Override this method if your DIC extensions do not follow the conventions:
*
* * Extensions are in the 'DependencyInjection/' sub-directory
* * Extension class names ends with 'Extension'
*
2010-08-10 15:59:12 +01:00
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function registerExtensions(ContainerBuilder $container)
{
if (!$dir = realpath($this->getPath().'/DependencyInjection')) {
return;
}
$finder = new Finder();
$finder->files()->name('*Extension.php')->in($dir);
$prefix = $this->namespace.'\\DependencyInjection';
foreach ($finder as $file) {
2010-12-20 15:15:50 +00:00
$class = $prefix.strtr($file->getPath(), array($dir => '', '/' => '\\')).'\\'.$file->getBasename('.php');
2010-12-20 15:21:56 +00:00
$container->registerExtension(new $class());
}
}
/**
* Finds and registers Commands.
2010-05-19 09:24:36 +01:00
*
2010-10-12 11:54:14 +01:00
* Override this method if your bundle commands do not follow the conventions:
*
* * Commands are in the 'Command' sub-directory
* * Commands extend Symfony\Component\Console\Command\Command
*
* @param Application $application An Application instance
2010-05-19 09:24:36 +01:00
*/
public function registerCommands(Application $application)
{
if (!$dir = realpath($this->getPath().'/Command')) {
return;
}
$finder = new Finder();
$finder->files()->name('*Command.php')->in($dir);
$prefix = $this->namespace.'\\Command';
foreach ($finder as $file) {
2010-12-20 15:15:50 +00:00
$r = new \ReflectionClass($prefix.strtr($file->getPath(), array($dir => '', '/' => '\\')).'\\'.$file->getBasename('.php'));
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
$application->add($r->newInstance());
}
}
}
2010-05-19 09:24:36 +01:00
2010-10-12 11:54:14 +01:00
/**
* Initializes the properties on this object that require a reflection
* object to have been created.
*/
2010-05-19 09:24:36 +01:00
protected function initReflection()
{
$this->reflection = new \ReflectionObject($this);
$this->namespace = $this->reflection->getNamespaceName();
$this->name = $this->reflection->getShortName();
$this->path = str_replace('\\', '/', dirname($this->reflection->getFilename()));
2010-05-19 09:24:36 +01:00
}
}