2010-02-17 13:54:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Symfony\Foundation\Bundle;
|
|
|
|
|
|
|
|
use Symfony\Components\DependencyInjection\ContainerInterface;
|
2010-04-12 20:56:42 +01:00
|
|
|
use Symfony\Components\Console\Application;
|
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
|
|
|
*
|
2010-04-07 01:51:29 +01:00
|
|
|
* @package Symfony
|
|
|
|
* @subpackage Foundation
|
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.
|
|
|
|
*
|
|
|
|
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
|
|
|
|
*
|
|
|
|
* @return Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function buildContainer(ContainerInterface $container)
|
|
|
|
{
|
|
|
|
}
|
2010-04-19 08:05:11 +01:00
|
|
|
|
2010-05-19 09:24:36 +01:00
|
|
|
/**
|
|
|
|
* Boots the Bundle.
|
|
|
|
*
|
|
|
|
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
|
|
|
|
*/
|
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.
|
|
|
|
*
|
|
|
|
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
|
|
|
|
*/
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers the Commands for the console.
|
|
|
|
*
|
2010-07-01 19:17:03 +01:00
|
|
|
* @param Symfony\Components\Console\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-05-07 15:09:11 +01:00
|
|
|
foreach ($application->getKernel()->getBundleDirs() as $dir) {
|
2010-05-06 12:25:53 +01:00
|
|
|
$bundleBase = dirname(str_replace('\\', '/', get_class($this)));
|
|
|
|
$commandDir = $dir.'/'.basename($bundleBase).'/Command';
|
2010-05-07 15:09:11 +01:00
|
|
|
if (!is_dir($commandDir)) {
|
2010-05-06 12:25:53 +01:00
|
|
|
continue;
|
|
|
|
}
|
2010-04-12 20:56:42 +01:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
// look for commands
|
2010-05-07 15:09:11 +01:00
|
|
|
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($commandDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
|
2010-05-08 14:32:30 +01:00
|
|
|
if ($file->isDir() || substr($file, -4) !== '.php') {
|
2010-05-06 12:25:53 +01:00
|
|
|
continue;
|
|
|
|
}
|
2010-04-12 20:56:42 +01:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
$class = str_replace('/', '\\', $bundleBase).'\\Command\\'.str_replace(realpath($commandDir).'/', '', basename(realpath($file), '.php'));
|
2010-04-12 20:56:42 +01:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
$r = new \ReflectionClass($class);
|
|
|
|
|
2010-05-07 15:09:11 +01:00
|
|
|
if ($r->isSubclassOf('Symfony\\Components\\Console\\Command\\Command') && !$r->isAbstract()) {
|
2010-05-06 12:25:53 +01:00
|
|
|
$application->addCommand(new $class());
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|