comparison vendor/symfony/http-kernel/Bundle/Bundle.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
9 * file that was distributed with this source code. 9 * file that was distributed with this source code.
10 */ 10 */
11 11
12 namespace Symfony\Component\HttpKernel\Bundle; 12 namespace Symfony\Component\HttpKernel\Bundle;
13 13
14 use Symfony\Component\Console\Application;
15 use Symfony\Component\DependencyInjection\Container;
14 use Symfony\Component\DependencyInjection\ContainerAwareTrait; 16 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
15 use Symfony\Component\DependencyInjection\ContainerBuilder; 17 use Symfony\Component\DependencyInjection\ContainerBuilder;
16 use Symfony\Component\DependencyInjection\Container; 18 use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
17 use Symfony\Component\Console\Application;
18 use Symfony\Component\Finder\Finder; 19 use Symfony\Component\Finder\Finder;
19 use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
20 20
21 /** 21 /**
22 * An implementation of BundleInterface that adds a few conventions 22 * An implementation of BundleInterface that adds a few conventions
23 * for DependencyInjection extensions and Console commands. 23 * for DependencyInjection extensions and Console commands.
24 * 24 *
32 protected $extension; 32 protected $extension;
33 protected $path; 33 protected $path;
34 private $namespace; 34 private $namespace;
35 35
36 /** 36 /**
37 * Boots the Bundle. 37 * {@inheritdoc}
38 */ 38 */
39 public function boot() 39 public function boot()
40 { 40 {
41 } 41 }
42 42
43 /** 43 /**
44 * Shutdowns the Bundle. 44 * {@inheritdoc}
45 */ 45 */
46 public function shutdown() 46 public function shutdown()
47 { 47 {
48 } 48 }
49 49
50 /** 50 /**
51 * Builds the bundle. 51 * {@inheritdoc}
52 *
53 * It is only ever called once when the cache is empty.
54 * 52 *
55 * This method can be overridden to register compilation passes, 53 * This method can be overridden to register compilation passes,
56 * other extensions, ... 54 * other extensions, ...
57 */ 55 */
58 public function build(ContainerBuilder $container) 56 public function build(ContainerBuilder $container)
71 if (null === $this->extension) { 69 if (null === $this->extension) {
72 $extension = $this->createContainerExtension(); 70 $extension = $this->createContainerExtension();
73 71
74 if (null !== $extension) { 72 if (null !== $extension) {
75 if (!$extension instanceof ExtensionInterface) { 73 if (!$extension instanceof ExtensionInterface) {
76 throw new \LogicException(sprintf('Extension %s must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface.', get_class($extension))); 74 throw new \LogicException(sprintf('Extension %s must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface.', \get_class($extension)));
77 } 75 }
78 76
79 // check naming convention 77 // check naming convention
80 $basename = preg_replace('/Bundle$/', '', $this->getName()); 78 $basename = preg_replace('/Bundle$/', '', $this->getName());
81 $expectedAlias = Container::underscore($basename); 79 $expectedAlias = Container::underscore($basename);
82 80
83 if ($expectedAlias != $extension->getAlias()) { 81 if ($expectedAlias != $extension->getAlias()) {
84 throw new \LogicException(sprintf( 82 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()));
85 '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.',
86 $expectedAlias, $extension->getAlias()
87 ));
88 } 83 }
89 84
90 $this->extension = $extension; 85 $this->extension = $extension;
91 } else { 86 } else {
92 $this->extension = false; 87 $this->extension = false;
97 return $this->extension; 92 return $this->extension;
98 } 93 }
99 } 94 }
100 95
101 /** 96 /**
102 * Gets the Bundle namespace. 97 * {@inheritdoc}
103 *
104 * @return string The Bundle namespace
105 */ 98 */
106 public function getNamespace() 99 public function getNamespace()
107 { 100 {
108 if (null === $this->namespace) { 101 if (null === $this->namespace) {
109 $this->parseClassName(); 102 $this->parseClassName();
111 104
112 return $this->namespace; 105 return $this->namespace;
113 } 106 }
114 107
115 /** 108 /**
116 * Gets the Bundle directory path. 109 * {@inheritdoc}
117 *
118 * @return string The Bundle absolute path
119 */ 110 */
120 public function getPath() 111 public function getPath()
121 { 112 {
122 if (null === $this->path) { 113 if (null === $this->path) {
123 $reflected = new \ReflectionObject($this); 114 $reflected = new \ReflectionObject($this);
124 $this->path = dirname($reflected->getFileName()); 115 $this->path = \dirname($reflected->getFileName());
125 } 116 }
126 117
127 return $this->path; 118 return $this->path;
128 } 119 }
129 120
130 /** 121 /**
131 * Returns the bundle parent name. 122 * {@inheritdoc}
132 *
133 * @return string|null The Bundle parent name it overrides or null if no parent
134 */ 123 */
135 public function getParent() 124 public function getParent()
136 { 125 {
137 } 126 }
138 127
139 /** 128 /**
140 * Returns the bundle name (the class short name). 129 * {@inheritdoc}
141 *
142 * @return string The Bundle name
143 */ 130 */
144 final public function getName() 131 final public function getName()
145 { 132 {
146 if (null === $this->name) { 133 if (null === $this->name) {
147 $this->parseClassName(); 134 $this->parseClassName();
177 if ($relativePath = $file->getRelativePath()) { 164 if ($relativePath = $file->getRelativePath()) {
178 $ns .= '\\'.str_replace('/', '\\', $relativePath); 165 $ns .= '\\'.str_replace('/', '\\', $relativePath);
179 } 166 }
180 $class = $ns.'\\'.$file->getBasename('.php'); 167 $class = $ns.'\\'.$file->getBasename('.php');
181 if ($this->container) { 168 if ($this->container) {
182 $commandIds = $this->container->hasParameter('console.command.ids') ? $this->container->getParameter('console.command.ids') : array(); 169 $commandIds = $this->container->hasParameter('console.command.ids') ? $this->container->getParameter('console.command.ids') : [];
183 $alias = 'console.command.'.strtolower(str_replace('\\', '_', $class)); 170 $alias = 'console.command.'.strtolower(str_replace('\\', '_', $class));
184 if (isset($commandIds[$alias]) || $this->container->has($alias)) { 171 if (isset($commandIds[$alias]) || $this->container->has($alias)) {
185 continue; 172 continue;
186 } 173 }
187 } 174 }