ContainerBuilder.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\Compiler\Compiler;
  12. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  13. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  14. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  15. use Symfony\Component\Config\Resource\FileResource;
  16. use Symfony\Component\Config\Resource\ResourceInterface;
  17. /**
  18. * ContainerBuilder is a DI container that provides an API to easily describe services.
  19. *
  20. * @author Fabien Potencier <fabien@symfony.com>
  21. *
  22. * @api
  23. */
  24. class ContainerBuilder extends Container implements TaggedContainerInterface
  25. {
  26. private $extensions = array();
  27. private $extensionsByNs = array();
  28. private $definitions = array();
  29. private $aliases = array();
  30. private $resources = array();
  31. private $extensionConfigs = array();
  32. private $injectors = array();
  33. private $compiler;
  34. /**
  35. * Registers an extension.
  36. *
  37. * @param ExtensionInterface $extension An extension instance
  38. *
  39. * @api
  40. */
  41. public function registerExtension(ExtensionInterface $extension)
  42. {
  43. $this->extensions[$extension->getAlias()] = $extension;
  44. if (false !== $extension->getNamespace()) {
  45. $this->extensionsByNs[$extension->getNamespace()] = $extension;
  46. }
  47. }
  48. /**
  49. * Returns an extension by alias or namespace.
  50. *
  51. * @param string $name An alias or a namespace
  52. *
  53. * @return ExtensionInterface An extension instance
  54. *
  55. * @api
  56. */
  57. public function getExtension($name)
  58. {
  59. if (isset($this->extensions[$name])) {
  60. return $this->extensions[$name];
  61. }
  62. if (isset($this->extensionsByNs[$name])) {
  63. return $this->extensionsByNs[$name];
  64. }
  65. throw new \LogicException(sprintf('Container extension "%s" is not registered', $name));
  66. }
  67. /**
  68. * Returns all registered extensions.
  69. *
  70. * @return array An array of ExtensionInterface
  71. *
  72. * @api
  73. */
  74. public function getExtensions()
  75. {
  76. return $this->extensions;
  77. }
  78. /**
  79. * Checks if we have an extension.
  80. *
  81. * @param string $name The name of the extension
  82. * @return Boolean If the extension exists
  83. *
  84. * @api
  85. */
  86. public function hasExtension($name)
  87. {
  88. return isset($this->extensions[$name]) || isset($this->extensionsByNs[$name]);
  89. }
  90. /**
  91. * Returns an array of resources loaded to build this configuration.
  92. *
  93. * @return ResourceInterface[] An array of resources
  94. *
  95. * @api
  96. */
  97. public function getResources()
  98. {
  99. return array_unique($this->resources);
  100. }
  101. /**
  102. * Adds a resource for this configuration.
  103. *
  104. * @param ResourceInterface $resource A resource instance
  105. *
  106. * @return ContainerBuilder The current instance
  107. *
  108. * @api
  109. */
  110. public function addResource(ResourceInterface $resource)
  111. {
  112. $this->resources[] = $resource;
  113. return $this;
  114. }
  115. /**
  116. * Adds the object class hierarchy as resources.
  117. *
  118. * @param object $object An object instance
  119. *
  120. * @api
  121. */
  122. public function addObjectResource($object)
  123. {
  124. $parent = new \ReflectionObject($object);
  125. do {
  126. $this->addResource(new FileResource($parent->getFileName()));
  127. } while ($parent = $parent->getParentClass());
  128. }
  129. /**
  130. * Loads the configuration for an extension.
  131. *
  132. * @param string $extension The extension alias or namespace
  133. * @param array $values An array of values that customizes the extension
  134. *
  135. * @return ContainerBuilder The current instance
  136. *
  137. * @api
  138. */
  139. public function loadFromExtension($extension, array $values = array())
  140. {
  141. if (true === $this->isFrozen()) {
  142. throw new \LogicException('Cannot load from an extension on a frozen container.');
  143. }
  144. $namespace = $this->getExtension($extension)->getAlias();
  145. $this->extensionConfigs[$namespace][] = $values;
  146. return $this;
  147. }
  148. /**
  149. * Adds a compiler pass.
  150. *
  151. * @param CompilerPassInterface $pass A compiler pass
  152. * @param string $type The type of compiler pass
  153. *
  154. * @api
  155. */
  156. public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION)
  157. {
  158. if (null === $this->compiler) {
  159. $this->compiler = new Compiler();
  160. }
  161. $this->compiler->addPass($pass, $type);
  162. $this->addObjectResource($pass);
  163. }
  164. /**
  165. * Returns the compiler pass config which can then be modified.
  166. *
  167. * @return PassConfig The compiler pass config
  168. *
  169. * @api
  170. */
  171. public function getCompilerPassConfig()
  172. {
  173. if (null === $this->compiler) {
  174. $this->compiler = new Compiler();
  175. }
  176. return $this->compiler->getPassConfig();
  177. }
  178. /**
  179. * Returns the compiler.
  180. *
  181. * @return Compiler The compiler
  182. *
  183. * @api
  184. */
  185. public function getCompiler()
  186. {
  187. if (null === $this->compiler) {
  188. $this->compiler = new Compiler();
  189. }
  190. return $this->compiler;
  191. }
  192. /**
  193. * Returns all Scopes.
  194. *
  195. * @return array An array of scopes
  196. *
  197. * @api
  198. */
  199. public function getScopes()
  200. {
  201. return $this->scopes;
  202. }
  203. /**
  204. * Returns all Scope children.
  205. *
  206. * @return array An array of scope children.
  207. *
  208. * @api
  209. */
  210. public function getScopeChildren()
  211. {
  212. return $this->scopeChildren;
  213. }
  214. /**
  215. * Sets a service.
  216. *
  217. * @param string $id The service identifier
  218. * @param object $service The service instance
  219. * @param string $scope The scope
  220. *
  221. * @throws BadMethodCallException
  222. *
  223. * @api
  224. */
  225. public function set($id, $service, $scope = self::SCOPE_CONTAINER)
  226. {
  227. if ($this->isFrozen()) {
  228. throw new \BadMethodCallException('Setting service on a frozen container is not allowed');
  229. }
  230. $id = strtolower($id);
  231. unset($this->definitions[$id], $this->aliases[$id]);
  232. parent::set($id, $service, $scope);
  233. }
  234. /**
  235. * Removes a service definition.
  236. *
  237. * @param string $id The service identifier
  238. *
  239. * @api
  240. */
  241. public function removeDefinition($id)
  242. {
  243. unset($this->definitions[strtolower($id)]);
  244. }
  245. /**
  246. * Returns true if the given service is defined.
  247. *
  248. * @param string $id The service identifier
  249. *
  250. * @return Boolean true if the service is defined, false otherwise
  251. *
  252. * @api
  253. */
  254. public function has($id)
  255. {
  256. $id = strtolower($id);
  257. return isset($this->definitions[$id]) || isset($this->aliases[$id]) || parent::has($id);
  258. }
  259. /**
  260. * Gets a service.
  261. *
  262. * @param string $id The service identifier
  263. * @param integer $invalidBehavior The behavior when the service does not exist
  264. *
  265. * @return object The associated service
  266. *
  267. * @throws \InvalidArgumentException if the service is not defined
  268. * @throws \LogicException if the service has a circular reference to itself
  269. *
  270. * @see Reference
  271. *
  272. * @api
  273. */
  274. public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
  275. {
  276. $id = strtolower($id);
  277. try {
  278. return parent::get($id, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE);
  279. } catch (\InvalidArgumentException $e) {
  280. if (isset($this->loading[$id])) {
  281. throw new \LogicException(sprintf('The service "%s" has a circular reference to itself.', $id), 0, $e);
  282. }
  283. if (!$this->hasDefinition($id) && isset($this->aliases[$id])) {
  284. return $this->get($this->aliases[$id]);
  285. }
  286. try {
  287. $definition = $this->getDefinition($id);
  288. } catch (\InvalidArgumentException $e) {
  289. if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
  290. return null;
  291. }
  292. throw $e;
  293. }
  294. $this->loading[$id] = true;
  295. $service = $this->createService($definition, $id);
  296. unset($this->loading[$id]);
  297. return $service;
  298. }
  299. }
  300. /**
  301. * Merges a ContainerBuilder with the current ContainerBuilder configuration.
  302. *
  303. * Service definitions overrides the current defined ones.
  304. *
  305. * But for parameters, they are overridden by the current ones. It allows
  306. * the parameters passed to the container constructor to have precedence
  307. * over the loaded ones.
  308. *
  309. * $container = new ContainerBuilder(array('foo' => 'bar'));
  310. * $loader = new LoaderXXX($container);
  311. * $loader->load('resource_name');
  312. * $container->register('foo', new stdClass());
  313. *
  314. * In the above example, even if the loaded resource defines a foo
  315. * parameter, the value will still be 'bar' as defined in the ContainerBuilder
  316. * constructor.
  317. *
  318. * @param ContainerBuilder $container The ContainerBuilder instance to merge.
  319. * @throws \LogicException when this ContainerBuilder is frozen
  320. *
  321. * @api
  322. */
  323. public function merge(ContainerBuilder $container)
  324. {
  325. if (true === $this->isFrozen()) {
  326. throw new \LogicException('Cannot merge on a frozen container.');
  327. }
  328. $this->addDefinitions($container->getDefinitions());
  329. $this->addAliases($container->getAliases());
  330. $this->getParameterBag()->add($container->getParameterBag()->all());
  331. foreach ($container->getResources() as $resource) {
  332. $this->addResource($resource);
  333. }
  334. foreach ($this->extensions as $name => $extension) {
  335. if (!isset($this->extensionConfigs[$name])) {
  336. $this->extensionConfigs[$name] = array();
  337. }
  338. $this->extensionConfigs[$name] = array_merge($this->extensionConfigs[$name], $container->getExtensionConfig($name));
  339. }
  340. }
  341. /**
  342. * Returns the configuration array for the given extension.
  343. *
  344. * @param string $name The name of the extension
  345. *
  346. * @return array An array of configuration
  347. *
  348. * @api
  349. */
  350. public function getExtensionConfig($name)
  351. {
  352. if (!isset($this->extensionConfigs[$name])) {
  353. $this->extensionConfigs[$name] = array();
  354. }
  355. return $this->extensionConfigs[$name];
  356. }
  357. /**
  358. * Compiles the container.
  359. *
  360. * This method passes the container to compiler
  361. * passes whose job is to manipulate and optimize
  362. * the container.
  363. *
  364. * The main compiler passes roughly do four things:
  365. *
  366. * * The extension configurations are merged;
  367. * * Parameter values are resolved;
  368. * * The parameter bag is frozen;
  369. * * Extension loading is disabled.
  370. *
  371. * @api
  372. */
  373. public function compile()
  374. {
  375. if (null === $this->compiler) {
  376. $this->compiler = new Compiler();
  377. }
  378. foreach ($this->compiler->getPassConfig()->getPasses() as $pass) {
  379. $this->addObjectResource($pass);
  380. }
  381. $this->compiler->compile($this);
  382. $this->extensionConfigs = array();
  383. parent::compile();
  384. }
  385. /**
  386. * Gets all service ids.
  387. *
  388. * @return array An array of all defined service ids
  389. */
  390. public function getServiceIds()
  391. {
  392. return array_unique(array_merge(array_keys($this->getDefinitions()), array_keys($this->aliases), parent::getServiceIds()));
  393. }
  394. /**
  395. * Adds the service aliases.
  396. *
  397. * @param array $aliases An array of aliases
  398. *
  399. * @api
  400. */
  401. public function addAliases(array $aliases)
  402. {
  403. foreach ($aliases as $alias => $id) {
  404. $this->setAlias($alias, $id);
  405. }
  406. }
  407. /**
  408. * Sets the service aliases.
  409. *
  410. * @param array $aliases An array of service definitions
  411. *
  412. * @api
  413. */
  414. public function setAliases(array $aliases)
  415. {
  416. $this->aliases = array();
  417. $this->addAliases($aliases);
  418. }
  419. /**
  420. * Sets an alias for an existing service.
  421. *
  422. * @param string $alias The alias to create
  423. * @param mixed $id The service to alias
  424. *
  425. * @api
  426. */
  427. public function setAlias($alias, $id)
  428. {
  429. $alias = strtolower($alias);
  430. if (is_string($id)) {
  431. $id = new Alias($id);
  432. } else if (!$id instanceof Alias) {
  433. throw new \InvalidArgumentException('$id must be a string, or an Alias object.');
  434. }
  435. if ($alias === strtolower($id)) {
  436. throw new \InvalidArgumentException('An alias can not reference itself, got a circular reference on "'.$alias.'".');
  437. }
  438. unset($this->definitions[$alias]);
  439. $this->aliases[$alias] = $id;
  440. }
  441. /**
  442. * Removes an alias.
  443. *
  444. * @param string $alias The alias to remove
  445. *
  446. * @api
  447. */
  448. public function removeAlias($alias)
  449. {
  450. unset($this->aliases[strtolower($alias)]);
  451. }
  452. /**
  453. * Returns true if an alias exists under the given identifier.
  454. *
  455. * @param string $id The service identifier
  456. *
  457. * @return Boolean true if the alias exists, false otherwise
  458. *
  459. * @api
  460. */
  461. public function hasAlias($id)
  462. {
  463. return isset($this->aliases[strtolower($id)]);
  464. }
  465. /**
  466. * Gets all defined aliases.
  467. *
  468. * @return array An array of aliases
  469. *
  470. * @api
  471. */
  472. public function getAliases()
  473. {
  474. return $this->aliases;
  475. }
  476. /**
  477. * Gets an alias.
  478. *
  479. * @param string $id The service identifier
  480. *
  481. * @return string The aliased service identifier
  482. *
  483. * @throws \InvalidArgumentException if the alias does not exist
  484. *
  485. * @api
  486. */
  487. public function getAlias($id)
  488. {
  489. $id = strtolower($id);
  490. if (!$this->hasAlias($id)) {
  491. throw new \InvalidArgumentException(sprintf('The service alias "%s" does not exist.', $id));
  492. }
  493. return $this->aliases[$id];
  494. }
  495. /**
  496. * Registers a service definition.
  497. *
  498. * This methods allows for simple registration of service definition
  499. * with a fluid interface.
  500. *
  501. * @param string $id The service identifier
  502. * @param string $class The service class
  503. *
  504. * @return Definition A Definition instance
  505. *
  506. * @api
  507. */
  508. public function register($id, $class = null)
  509. {
  510. return $this->setDefinition(strtolower($id), new Definition($class));
  511. }
  512. /**
  513. * Adds the service definitions.
  514. *
  515. * @param Definition[] $definitions An array of service definitions
  516. *
  517. * @api
  518. */
  519. public function addDefinitions(array $definitions)
  520. {
  521. foreach ($definitions as $id => $definition) {
  522. $this->setDefinition($id, $definition);
  523. }
  524. }
  525. /**
  526. * Sets the service definitions.
  527. *
  528. * @param array $definitions An array of service definitions
  529. *
  530. * @api
  531. */
  532. public function setDefinitions(array $definitions)
  533. {
  534. $this->definitions = array();
  535. $this->addDefinitions($definitions);
  536. }
  537. /**
  538. * Gets all service definitions.
  539. *
  540. * @return array An array of Definition instances
  541. *
  542. * @api
  543. */
  544. public function getDefinitions()
  545. {
  546. return $this->definitions;
  547. }
  548. /**
  549. * Sets a service definition.
  550. *
  551. * @param string $id The service identifier
  552. * @param Definition $definition A Definition instance
  553. *
  554. * @throws BadMethodCallException
  555. *
  556. * @api
  557. */
  558. public function setDefinition($id, Definition $definition)
  559. {
  560. if ($this->isFrozen()) {
  561. throw new \BadMethodCallException('Adding definition to a frozen container is not allowed');
  562. }
  563. $id = strtolower($id);
  564. unset($this->aliases[$id]);
  565. return $this->definitions[$id] = $definition;
  566. }
  567. /**
  568. * Returns true if a service definition exists under the given identifier.
  569. *
  570. * @param string $id The service identifier
  571. *
  572. * @return Boolean true if the service definition exists, false otherwise
  573. *
  574. * @api
  575. */
  576. public function hasDefinition($id)
  577. {
  578. return array_key_exists(strtolower($id), $this->definitions);
  579. }
  580. /**
  581. * Gets a service definition.
  582. *
  583. * @param string $id The service identifier
  584. *
  585. * @return Definition A Definition instance
  586. *
  587. * @throws \InvalidArgumentException if the service definition does not exist
  588. *
  589. * @api
  590. */
  591. public function getDefinition($id)
  592. {
  593. $id = strtolower($id);
  594. if (!$this->hasDefinition($id)) {
  595. throw new \InvalidArgumentException(sprintf('The service definition "%s" does not exist.', $id));
  596. }
  597. return $this->definitions[$id];
  598. }
  599. /**
  600. * Gets a service definition by id or alias.
  601. *
  602. * The method "unaliases" recursively to return a Definition instance.
  603. *
  604. * @param string $id The service identifier or alias
  605. *
  606. * @return Definition A Definition instance
  607. *
  608. * @throws \InvalidArgumentException if the service definition does not exist
  609. *
  610. * @api
  611. */
  612. public function findDefinition($id)
  613. {
  614. while ($this->hasAlias($id)) {
  615. $id = (string) $this->getAlias($id);
  616. }
  617. return $this->getDefinition($id);
  618. }
  619. /**
  620. * Creates a service for a service definition.
  621. *
  622. * @param Definition $definition A service definition instance
  623. * @param string $id The service identifier
  624. *
  625. * @return object The service described by the service definition
  626. *
  627. * @throws \InvalidArgumentException When configure callable is not callable
  628. */
  629. private function createService(Definition $definition, $id)
  630. {
  631. if (null !== $definition->getFile()) {
  632. require_once $this->getParameterBag()->resolveValue($definition->getFile());
  633. }
  634. $arguments = $this->resolveServices($this->getParameterBag()->resolveValue($definition->getArguments()));
  635. if (null !== $definition->getFactoryMethod()) {
  636. if (null !== $definition->getFactoryClass()) {
  637. $factory = $this->getParameterBag()->resolveValue($definition->getFactoryClass());
  638. } elseif (null !== $definition->getFactoryService()) {
  639. $factory = $this->get($this->getParameterBag()->resolveValue($definition->getFactoryService()));
  640. } else {
  641. throw new \RuntimeException('Cannot create service from factory method without a factory service or factory class.');
  642. }
  643. $service = call_user_func_array(array($factory, $definition->getFactoryMethod()), $arguments);
  644. } else {
  645. $r = new \ReflectionClass($this->getParameterBag()->resolveValue($definition->getClass()));
  646. $service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
  647. }
  648. if (self::SCOPE_PROTOTYPE !== $scope = $definition->getScope()) {
  649. if (self::SCOPE_CONTAINER !== $scope && !isset($this->scopedServices[$scope])) {
  650. throw new \RuntimeException('You tried to create a service of an inactive scope.');
  651. }
  652. $this->services[$lowerId = strtolower($id)] = $service;
  653. if (self::SCOPE_CONTAINER !== $scope) {
  654. $this->scopedServices[$scope][$lowerId] = $service;
  655. }
  656. }
  657. foreach ($definition->getMethodCalls() as $call) {
  658. $services = self::getServiceConditionals($call[1]);
  659. $ok = true;
  660. foreach ($services as $s) {
  661. if (!$this->has($s)) {
  662. $ok = false;
  663. break;
  664. }
  665. }
  666. if ($ok) {
  667. call_user_func_array(array($service, $call[0]), $this->resolveServices($this->getParameterBag()->resolveValue($call[1])));
  668. }
  669. }
  670. $properties = $this->resolveServices($this->getParameterBag()->resolveValue($definition->getProperties()));
  671. foreach ($properties as $name => $value) {
  672. $service->$name = $value;
  673. }
  674. if ($callable = $definition->getConfigurator()) {
  675. if (is_array($callable) && is_object($callable[0]) && $callable[0] instanceof Reference) {
  676. $callable[0] = $this->get((string) $callable[0]);
  677. } elseif (is_array($callable)) {
  678. $callable[0] = $this->getParameterBag()->resolveValue($callable[0]);
  679. }
  680. if (!is_callable($callable)) {
  681. throw new \InvalidArgumentException(sprintf('The configure callable for class "%s" is not a callable.', get_class($service)));
  682. }
  683. call_user_func($callable, $service);
  684. }
  685. return $service;
  686. }
  687. /**
  688. * Replaces service references by the real service instance.
  689. *
  690. * @param mixed $value A value
  691. *
  692. * @return mixed The same value with all service references replaced by the real service instances
  693. */
  694. public function resolveServices($value)
  695. {
  696. if (is_array($value)) {
  697. foreach ($value as &$v) {
  698. $v = $this->resolveServices($v);
  699. }
  700. } elseif (is_object($value) && $value instanceof Reference) {
  701. $value = $this->get((string) $value, $value->getInvalidBehavior());
  702. } elseif (is_object($value) && $value instanceof Definition) {
  703. $value = $this->createService($value, null);
  704. }
  705. return $value;
  706. }
  707. /**
  708. * Returns service ids for a given tag.
  709. *
  710. * @param string $name The tag name
  711. *
  712. * @return array An array of tags
  713. *
  714. * @api
  715. */
  716. public function findTaggedServiceIds($name)
  717. {
  718. $tags = array();
  719. foreach ($this->getDefinitions() as $id => $definition) {
  720. if ($definition->getTag($name)) {
  721. $tags[$id] = $definition->getTag($name);
  722. }
  723. }
  724. return $tags;
  725. }
  726. /**
  727. * Returns the Service Conditionals.
  728. *
  729. * @param mixed $value An array of conditionals to return.
  730. * @return array An array of Service conditionals
  731. */
  732. static public function getServiceConditionals($value)
  733. {
  734. $services = array();
  735. if (is_array($value)) {
  736. foreach ($value as $v) {
  737. $services = array_unique(array_merge($services, self::getServiceConditionals($v)));
  738. }
  739. } elseif (is_object($value) && $value instanceof Reference && $value->getInvalidBehavior() === ContainerInterface::IGNORE_ON_INVALID_REFERENCE) {
  740. $services[] = (string) $value;
  741. }
  742. return $services;
  743. }
  744. }