예제 #1
0
 public function __construct(Loader $loader, $opt = null)
 {
     $this->_container = Container::getInstance();
     $this->_request = new Request($_REQUEST, $_SERVER);
     $this->_loader = $loader;
     if (!$opt) {
         $opt = [];
     }
     $loader->prepare($this, $opt);
     $this->_options = $opt;
     $this->_response = new Response();
     //set default error handler
     $this->error(function () {
         echo "oops";
     }, -1);
     if (isset($opt["url"])) {
         $this->request()->setUrl($opt["url"]);
     }
     self::$_inst = $this;
 }
예제 #2
0
 function testSingleton()
 {
     $container = new Container();
     $container->share(Hoge::class, function () {
         return new Hoge("default value");
     });
     /* @var $hoge Hoge */
     $hoge = $container->make(Hoge::class);
     $hoge->value = "書き換えました";
     //singletonパターンで副作用のある動作ってのはちょっとアレだけど
     $hoge2 = $container->make(Hoge::class);
     $this->assertEquals("書き換えました", $hoge2->value);
     $this->assertEquals($hoge, $hoge2);
     //destoryで作り直しが出来ます
     $container->destory();
     $hoge3 = $container->make(Hoge::class);
     $this->assertNotEquals($hoge2, $hoge3);
     $this->assertEquals("default value", $hoge3->value);
 }