2010-02-17 13:54:36 +00:00
|
|
|
<?php
|
|
|
|
|
2010-07-09 09:12:56 +01:00
|
|
|
namespace Symfony\Framework\Bundle;
|
2010-02-17 13:54:36 +00:00
|
|
|
|
|
|
|
use Symfony\Components\DependencyInjection\ContainerInterface;
|
2010-07-27 14:33:28 +01:00
|
|
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
2010-07-13 10:14:21 +01:00
|
|
|
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface;
|
2010-04-12 20:56:42 +01:00
|
|
|
use Symfony\Components\Console\Application;
|
2010-07-13 19:35:27 +01:00
|
|
|
use Symfony\Components\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-04-07 01:51:29 +01:00
|
|
|
* Bundle.
|
2010-02-17 13:54:36 +00:00
|
|
|
*
|
|
|
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*/
|
|
|
|
abstract class Bundle implements BundleInterface
|
|
|
|
{
|
2010-05-19 09:24:36 +01:00
|
|
|
protected $name;
|
|
|
|
protected $namespacePrefix;
|
|
|
|
protected $path;
|
|
|
|
protected $reflection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Customizes the Container instance.
|
|
|
|
*
|
2010-07-27 14:33:28 +01:00
|
|
|
* @param ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
2010-05-19 09:24:36 +01:00
|
|
|
*
|
2010-07-27 14:33:28 +01:00
|
|
|
* @return ContainerBuilder A ContainerBuilder instance
|
2010-05-19 09:24:36 +01:00
|
|
|
*/
|
2010-07-13 10:14:21 +01:00
|
|
|
public function buildContainer(ParameterBagInterface $parameterBag)
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
|
|
|
}
|
2010-04-19 08:05:11 +01:00
|
|
|
|
2010-05-19 09:24:36 +01:00
|
|
|
/**
|
|
|
|
* Boots the Bundle.
|
|
|
|
*
|
2010-07-27 14:33:28 +01:00
|
|
|
* @param ContainerInterface $container A ContainerInterface instance
|
2010-05-19 09:24:36 +01:00
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function boot(ContainerInterface $container)
|
|
|
|
{
|
|
|
|
}
|
2010-04-12 20:56:42 +01:00
|
|
|
|
2010-05-19 09:24:36 +01:00
|
|
|
/**
|
|
|
|
* Shutdowns the Bundle.
|
|
|
|
*
|
2010-07-27 14:33:28 +01:00
|
|
|
* @param ContainerInterface $container A ContainerInterface instance
|
2010-05-19 09:24:36 +01:00
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function shutdown(ContainerInterface $container)
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Bundle namespace prefix.
|
|
|
|
*
|
|
|
|
* @return string The Bundle namespace prefix
|
|
|
|
*/
|
|
|
|
public function getNamespacePrefix()
|
|
|
|
{
|
|
|
|
if (null === $this->name) {
|
|
|
|
$this->initReflection();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->namespacePrefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-07-13 19:35:27 +01:00
|
|
|
* Finds and registers commands for the current bundle.
|
2010-05-19 09:24:36 +01:00
|
|
|
*
|
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
|
|
|
|
2010-07-15 12:31:22 +01:00
|
|
|
$prefix = $this->namespacePrefix.'\\'.$this->name.'\\Command';
|
2010-07-13 19:35:27 +01:00
|
|
|
foreach ($finder as $file) {
|
2010-07-15 12:31:22 +01:00
|
|
|
$r = new \ReflectionClass($prefix.strtr($file->getPath(), array($dir => '', '/' => '\\')).'\\'.basename($file, '.php'));
|
2010-07-13 19:35:27 +01:00
|
|
|
if ($r->isSubclassOf('Symfony\\Components\\Console\\Command\\Command') && !$r->isAbstract()) {
|
|
|
|
$application->addCommand($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
|
|
|
|
|
|
|
protected function initReflection()
|
|
|
|
{
|
|
|
|
$tmp = dirname(str_replace('\\', '/', get_class($this)));
|
|
|
|
$this->namespacePrefix = str_replace('/', '\\', dirname($tmp));
|
|
|
|
$this->name = basename($tmp);
|
|
|
|
$this->reflection = new \ReflectionObject($this);
|
|
|
|
$this->path = dirname($this->reflection->getFilename());
|
|
|
|
}
|
2010-02-17 13:54:36 +00:00
|
|
|
}
|