[vendor / laravel / framework / src / Illuminate / Database / DatabaseManager.php中有一种方法
/**
* Parse the connection into an array of the name and read / write type.
*
* @param string $name
* @return array
*/
protected function parseConnectionName($name)
{
$name = $name ?: $this->getDefaultConnection();
return Str::endsWith($name, ['::read', '::write'])
? explode('::', $name, 2) : [$name, null];
}
如果我想覆盖此方法,我该怎么做?
由于此方法受到保护,因此您必须在Illuminate\Database\DatabaseManager
文件夹中创建一个扩展app
的类,并使用您自己的类覆盖该函数
然后通过绑定单例将自定义类注入到容器中
$this->app->bind('Illuminate\Database\DatabaseManager', function () {
return new App\CustomClass;
});
希望这会有所帮助