灰太狼 2018-11-02 16:53:15 2063次浏览 0条回复 0 0 0
class Container
{
    protected $binds;

    protected $instances;

    public function bind($abstract,$concrete)
    {
        if($concrete instanceof \Closure){
            $this->binds[$abstract] = $concrete;
        } else {
            $this->instances[$abstract] = $concrete;
        }
    }

    public function make($abstract,$parameters = [])
    {
        if(isset($this->instances[$abstract])){
            return $this->instances[$abstract];
        }
        $parameters = [$parameters];
        array_unshift($parameters,$this);
        return call_user_func_array($this->binds[$abstract],$parameters);
    }
}
    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册