/vendor/symfony/src/Symfony/Component/HttpKernel/Bundle/Bundle.php
PHP | 136 lines | 70 code | 16 blank | 50 comment | 5 complexity | 6dc744f509e8a020dc5d0ef3f82829a9 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, ISC, BSD-3-Clause
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Component\HttpKernel\Bundle;
- use Symfony\Component\DependencyInjection\ContainerAware;
- use Symfony\Component\DependencyInjection\ContainerBuilder;
- use Symfony\Component\Console\Application;
- use Symfony\Component\Finder\Finder;
- /**
- * An implementation of BundleInterface that adds a few conventions
- * for DependencyInjection extensions and Console commands.
- *
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
- abstract class Bundle extends ContainerAware implements BundleInterface
- {
- protected $name;
- /**
- * Boots the Bundle.
- */
- public function boot()
- {
- }
- /**
- * Shutdowns the Bundle.
- */
- public function shutdown()
- {
- }
- /**
- * Returns the bundle parent name.
- *
- * @return string The Bundle parent name it overrides or null if no parent
- */
- public function getParent()
- {
- return null;
- }
- /**
- * Returns the bundle name (the class short name).
- *
- * @return string The Bundle name
- */
- final public function getName()
- {
- if (null !== $this->name) {
- return $this->name;
- }
- $name = get_class($this);
- $pos = strrpos($name, '\\');
- return $this->name = false === $pos ? $name : substr($name, $pos + 1);
- }
- /**
- * Gets the Bundle directory path.
- *
- * The path should always be returned as a Unix path (with /).
- *
- * @return string The Bundle absolute path
- */
- final public function getNormalizedPath()
- {
- return strtr($this->getPath(), '\\', '/');
- }
- /**
- * Finds and registers Dependency Injection Container extensions.
- *
- * Override this method if your DIC extensions do not follow the conventions:
- *
- * * Extensions are in the 'DependencyInjection/' sub-directory
- * * Extension class names ends with 'Extension'
- *
- * @param ContainerBuilder $container A ContainerBuilder instance
- */
- public function registerExtensions(ContainerBuilder $container)
- {
- if (!$dir = realpath($this->getNormalizedPath().'/DependencyInjection')) {
- return;
- }
- $finder = new Finder();
- $finder->files()->name('*Extension.php')->in($dir);
- $prefix = $this->getNamespace().'\\DependencyInjection';
- foreach ($finder as $file) {
- $class = $prefix.strtr($file->getPath(), array($dir => '', '/' => '\\')).'\\'.$file->getBasename('.php');
- $container->registerExtension(new $class());
- }
- }
- /**
- * Finds and registers Commands.
- *
- * Override this method if your bundle commands do not follow the conventions:
- *
- * * Commands are in the 'Command' sub-directory
- * * Commands extend Symfony\Component\Console\Command\Command
- *
- * @param Application $application An Application instance
- */
- public function registerCommands(Application $application)
- {
- if (!$dir = realpath($this->getNormalizedPath().'/Command')) {
- return;
- }
- $finder = new Finder();
- $finder->files()->name('*Command.php')->in($dir);
- $prefix = $this->getNamespace().'\\Command';
- foreach ($finder as $file) {
- $r = new \ReflectionClass($prefix.strtr($file->getPath(), array($dir => '', '/' => '\\')).'\\'.$file->getBasename('.php'));
- if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
- $application->add($r->newInstance());
- }
- }
- }
- }