/** * @param int $index * @return mixed */ private function resolveParameter($index) { $parameter = null; if ($this->container->has('registry')) { $key = sprintf('services.%s.parameters.%d', $this->name, $index); $parameter = $this->container->get('registry')->get($key, null); } return $parameter; }
/** * Get instance of MVC view object * * @throws \Janeiro\Mvc\Exception * @return ViewInterface */ private function getViewObject() { $success = false; try { $renderer = $this->container->get($this->getView()); if ($renderer instanceof ViewInterface) { $success = true; } } catch (\Exception $e) { $renderer = null; } if (false === $success) { throw new Exception('Could not create view'); } return $renderer; }
/** * @expectedException \Janeiro\Di\Exception * @expectedExceptionMessage Service "foobar" is unknown */ public function testExceptionThrownWhenAccessingAnUnknownService() { $this->container->get('foobar'); }
public function testResolveWithAutoWiringParametersFromRegistry() { $config = ['services' => ['some_service' => ['class' => '\\Janeiro\\Di\\ServiceDummyWithParameters', 'parameters' => [0 => ['foo' => 'bar']]]]]; $container = new Container(new Registry($config)); $this->assertEquals('bar', $container->get('some_service')->getParameter('foo')); }