2010-02-17 13:54:36 +00:00
|
|
|
<?php
|
|
|
|
|
2010-09-15 19:49:16 +01:00
|
|
|
namespace Symfony\Component\HttpKernel\Bundle;
|
2010-02-17 13:54:36 +00:00
|
|
|
|
2010-08-28 08:39:04 +01:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerAware;
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
|
|
|
use Symfony\Component\Console\Application;
|
|
|
|
use Symfony\Component\Finder\Finder;
|
2010-02-17 13:54:36 +00:00
|
|
|
|
|
|
|
/*
|
2010-04-07 01:51:29 +01:00
|
|
|
* This file is part of the Symfony framework.
|
2010-02-17 13:54:36 +00:00
|
|
|
*
|
|
|
|
* (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
|
2010-12-20 19:56:14 +00:00
|
|
|
* for the DependencyInjection extensions and the Console commands.
|
2010-02-17 13:54:36 +00:00
|
|
|
*
|
2010-10-17 12:45:15 +01:00
|
|
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
2010-02-17 13:54:36 +00:00
|
|
|
*/
|
2010-08-28 08:39:04 +01:00
|
|
|
abstract class Bundle extends ContainerAware implements BundleInterface
|
2010-02-17 13:54:36 +00:00
|
|
|
{
|
2010-05-19 09:24:36 +01:00
|
|
|
protected $name;
|
2011-01-15 14:11:02 +00:00
|
|
|
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-06 12:25:53 +01:00
|
|
|
{
|
|
|
|
}
|
2010-04-12 20:56:42 +01:00
|
|
|
|
2010-05-19 09:24:36 +01:00
|
|
|
/**
|
|
|
|
* Shutdowns the Bundle.
|
|
|
|
*/
|
2010-08-10 15:59:12 +01:00
|
|
|
public function shutdown()
|
2010-04-12 20:56:42 +01:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2010-04-12 20:56:42 +01:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-01-15 14:11:02 +00:00
|
|
|
* Gets the Bundle namespace.
|
2010-05-19 09:24:36 +01:00
|
|
|
*
|
2011-01-15 14:11:02 +00:00
|
|
|
* @return string The Bundle namespace
|
2010-05-19 09:24:36 +01:00
|
|
|
*/
|
2011-01-15 14:30:15 +00:00
|
|
|
public function getNamespace()
|
2010-05-19 09:24:36 +01:00
|
|
|
{
|
|
|
|
if (null === $this->name) {
|
|
|
|
$this->initReflection();
|
|
|
|
}
|
|
|
|
|
2011-01-15 14:11:02 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-08-10 15:00:49 +01:00
|
|
|
* 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
|
2010-08-10 15:00:49 +01:00
|
|
|
*/
|
|
|
|
public function registerExtensions(ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
if (!$dir = realpath($this->getPath().'/DependencyInjection')) {
|
2010-12-20 19:56:14 +00:00
|
|
|
return;
|
2010-08-10 15:00:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$finder = new Finder();
|
|
|
|
$finder->files()->name('*Extension.php')->in($dir);
|
|
|
|
|
2011-01-15 14:11:02 +00:00
|
|
|
$prefix = $this->namespace.'\\DependencyInjection';
|
2010-08-10 15:00:49 +01:00
|
|
|
foreach ($finder as $file) {
|
2010-12-20 15:15:50 +00:00
|
|
|
$class = $prefix.strtr($file->getPath(), array($dir => '', '/' => '\\')).'\\'.$file->getBasename('.php');
|
2010-08-10 15:00:49 +01:00
|
|
|
|
2010-12-20 15:21:56 +00:00
|
|
|
$container->registerExtension(new $class());
|
2010-08-10 15:00:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2010-07-27 14:33:28 +01:00
|
|
|
* @param Application $application An Application instance
|
2010-05-19 09:24:36 +01:00
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function registerCommands(Application $application)
|
|
|
|
{
|
2010-07-15 12:31:22 +01:00
|
|
|
if (!$dir = realpath($this->getPath().'/Command')) {
|
2010-07-13 19:35:27 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-04-12 20:56:42 +01:00
|
|
|
|
2010-07-13 19:35:27 +01:00
|
|
|
$finder = new Finder();
|
|
|
|
$finder->files()->name('*Command.php')->in($dir);
|
2010-05-06 12:25:53 +01:00
|
|
|
|
2011-01-15 14:11:02 +00:00
|
|
|
$prefix = $this->namespace.'\\Command';
|
2010-07-13 19:35:27 +01:00
|
|
|
foreach ($finder as $file) {
|
2010-12-20 15:15:50 +00:00
|
|
|
$r = new \ReflectionClass($prefix.strtr($file->getPath(), array($dir => '', '/' => '\\')).'\\'.$file->getBasename('.php'));
|
2010-08-20 22:09:55 +01:00
|
|
|
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
|
2010-11-26 19:28:15 +00:00
|
|
|
$application->add($r->newInstance());
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2010-04-12 20:56:42 +01:00
|
|
|
}
|
|
|
|
}
|
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);
|
2011-01-15 14:11:02 +00:00
|
|
|
$this->namespace = $this->reflection->getNamespaceName();
|
|
|
|
$this->name = $this->reflection->getShortName();
|
2011-01-04 17:21:58 +00:00
|
|
|
$this->path = str_replace('\\', '/', dirname($this->reflection->getFilename()));
|
2010-05-19 09:24:36 +01:00
|
|
|
}
|
2010-02-17 13:54:36 +00:00
|
|
|
}
|