comparison core/lib/Drupal/Component/DependencyInjection/Container.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php 1 <?php
2 2
3 namespace Drupal\Component\DependencyInjection; 3 namespace Drupal\Component\DependencyInjection;
4 4
5 use Symfony\Component\DependencyInjection\ContainerInterface; 5 use Symfony\Component\DependencyInjection\ContainerInterface;
6 use Symfony\Component\DependencyInjection\ResettableContainerInterface;
7 use Symfony\Component\DependencyInjection\Exception\LogicException; 6 use Symfony\Component\DependencyInjection\Exception\LogicException;
8 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; 7 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
9 use Symfony\Component\DependencyInjection\Exception\RuntimeException; 8 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
10 use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; 9 use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
11 use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; 10 use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
40 * not supported: getParameterBag(), isFrozen(), compile(), 39 * not supported: getParameterBag(), isFrozen(), compile(),
41 * getAServiceWithAnIdByCamelCase(). 40 * getAServiceWithAnIdByCamelCase().
42 * - The function getServiceIds() was added as it has a use-case in core and 41 * - The function getServiceIds() was added as it has a use-case in core and
43 * contrib. 42 * contrib.
44 * 43 *
44 * @todo Implement Symfony\Contracts\Service\ResetInterface once Symfony 4
45 * is being used. See https://www.drupal.org/project/drupal/issues/3032605
46 *
45 * @ingroup container 47 * @ingroup container
46 */ 48 */
47 class Container implements ContainerInterface, ResettableContainerInterface { 49 class Container implements ContainerInterface {
48 50
49 /** 51 /**
50 * The parameters of the container. 52 * The parameters of the container.
51 * 53 *
52 * @var array 54 * @var array
143 145
144 $definition = isset($this->serviceDefinitions[$id]) ? $this->serviceDefinitions[$id] : NULL; 146 $definition = isset($this->serviceDefinitions[$id]) ? $this->serviceDefinitions[$id] : NULL;
145 147
146 if (!$definition && $invalid_behavior === ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) { 148 if (!$definition && $invalid_behavior === ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) {
147 if (!$id) { 149 if (!$id) {
148 throw new ServiceNotFoundException($id); 150 throw new ServiceNotFoundException('');
149 } 151 }
150 152
151 throw new ServiceNotFoundException($id, NULL, NULL, $this->getServiceAlternatives($id)); 153 throw new ServiceNotFoundException($id, NULL, NULL, $this->getServiceAlternatives($id));
152 } 154 }
153 155
185 187
186 return $service; 188 return $service;
187 } 189 }
188 190
189 /** 191 /**
190 * {@inheritdoc} 192 * Resets shared services from the container.
193 *
194 * The container is not intended to be used again after being reset in a
195 * normal workflow. This method is meant as a way to release references for
196 * ref-counting. A subsequent call to ContainerInterface::get() will recreate
197 * a new instance of the shared service.
191 */ 198 */
192 public function reset() { 199 public function reset() {
193 if (!empty($this->scopedServices)) { 200 if (!empty($this->scopedServices)) {
194 throw new LogicException('Resetting the container is not allowed when a scope is active.'); 201 throw new LogicException('Resetting the container is not allowed when a scope is active.');
195 } 202 }
366 * {@inheritdoc} 373 * {@inheritdoc}
367 */ 374 */
368 public function getParameter($name) { 375 public function getParameter($name) {
369 if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters))) { 376 if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters))) {
370 if (!$name) { 377 if (!$name) {
371 throw new ParameterNotFoundException($name); 378 throw new ParameterNotFoundException('');
372 } 379 }
373 380
374 throw new ParameterNotFoundException($name, NULL, NULL, NULL, $this->getParameterAlternatives($name)); 381 throw new ParameterNotFoundException($name, NULL, NULL, NULL, $this->getParameterAlternatives($name));
375 } 382 }
376 383