Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
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\DependencyInjection\ContainerInterface;
015 use Symfony\Component\DependencyInjection\ContainerBuilder;
016 use Symfony\Component\DependencyInjection\Container;
017 use Symfony\Component\Console\Application;
018 use Symfony\Component\Finder\Finder;
019 use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
020
021 /**
022 * An implementation of BundleInterface that adds a few conventions
023 * for DependencyInjection extensions and Console commands.
024 *
025 * @author Fabien Potencier <fabien@symfony.com>
026 */
027 abstract class Bundle implements BundleInterface
028 {
029 /**
030 * @var ContainerInterface
031 */
032 protected $container;
033 protected $name;
034 protected $extension;
035 protected $path;
036
037 /**
038 * Boots the Bundle.
039 */
040 public function boot()
041 {
042 }
043
044 /**
045 * Shutdowns the Bundle.
046 */
047 public function shutdown()
048 {
049 }
050
051 /**
052 * Builds the bundle.
053 *
054 * It is only ever called once when the cache is empty.
055 *
056 * This method can be overridden to register compilation passes,
057 * other extensions, ...
058 *
059 * @param ContainerBuilder $container A ContainerBuilder instance
060 */
061 public function build(ContainerBuilder $container)
062 {
063 }
064
065 /**
066 * Sets the container.
067 *
068 * @param ContainerInterface|null $container A ContainerInterface instance or null
069 */
070 public function setContainer(ContainerInterface $container = null)
071 {
072 $this->container = $container;
073 }
074
075 /**
076 * Returns the bundle's container extension.
077 *
078 * @return ExtensionInterface|null The container extension
079 *
080 * @throws \LogicException
081 */
082 public function getContainerExtension()
083 {
084 if (null === $this->extension) {
085 $extension = $this->createContainerExtension();
086
087 if (null !== $extension) {
088 if (!$extension instanceof ExtensionInterface) {
089 throw new \LogicException(sprintf('Extension %s must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface.', get_class($extension)));
090 }
091
092 // check naming convention
093 $basename = preg_replace('/Bundle$/', '', $this->getName());
094 $expectedAlias = Container::underscore($basename);
095
096 if ($expectedAlias != $extension->getAlias()) {
097 throw new \LogicException(sprintf(
098 '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.',
099 $expectedAlias, $extension->getAlias()
100 ));
101 }
102
103 $this->extension = $extension;
104 } else {
105 $this->extension = false;
106 }
107 }
108
109 if ($this->extension) {
110 return $this->extension;
111 }
112 }
113
114 /**
115 * Gets the Bundle namespace.
116 *
117 * @return string The Bundle namespace
118 */
119 public function getNamespace()
120 {
121 $class = get_class($this);
122
123 return substr($class, 0, strrpos($class, '\\'));
124 }
125
126 /**
127 * Gets the Bundle directory path.
128 *
129 * @return string The Bundle absolute path
130 */
131 public function getPath()
132 {
133 if (null === $this->path) {
134 $reflected = new \ReflectionObject($this);
135 $this->path = dirname($reflected->getFileName());
136 }
137
138 return $this->path;
139 }
140
141 /**
142 * Returns the bundle parent name.
143 *
144 * @return string The Bundle parent name it overrides or null if no parent
145 */
146 public function getParent()
147 {
148 }
149
150 /**
151 * Returns the bundle name (the class short name).
152 *
153 * @return string The Bundle name
154 */
155 final public function getName()
156 {
157 if (null !== $this->name) {
158 return $this->name;
159 }
160
161 $name = get_class($this);
162 $pos = strrpos($name, '\\');
163
164 return $this->name = false === $pos ? $name : substr($name, $pos + 1);
165 }
166
167 /**
168 * Finds and registers Commands.
169 *
170 * Override this method if your bundle commands do not follow the conventions:
171 *
172 * * Commands are in the 'Command' sub-directory
173 * * Commands extend Symfony\Component\Console\Command\Command
174 *
175 * @param Application $application An Application instance
176 */
177 public function registerCommands(Application $application)
178 {
179 if (!is_dir($dir = $this->getPath().'/Command')) {
180 return;
181 }
182
183 if (!class_exists('Symfony\Component\Finder\Finder')) {
184 throw new \RuntimeException('You need the symfony/finder component to register bundle commands.');
185 }
186
187 $finder = new Finder();
188 $finder->files()->name('*Command.php')->in($dir);
189
190 $prefix = $this->getNamespace().'\\Command';
191 foreach ($finder as $file) {
192 $ns = $prefix;
193 if ($relativePath = $file->getRelativePath()) {
194 $ns .= '\\'.str_replace('/', '\\', $relativePath);
195 }
196 $class = $ns.'\\'.$file->getBasename('.php');
197 if ($this->container) {
198 $alias = 'console.command.'.strtolower(str_replace('\\', '_', $class));
199 if ($this->container->has($alias)) {
200 continue;
201 }
202 }
203 $r = new \ReflectionClass($class);
204 if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
205 $application->add($r->newInstance());
206 }
207 }
208 }
209
210 /**
211 * Returns the bundle's container extension class.
212 *
213 * @return string
214 */
215 protected function getContainerExtensionClass()
216 {
217 $basename = preg_replace('/Bundle$/', '', $this->getName());
218
219 return $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
220 }
221
222 /**
223 * Creates the bundle's container extension.
224 *
225 * @return ExtensionInterface|null
226 */
227 protected function createContainerExtension()
228 {
229 if (class_exists($class = $this->getContainerExtensionClass())) {
230 return new $class();
231 }
232 }
233 }
234