Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
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\ContainerAware;
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 * @api
028 */
029 abstract class Bundle extends ContainerAware implements BundleInterface
030 {
031 protected $name;
032 protected $reflected;
033 protected $extension;
034
035 /**
036 * Boots the Bundle.
037 */
038 public function boot()
039 {
040 }
041
042 /**
043 * Shutdowns the Bundle.
044 */
045 public function shutdown()
046 {
047 }
048
049 /**
050 * Builds the bundle.
051 *
052 * It is only ever called once when the cache is empty.
053 *
054 * This method can be overridden to register compilation passes,
055 * other extensions, ...
056 *
057 * @param ContainerBuilder $container A ContainerBuilder instance
058 */
059 public function build(ContainerBuilder $container)
060 {
061 }
062
063 /**
064 * Returns the bundle's container extension.
065 *
066 * @return ExtensionInterface|null The container extension
067 *
068 * @throws \LogicException
069 *
070 * @api
071 */
072 public function getContainerExtension()
073 {
074 if (null === $this->extension) {
075 $basename = preg_replace('/Bundle$/', '', $this->getName());
076
077 $class = $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
078 if (class_exists($class)) {
079 $extension = new $class();
080
081 // check naming convention
082 $expectedAlias = Container::underscore($basename);
083 if ($expectedAlias != $extension->getAlias()) {
084 throw new \LogicException(sprintf(
085 'The extension alias for the default extension of a '.
086 'bundle must be the underscored version of the '.
087 'bundle name ("%s" instead of "%s")',
088 $expectedAlias, $extension->getAlias()
089 ));
090 }
091
092 $this->extension = $extension;
093 } else {
094 $this->extension = false;
095 }
096 }
097
098 if ($this->extension) {
099 return $this->extension;
100 }
101 }
102
103 /**
104 * Gets the Bundle namespace.
105 *
106 * @return string The Bundle namespace
107 *
108 * @api
109 */
110 public function getNamespace()
111 {
112 if (null === $this->reflected) {
113 $this->reflected = new \ReflectionObject($this);
114 }
115
116 return $this->reflected->getNamespaceName();
117 }
118
119 /**
120 * Gets the Bundle directory path.
121 *
122 * @return string The Bundle absolute path
123 *
124 * @api
125 */
126 public function getPath()
127 {
128 if (null === $this->reflected) {
129 $this->reflected = new \ReflectionObject($this);
130 }
131
132 return dirname($this->reflected->getFileName());
133 }
134
135 /**
136 * Returns the bundle parent name.
137 *
138 * @return string The Bundle parent name it overrides or null if no parent
139 *
140 * @api
141 */
142 public function getParent()
143 {
144 }
145
146 /**
147 * Returns the bundle name (the class short name).
148 *
149 * @return string The Bundle name
150 *
151 * @api
152 */
153 final public function getName()
154 {
155 if (null !== $this->name) {
156 return $this->name;
157 }
158
159 $name = get_class($this);
160 $pos = strrpos($name, '\\');
161
162 return $this->name = false === $pos ? $name : substr($name, $pos + 1);
163 }
164
165 /**
166 * Finds and registers Commands.
167 *
168 * Override this method if your bundle commands do not follow the conventions:
169 *
170 * * Commands are in the 'Command' sub-directory
171 * * Commands extend Symfony\Component\Console\Command\Command
172 *
173 * @param Application $application An Application instance
174 */
175 public function registerCommands(Application $application)
176 {
177 if (!is_dir($dir = $this->getPath().'/Command')) {
178 return;
179 }
180
181 $finder = new Finder();
182 $finder->files()->name('*Command.php')->in($dir);
183
184 $prefix = $this->getNamespace().'\\Command';
185 foreach ($finder as $file) {
186 $ns = $prefix;
187 if ($relativePath = $file->getRelativePath()) {
188 $ns .= '\\'.strtr($relativePath, '/', '\\');
189 }
190 $r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
191 if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
192 $application->add($r->newInstance());
193 }
194 }
195 }
196 }
197