我对此没有信心,我有两个班级
class Abc {
public $hi = 'hi';
public function __construct($xxx, $yyy) {}
public function test() { echo 'test'; }
}
class Def extends Abc {
public $hi = 'hello';
public function __construct($xxx, $yyy) {
parent::__construct($xxx, $yyy);
}
public function test() { echo 'testing'; }
}
我在laravel的服务提供商看起来像
class MyServiceProvider extends ServiceProvider {
public function register() {
$this->app->singleton('abc', function() {
return new Abc(config('my.xxx'), config('my.yyy'));
});
$this->app->alias('abc', Abc::class);
$this->app->singleton('cde', function() {
return new Cde(config('my.xxx'), config('my.yyy'));
});
$this->app->alias('cde', Cde::class);
}
}
这是正确的方法还是更好的实施?