Skip to content

Commit

Permalink
added methods to introspect a Bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed May 19, 2010
1 parent e09d57c commit c840c29
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 8 deletions.
92 changes: 92 additions & 0 deletions src/Symfony/Foundation/Bundle/Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,101 @@
*/
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) {
Expand All @@ -60,4 +143,13 @@ public function registerCommands(Application $application)
}
}
}

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());
}
}
17 changes: 17 additions & 0 deletions src/Symfony/Foundation/Bundle/BundleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,26 @@
*/
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);
}
12 changes: 12 additions & 0 deletions src/Symfony/Foundation/Bundle/KernelBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
*/
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());
Expand All @@ -44,6 +51,11 @@ public function buildContainer(ContainerInterface $container)
return $configuration;
}

/**
* Boots the Bundle.
*
* @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
*/
public function boot(ContainerInterface $container)
{
$container->getErrorHandlerService();
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Foundation/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,21 @@ public function handle(Request $request = null, $type = HttpKernelInterface::MAS
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;
Expand Down
63 changes: 63 additions & 0 deletions src/Symfony/Foundation/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,67 @@

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) {
Expand All @@ -46,6 +95,15 @@ public function registerCommands(Application $application)
}
}
}

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());
}
}


Expand All @@ -58,10 +116,13 @@ public function registerCommands(Application $application)

interface BundleInterface
{

public function buildContainer(ContainerInterface $container);


public function boot(ContainerInterface $container);


public function shutdown(ContainerInterface $container);
}

Expand All @@ -80,6 +141,7 @@ public function shutdown(ContainerInterface $container);

class KernelBundle extends Bundle
{

public function buildContainer(ContainerInterface $container)
{
Loader::registerExtension(new KernelExtension());
Expand All @@ -97,6 +159,7 @@ public function buildContainer(ContainerInterface $container)
return $configuration;
}


public function boot(ContainerInterface $container)
{
$container->getErrorHandlerService();
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Framework/DoctrineBundle/Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
*/
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')));
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Framework/ProfilerBundle/Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
*/
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());
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Framework/SwiftmailerBundle/Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
*/
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());
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Framework/WebBundle/Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
*/
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());
Expand Down
11 changes: 3 additions & 8 deletions src/Symfony/Framework/WebBundle/Command/AssetsInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,11 @@ protected function execute(InputInterface $input, OutputInterface $output)

$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);
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Framework/ZendBundle/Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
*/
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());
Expand Down

0 comments on commit c840c29

Please sign in to comment.