PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/vendor/symfony/src/Symfony/Component/HttpKernel/Bundle/Bundle.php

https://github.com/casoetan/ServerGroveLiveChat
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
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Bundle;
  11. use Symfony\Component\DependencyInjection\ContainerAware;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\Console\Application;
  14. use Symfony\Component\Finder\Finder;
  15. /**
  16. * An implementation of BundleInterface that adds a few conventions
  17. * for DependencyInjection extensions and Console commands.
  18. *
  19. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  20. */
  21. abstract class Bundle extends ContainerAware implements BundleInterface
  22. {
  23. protected $name;
  24. /**
  25. * Boots the Bundle.
  26. */
  27. public function boot()
  28. {
  29. }
  30. /**
  31. * Shutdowns the Bundle.
  32. */
  33. public function shutdown()
  34. {
  35. }
  36. /**
  37. * Returns the bundle parent name.
  38. *
  39. * @return string The Bundle parent name it overrides or null if no parent
  40. */
  41. public function getParent()
  42. {
  43. return null;
  44. }
  45. /**
  46. * Returns the bundle name (the class short name).
  47. *
  48. * @return string The Bundle name
  49. */
  50. final public function getName()
  51. {
  52. if (null !== $this->name) {
  53. return $this->name;
  54. }
  55. $name = get_class($this);
  56. $pos = strrpos($name, '\\');
  57. return $this->name = false === $pos ? $name : substr($name, $pos + 1);
  58. }
  59. /**
  60. * Gets the Bundle directory path.
  61. *
  62. * The path should always be returned as a Unix path (with /).
  63. *
  64. * @return string The Bundle absolute path
  65. */
  66. final public function getNormalizedPath()
  67. {
  68. return strtr($this->getPath(), '\\', '/');
  69. }
  70. /**
  71. * Finds and registers Dependency Injection Container extensions.
  72. *
  73. * Override this method if your DIC extensions do not follow the conventions:
  74. *
  75. * * Extensions are in the 'DependencyInjection/' sub-directory
  76. * * Extension class names ends with 'Extension'
  77. *
  78. * @param ContainerBuilder $container A ContainerBuilder instance
  79. */
  80. public function registerExtensions(ContainerBuilder $container)
  81. {
  82. if (!$dir = realpath($this->getNormalizedPath().'/DependencyInjection')) {
  83. return;
  84. }
  85. $finder = new Finder();
  86. $finder->files()->name('*Extension.php')->in($dir);
  87. $prefix = $this->getNamespace().'\\DependencyInjection';
  88. foreach ($finder as $file) {
  89. $class = $prefix.strtr($file->getPath(), array($dir => '', '/' => '\\')).'\\'.$file->getBasename('.php');
  90. $container->registerExtension(new $class());
  91. }
  92. }
  93. /**
  94. * Finds and registers Commands.
  95. *
  96. * Override this method if your bundle commands do not follow the conventions:
  97. *
  98. * * Commands are in the 'Command' sub-directory
  99. * * Commands extend Symfony\Component\Console\Command\Command
  100. *
  101. * @param Application $application An Application instance
  102. */
  103. public function registerCommands(Application $application)
  104. {
  105. if (!$dir = realpath($this->getNormalizedPath().'/Command')) {
  106. return;
  107. }
  108. $finder = new Finder();
  109. $finder->files()->name('*Command.php')->in($dir);
  110. $prefix = $this->getNamespace().'\\Command';
  111. foreach ($finder as $file) {
  112. $r = new \ReflectionClass($prefix.strtr($file->getPath(), array($dir => '', '/' => '\\')).'\\'.$file->getBasename('.php'));
  113. if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
  114. $application->add($r->newInstance());
  115. }
  116. }
  117. }
  118. }