diff --git a/src/Symfony/Foundation/Bundle/Bundle.php b/src/Symfony/Foundation/Bundle/Bundle.php index eb715c86fa..3283ff6c9c 100644 --- a/src/Symfony/Foundation/Bundle/Bundle.php +++ b/src/Symfony/Foundation/Bundle/Bundle.php @@ -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()); + } } diff --git a/src/Symfony/Foundation/Bundle/BundleInterface.php b/src/Symfony/Foundation/Bundle/BundleInterface.php index 04e2beca4c..b332335739 100644 --- a/src/Symfony/Foundation/Bundle/BundleInterface.php +++ b/src/Symfony/Foundation/Bundle/BundleInterface.php @@ -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); } diff --git a/src/Symfony/Foundation/Bundle/KernelBundle.php b/src/Symfony/Foundation/Bundle/KernelBundle.php index 339a4ec4ee..bc5e55cb11 100644 --- a/src/Symfony/Foundation/Bundle/KernelBundle.php +++ b/src/Symfony/Foundation/Bundle/KernelBundle.php @@ -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(); diff --git a/src/Symfony/Foundation/Kernel.php b/src/Symfony/Foundation/Kernel.php index dbb88cce93..5f158ea0aa 100644 --- a/src/Symfony/Foundation/Kernel.php +++ b/src/Symfony/Foundation/Kernel.php @@ -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; diff --git a/src/Symfony/Foundation/bootstrap.php b/src/Symfony/Foundation/bootstrap.php index 117894123c..8b9a8a96b6 100644 --- a/src/Symfony/Foundation/bootstrap.php +++ b/src/Symfony/Foundation/bootstrap.php @@ -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(); diff --git a/src/Symfony/Framework/DoctrineBundle/Bundle.php b/src/Symfony/Framework/DoctrineBundle/Bundle.php index a9cf40e1a5..a5471c12c0 100644 --- a/src/Symfony/Framework/DoctrineBundle/Bundle.php +++ b/src/Symfony/Framework/DoctrineBundle/Bundle.php @@ -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'))); diff --git a/src/Symfony/Framework/ProfilerBundle/Bundle.php b/src/Symfony/Framework/ProfilerBundle/Bundle.php index ee17bbb624..1aa8b005f4 100644 --- a/src/Symfony/Framework/ProfilerBundle/Bundle.php +++ b/src/Symfony/Framework/ProfilerBundle/Bundle.php @@ -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()); diff --git a/src/Symfony/Framework/SwiftmailerBundle/Bundle.php b/src/Symfony/Framework/SwiftmailerBundle/Bundle.php index 7ef77daaf9..880b6578a5 100644 --- a/src/Symfony/Framework/SwiftmailerBundle/Bundle.php +++ b/src/Symfony/Framework/SwiftmailerBundle/Bundle.php @@ -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()); diff --git a/src/Symfony/Framework/WebBundle/Bundle.php b/src/Symfony/Framework/WebBundle/Bundle.php index adba0bcd66..30ca3e4845 100644 --- a/src/Symfony/Framework/WebBundle/Bundle.php +++ b/src/Symfony/Framework/WebBundle/Bundle.php @@ -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()); diff --git a/src/Symfony/Framework/WebBundle/Command/AssetsInstallCommand.php b/src/Symfony/Framework/WebBundle/Command/AssetsInstallCommand.php index f05990e24c..684a0f48eb 100644 --- a/src/Symfony/Framework/WebBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Framework/WebBundle/Command/AssetsInstallCommand.php @@ -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 %s\\%s', $bundle->getNamespacePrefix(), $bundle->getName())); - if (isset($dirs[$namespace]) && is_dir($originDir = $dirs[$namespace].'/'.$class.'/Resources/public')) { - $output->writeln(sprintf('Installing assets for %s\\%s', $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); diff --git a/src/Symfony/Framework/ZendBundle/Bundle.php b/src/Symfony/Framework/ZendBundle/Bundle.php index 472d2799fb..3e09b1ebe4 100644 --- a/src/Symfony/Framework/ZendBundle/Bundle.php +++ b/src/Symfony/Framework/ZendBundle/Bundle.php @@ -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());