Beispiel #1
0
 function __invoke(Di $di, $share = [])
 {
     if (is_string($this->x)) {
         return $di->get($this->x, $this->params, false, $share);
     } else {
         return call_user_func_array($this->x, $this->params);
     }
 }
Beispiel #2
0
 public function serve()
 {
     $support_callback = ['start' => [$this, 'onStart'], 'managerStart' => [$this, 'onManagerStart'], 'workerStart' => [$this, 'onWorkerStart'], 'receive' => [$this, 'onReceive'], 'task' => null, 'finish' => null, 'workerStop' => [$this, 'onWorkerStop']];
     foreach ($support_callback as $name => $callback) {
         // If has the dependency injection
         if (is_callable(Di::get($name))) {
             $callback = Di::get($name);
         }
         if ($callback !== null) {
             $this->serv->on($name, $callback);
         }
     }
     $this->serv->set($this->swoole_config);
     $this->serv->start();
 }
Beispiel #3
0
 public function run()
 {
     Di::get('server')->serve();
 }
Beispiel #4
0
    public function __construct($name = '')
    {
        $this->name = $name;
    }
}
include "Di.class.php";
$di = new Di();
//匿名函数方式注册一个a1服务
$di->setShared('a1', function ($name = '') {
    return new A($name);
});
//直接以类名的方式注册
$di->set('a2', 'A');
//直接传入实例化的对象
$di->set('a3', new A('小超'));
$a1 = $di->get('a1', array('小李'));
echo $a1->name, "<br/>";
$a1_1 = $di->get('a1', array('小王'));
echo $a1->name, "<br/>";
echo $a1_1->name, "<br/>";
$a2 = $di->get('a2', array("小张"));
echo $a2->name . "<br/>";
//小张
$a2_1 = $di->get('a2', array("小徐"));
echo $a2->name . "<br/>";
//小张
echo $a2_1->name . "<br/>";
//小徐
$a3 = $di['a3'];
//可以直接通过数组方式获取服务对象
echo $a3->name . "<br/>";
Beispiel #5
0
 public function test_default_null_parameter_value()
 {
     $object = Di::get('DiTest\\FooBar');
     $this->assertNull($object->param1);
 }