/** * Ensure that dynamic settings are correctly reset, * so that services that rely on those are correctly updated. */ private function resetDynamicSettings() { // Ensure to reset services that need to be. foreach ($this->resettableServiceIds as $serviceId) { if (!$this->container->initialized($serviceId)) { continue; } $this->container->set($serviceId, null); } // Update services that can be updated. foreach ($this->updatableServices as $serviceId => $methodCalls) { if (!$this->container->initialized($serviceId)) { continue; } $service = $this->container->get($serviceId); foreach ($methodCalls as $callConfig) { list($method, $expression) = $callConfig; $argument = $this->expressionLanguage->evaluate($expression, ['container' => $this->container]); call_user_func_array([$service, $method], [$argument]); } } }
/** * Returns a real transport used to send mails by a mailer specified in the constructor of this class * * @return \Swift_Transport|null */ protected function findRealTransport() { $realTransport = null; $mailers = array_keys($this->container->getParameter('swiftmailer.mailers')); foreach ($mailers as $name) { if ($this->container instanceof IntrospectableContainerInterface && !$this->container->initialized(sprintf('swiftmailer.mailer.%s', $name))) { continue; } $mailer = $this->container->get(sprintf('swiftmailer.mailer.%s', $name)); if ($mailer === $this->baseMailer) { $realTransport = $this->container->get(sprintf('swiftmailer.mailer.%s.transport.real', $name)); break; } } return $realTransport; }
/** * Moves persistent service instances into a new container. */ protected function persistServices(ContainerInterface $container, array $persist) { foreach ($persist as $id => $object) { // Do not override services already set() on the new container, for // example 'service_container'. if (!$container->initialized($id)) { $container->set($id, $object); } } }
/** * Tests that Container::initialized works correctly for aliases. * * @covers ::initialized */ public function testInitializedForAliases() { $this->assertFalse($this->container->initialized('late.service_alias'), 'Late service is not initialized.'); $this->container->get('late.service'); $this->assertTrue($this->container->initialized('late.service_alias'), 'Late service is initialized after it was retrieved once.'); }