/** * Tests the get method. * * @see \Drupal\Core\DependencyInjection\Container::get() */ public function testGet() { $service = new \stdClass(); $service->key = 'value'; $this->container->set('test_service', $service); $result = $this->container->get('test_service'); $this->assertSame($service, $result); $this->assertEquals('test_service', $result->_serviceId); }
/** * {@inheritdoc} */ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) { if ($id === 'http_kernel') { throw new \Exception('Thrown exception during Container::get'); } else { return parent::get($id, $invalidBehavior); } }
/** * {@inheritdoc} */ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) { if ($id === 'http_kernel') { // Enforce a recoverable error. $callable = function (ErrorContainer $container) { }; $callable(1); } else { return parent::get($id, $invalidBehavior); } }
/** * @param string $id * @param int $invalidBehavior * * @return object */ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) { if (!$this->stopwatch && $this->has('stopwatch')) { $this->stopwatch = parent::get('stopwatch'); $this->stopwatch->openSection(); $this->hasStopwatch = TRUE; } if ('stopwatch' === $id) { return $this->stopwatch; } Timer::start($id); if ($this->hasStopwatch) { $e = $this->stopwatch->start($id, 'service'); } $service = parent::get($id, $invalidBehavior); $this->tracedData[$id] = Timer::stop($id); if ($this->hasStopwatch && $e->isStarted()) { $e->stop(); } return $service; }