Пример #1
0
 /**
  * @covers ::__construct
  * @covers ::initContainer
  * @covers ::register
  * @covers ::has
  * @covers ::get
  * @covers Nora\Core\DI\Exception\InstanceNotFound::__construct
  * @expectedException Nora\Core\DI\Exception\InstanceNotFound
  */
 public function testCreate()
 {
     $c = new Container();
     $c->register(['hOge' => function () {
         return new \StdClass();
     }]);
     $this->assertTrue($c->has('Hoge'));
     $this->assertInstanceOf('StdClass', $c->get('hogE'));
     $c->get('Hoge')->cnt = 0;
     $c->get('hoGe')->cnt++;
     $c->on('di.container.pre_get', function ($e) {
         if (strtolower($e->name) === 'phpunit') {
             $e->instance = $this;
         }
     });
     $this->assertEquals($this, $c->get('phpUnit'));
     $c->get('InvalidName');
 }
Пример #2
0
 public function testRegisterServiceProvider()
 {
     $di = new Container();
     $di->register(new TestServiceProvider());
     $this->assertInstanceOf('Lebran\\TestService', $di->get('test'));
 }
Пример #3
0
<?php

include dirname(__DIR__) . '/bootstrap/start.php';
$app = new \Slim\Slim(['debut' => true, 'templates.path' => ROOT . '/view']);
Container::register('app', function () use($app) {
    return $app;
});
// require routes
include ROOT . '/index/urls.php';
include ROOT . '/search/urls.php';
include ROOT . '/detail/urls.php';
include ROOT . '/about/urls.php';
$app->run();
Пример #4
0
echo $value;
$value2 = $container->hash() . '<br>';
echo $value2;
//echo '$value and $value2 refer to the same instance: ' . bool2str($value === $value2) . '<br>';
// temp function converts boolean to string
function bool2str($bool)
{
    if ($bool === false) {
        return 'FALSE';
    } else {
        return 'TRUE';
    }
}
// provider interface
echo '<div class="subtitle">6. part</div>';
$container->register(new UserServiceProvider());
$container->get("UserService")->getUser(3);
$container->get("UserApplicationService")->getUserApplications(317);
?>

                        </div>
                    </div>


                </div>
            </div>
        </div>
    </section>

    <!-- Bootstrap framework -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>