Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Bundle.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\HttpKernel\Bundle;
013
014 use Symfony\Component\Console\Application;
015 use Symfony\Component\DependencyInjection\Container;
016 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
017 use Symfony\Component\DependencyInjection\ContainerBuilder;
018 use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
019 use Symfony\Component\Finder\Finder;
020
021 /**
022 * An implementation of BundleInterface that adds a few conventions for DependencyInjection extensions.
023 *
024 * @author Fabien Potencier <fabien@symfony.com>
025 */
026 abstract class Bundle implements BundleInterface
027 {
028 use ContainerAwareTrait;
029
030 protected $name;
031 protected $extension;
032 protected $path;
033 private $namespace;
034
035 /**
036 * {@inheritdoc}
037 */
038 public function boot()
039 {
040 }
041
042 /**
043 * {@inheritdoc}
044 */
045 public function shutdown()
046 {
047 }
048
049 /**
050 * {@inheritdoc}
051 *
052 * This method can be overridden to register compilation passes,
053 * other extensions, ...
054 */
055 public function build(ContainerBuilder $container)
056 {
057 }
058
059 /**
060 * Returns the bundle's container extension.
061 *
062 * @return ExtensionInterface|null The container extension
063 *
064 * @throws \LogicException
065 */
066 public function getContainerExtension()
067 {
068 if (null === $this->extension) {
069 $extension = $this->createContainerExtension();
070
071 if (null !== $extension) {
072 if (!$extension instanceof ExtensionInterface) {
073 throw new \LogicException(sprintf('Extension "%s" must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface.', \get_class($extension)));
074 }
075
076 // check naming convention
077 $basename = preg_replace('/Bundle$/', '', $this->getName());
078 $expectedAlias = Container::underscore($basename);
079
080 if ($expectedAlias != $extension->getAlias()) {
081 throw new \LogicException(sprintf('Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.', $expectedAlias, $extension->getAlias()));
082 }
083
084 $this->extension = $extension;
085 } else {
086 $this->extension = false;
087 }
088 }
089
090 return $this->extension ?: null;
091 }
092
093 /**
094 * {@inheritdoc}
095 */
096 public function getNamespace()
097 {
098 if (null === $this->namespace) {
099 $this->parseClassName();
100 }
101
102 return $this->namespace;
103 }
104
105 /**
106 * {@inheritdoc}
107 */
108 public function getPath()
109 {
110 if (null === $this->path) {
111 $reflected = new \ReflectionObject($this);
112 $this->path = \dirname($reflected->getFileName());
113 }
114
115 return $this->path;
116 }
117
118 /**
119 * {@inheritdoc}
120 */
121 public function getParent()
122 {
123 }
124
125 /**
126 * {@inheritdoc}
127 */
128 final public function getName()
129 {
130 if (null === $this->name) {
131 $this->parseClassName();
132 }
133
134 return $this->name;
135 }
136
137 /**
138 * Finds and registers Commands.
139 *
140 * Override this method if your bundle commands do not follow the conventions:
141 *
142 * * Commands are in the 'Command' sub-directory
143 * * Commands extend Symfony\Component\Console\Command\Command
144 */
145 public function registerCommands(Application $application)
146 {
147 if (!is_dir($dir = $this->getPath().'/Command')) {
148 return;
149 }
150
151 if (!class_exists('Symfony\Component\Finder\Finder')) {
152 throw new \RuntimeException('You need the symfony/finder component to register bundle commands.');
153 }
154
155 $finder = new Finder();
156 $finder->files()->name('*Command.php')->in($dir);
157
158 $prefix = $this->getNamespace().'\\Command';
159 foreach ($finder as $file) {
160 $ns = $prefix;
161 if ($relativePath = $file->getRelativePath()) {
162 $ns .= '\\'.str_replace('/', '\\', $relativePath);
163 }
164 $class = $ns.'\\'.$file->getBasename('.php');
165 if ($this->container) {
166 $commandIds = $this->container->hasParameter('console.command.ids') ? $this->container->getParameter('console.command.ids') : [];
167 $alias = 'console.command.'.strtolower(str_replace('\\', '_', $class));
168 if (isset($commandIds[$alias]) || $this->container->has($alias)) {
169 continue;
170 }
171 }
172 $r = new \ReflectionClass($class);
173 if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
174 @trigger_error(sprintf('Auto-registration of the command "%s" is deprecated since Symfony 3.4 and won\'t be supported in 4.0. Use PSR-4 based service discovery instead.', $class), \E_USER_DEPRECATED);
175
176 $application->add($r->newInstance());
177 }
178 }
179 }
180
181 /**
182 * Returns the bundle's container extension class.
183 *
184 * @return string
185 */
186 protected function getContainerExtensionClass()
187 {
188 $basename = preg_replace('/Bundle$/', '', $this->getName());
189
190 return $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
191 }
192
193 /**
194 * Creates the bundle's container extension.
195 *
196 * @return ExtensionInterface|null
197 */
198 protected function createContainerExtension()
199 {
200 return class_exists($class = $this->getContainerExtensionClass()) ? new $class() : null;
201 }
202
203 private function parseClassName()
204 {
205 $pos = strrpos(static::class, '\\');
206 $this->namespace = false === $pos ? '' : substr(static::class, 0, $pos);
207 if (null === $this->name) {
208 $this->name = false === $pos ? static::class : substr(static::class, $pos + 1);
209 }
210 }
211 }
212