added methods to introspect a Bundle
This commit is contained in:
parent
e09d57ca8b
commit
c840c294fa
|
@ -23,18 +23,101 @@ use Symfony\Components\Console\Application;
|
|||
*/
|
||||
abstract class Bundle implements BundleInterface
|
||||
{
|
||||
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
|
||||
*/
|
||||
public function buildContainer(ContainerInterface $container)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Boots the Bundle.
|
||||
*
|
||||
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
|
||||
*/
|
||||
public function boot(ContainerInterface $container)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdowns the Bundle.
|
||||
*
|
||||
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
|
||||
*/
|
||||
public function shutdown(ContainerInterface $container)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param Symfony\Components\Console\Application An Application instance
|
||||
*/
|
||||
public function registerCommands(Application $application)
|
||||
{
|
||||
foreach ($application->getKernel()->getBundleDirs() as $dir) {
|
||||
|
@ -60,4 +143,13 @@ abstract class Bundle implements BundleInterface
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,26 @@ use Symfony\Components\DependencyInjection\ContainerInterface;
|
|||
*/
|
||||
interface BundleInterface
|
||||
{
|
||||
/**
|
||||
* Customizes the Container instance.
|
||||
*
|
||||
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
|
||||
*
|
||||
* @return Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
||||
*/
|
||||
public function buildContainer(ContainerInterface $container);
|
||||
|
||||
/**
|
||||
* Boots the Bundle.
|
||||
*
|
||||
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
|
||||
*/
|
||||
public function boot(ContainerInterface $container);
|
||||
|
||||
/**
|
||||
* Shutdowns the Bundle.
|
||||
*
|
||||
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
|
||||
*/
|
||||
public function shutdown(ContainerInterface $container);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,13 @@ use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
|||
*/
|
||||
class KernelBundle extends Bundle
|
||||
{
|
||||
/**
|
||||
* Customizes the Container instance.
|
||||
*
|
||||
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
|
||||
*
|
||||
* @return Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
||||
*/
|
||||
public function buildContainer(ContainerInterface $container)
|
||||
{
|
||||
Loader::registerExtension(new KernelExtension());
|
||||
|
@ -44,6 +51,11 @@ class KernelBundle extends Bundle
|
|||
return $configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Boots the Bundle.
|
||||
*
|
||||
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
|
||||
*/
|
||||
public function boot(ContainerInterface $container)
|
||||
{
|
||||
$container->getErrorHandlerService();
|
||||
|
|
|
@ -192,11 +192,21 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
|
|||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the directories where bundles can be stored.
|
||||
*
|
||||
* @return array An array of directories where bundles can be stored
|
||||
*/
|
||||
public function getBundleDirs()
|
||||
{
|
||||
return $this->bundleDirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the registered bundle names.
|
||||
*
|
||||
* @return array An array of registered bundle names
|
||||
*/
|
||||
public function getBundles()
|
||||
{
|
||||
return $this->bundles;
|
||||
|
|
|
@ -10,18 +10,67 @@ use Symfony\Components\Console\Application;
|
|||
|
||||
abstract class Bundle implements BundleInterface
|
||||
{
|
||||
protected $name;
|
||||
protected $namespacePrefix;
|
||||
protected $path;
|
||||
protected $reflection;
|
||||
|
||||
|
||||
public function buildContainer(ContainerInterface $container)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function boot(ContainerInterface $container)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function shutdown(ContainerInterface $container)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function getName()
|
||||
{
|
||||
if (null === $this->name) {
|
||||
$this->initReflection();
|
||||
}
|
||||
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
|
||||
public function getNamespacePrefix()
|
||||
{
|
||||
if (null === $this->name) {
|
||||
$this->initReflection();
|
||||
}
|
||||
|
||||
return $this->namespacePrefix;
|
||||
}
|
||||
|
||||
|
||||
public function getPath()
|
||||
{
|
||||
if (null === $this->name) {
|
||||
$this->initReflection();
|
||||
}
|
||||
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
|
||||
public function getReflection()
|
||||
{
|
||||
if (null === $this->name) {
|
||||
$this->initReflection();
|
||||
}
|
||||
|
||||
return $this->reflection;
|
||||
}
|
||||
|
||||
|
||||
public function registerCommands(Application $application)
|
||||
{
|
||||
foreach ($application->getKernel()->getBundleDirs() as $dir) {
|
||||
|
@ -46,6 +95,15 @@ abstract class Bundle implements BundleInterface
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,10 +116,13 @@ use Symfony\Components\DependencyInjection\ContainerInterface;
|
|||
|
||||
interface BundleInterface
|
||||
{
|
||||
|
||||
public function buildContainer(ContainerInterface $container);
|
||||
|
||||
|
||||
public function boot(ContainerInterface $container);
|
||||
|
||||
|
||||
public function shutdown(ContainerInterface $container);
|
||||
}
|
||||
|
||||
|
@ -80,6 +141,7 @@ use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
|||
|
||||
class KernelBundle extends Bundle
|
||||
{
|
||||
|
||||
public function buildContainer(ContainerInterface $container)
|
||||
{
|
||||
Loader::registerExtension(new KernelExtension());
|
||||
|
@ -97,6 +159,7 @@ class KernelBundle extends Bundle
|
|||
return $configuration;
|
||||
}
|
||||
|
||||
|
||||
public function boot(ContainerInterface $container)
|
||||
{
|
||||
$container->getErrorHandlerService();
|
||||
|
|
|
@ -27,6 +27,13 @@ use Symfony\Framework\DoctrineBundle\DependencyInjection\DoctrineExtension;
|
|||
*/
|
||||
class Bundle extends BaseBundle
|
||||
{
|
||||
/**
|
||||
* Customizes the Container instance.
|
||||
*
|
||||
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
|
||||
*
|
||||
* @return Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
||||
*/
|
||||
public function buildContainer(ContainerInterface $container)
|
||||
{
|
||||
Loader::registerExtension(new DoctrineExtension($container->getParameter('kernel.bundle_dirs'), $container->getParameter('kernel.bundles')));
|
||||
|
|
|
@ -25,6 +25,13 @@ use Symfony\Framework\ProfilerBundle\DependencyInjection\ProfilerExtension;
|
|||
*/
|
||||
class Bundle extends BaseBundle
|
||||
{
|
||||
/**
|
||||
* Customizes the Container instance.
|
||||
*
|
||||
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
|
||||
*
|
||||
* @return Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
||||
*/
|
||||
public function buildContainer(ContainerInterface $container)
|
||||
{
|
||||
Loader::registerExtension(new ProfilerExtension());
|
||||
|
|
|
@ -25,6 +25,13 @@ use Symfony\Framework\SwiftmailerBundle\DependencyInjection\SwiftmailerExtension
|
|||
*/
|
||||
class Bundle extends BaseBundle
|
||||
{
|
||||
/**
|
||||
* Customizes the Container instance.
|
||||
*
|
||||
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
|
||||
*
|
||||
* @return Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
||||
*/
|
||||
public function buildContainer(ContainerInterface $container)
|
||||
{
|
||||
Loader::registerExtension(new SwiftmailerExtension());
|
||||
|
|
|
@ -27,6 +27,13 @@ use Symfony\Framework\WebBundle\DependencyInjection\WebExtension;
|
|||
*/
|
||||
class Bundle extends BaseBundle
|
||||
{
|
||||
/**
|
||||
* Customizes the Container instance.
|
||||
*
|
||||
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
|
||||
*
|
||||
* @return Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
||||
*/
|
||||
public function buildContainer(ContainerInterface $container)
|
||||
{
|
||||
Loader::registerExtension(new WebExtension());
|
||||
|
|
|
@ -53,16 +53,11 @@ class AssetsInstallCommand extends Command
|
|||
|
||||
$filesystem = new Filesystem();
|
||||
|
||||
$dirs = $this->container->getKernelService()->getBundleDirs();
|
||||
foreach ($this->container->getKernelService()->getBundles() as $bundle) {
|
||||
$tmp = dirname(str_replace('\\', '/', get_class($bundle)));
|
||||
$namespace = str_replace('/', '\\', dirname($tmp));
|
||||
$class = basename($tmp);
|
||||
if (is_dir($originDir = $bundle->getPath().'/Resources/public')) {
|
||||
$output->writeln(sprintf('Installing assets for <comment>%s\\%s</comment>', $bundle->getNamespacePrefix(), $bundle->getName()));
|
||||
|
||||
if (isset($dirs[$namespace]) && is_dir($originDir = $dirs[$namespace].'/'.$class.'/Resources/public')) {
|
||||
$output->writeln(sprintf('Installing assets for <comment>%s\\%s</comment>', $namespace, $class));
|
||||
|
||||
$targetDir = $input->getArgument('target').'/bundles/'.preg_replace('/bundle$/', '', strtolower($class));
|
||||
$targetDir = $input->getArgument('target').'/bundles/'.preg_replace('/bundle$/', '', strtolower($bundle->getName()));
|
||||
|
||||
$filesystem->remove($targetDir);
|
||||
mkdir($targetDir, 0755, true);
|
||||
|
|
|
@ -26,6 +26,13 @@ use Symfony\Framework\ZendBundle\DependencyInjection\ZendExtension;
|
|||
*/
|
||||
class Bundle extends BaseBundle
|
||||
{
|
||||
/**
|
||||
* Customizes the Container instance.
|
||||
*
|
||||
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
|
||||
*
|
||||
* @return Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
||||
*/
|
||||
public function buildContainer(ContainerInterface $container)
|
||||
{
|
||||
Loader::registerExtension(new ZendExtension());
|
||||
|
|
Reference in New Issue