<?php


namespace App\Traits;


use App\Services\LogService;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;

trait TestableInstant
{


    /**
     * 实例化一个service的入口，为了测试方便做出来的，这样测试时可以代入假的柱件替换service的实现
     * 应当在一般性用app的地方换成本方法才可以做到使用柱件
     * @param $targetService
     * @param $abstractClassName
     * @return Application|mixed|string
     */
    public function instant(&$targetService, $abstractClassName){
        if(!is_string($targetService)){
            if(empty($targetService))
                $targetService=app($abstractClassName);
            return $targetService;
        }
        if(!is_string($abstractClassName)){
            $this->$targetService=$abstractClassName;
        }else{
            $this->$targetService=app($abstractClassName);
        }
        return $targetService;
    }
}
