Beispiel #1
0
 /**
  * @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;
 }
Beispiel #2
0
 /**
  * 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;
 }
Beispiel #3
0
 /**
  * @expectedException \Janeiro\Di\Exception
  * @expectedExceptionMessage Service "foobar" is unknown
  */
 public function testExceptionThrownWhenAccessingAnUnknownService()
 {
     $this->container->get('foobar');
 }
Beispiel #4
0
 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'));
 }