public function generateConfigurationArray(Website $website): array
{
switch ($mode) {
case static::DIVISION_MODE_SEPARATE_DATABASE:
// ORIGINAL CODE
$clone['username'] = $clone['database'] = $website->uuid;
$clone['password'] = $this->passwordGenerator->generate($website);
break;
case static::DIVISION_MODE_BYPASS:
break;
default:
throw new ConnectionException("Division mode '$mode' unknown.");
}
}
Я хотел бы переопределить эту функцию из Hyn \ Tenancy \ Database \ Connection (мультитенант laravel), но я понятия не имею, кто-нибудь даст мне пример?
public function generateConfigurationArray(Website $website): array
{
switch ($mode) {
case static::DIVISION_MODE_SEPARATE_DATABASE:
// MAKE CHANGE CODE
$clone['username'] = 'username';
$clone['database'] = $website->uuid;
$clone['password'] = 'password';
break;
case static::DIVISION_MODE_BYPASS:
break;
default:
throw new ConnectionException("Division mode '$mode' unknown.");
}
}
Мне пришлось попробовать поставщика услуг, но из-за того, что функция имеет параметр, я не знаю, как его передать, и получил ошибку тоже, это код поставщика, который я положил в регистр $ this-> app-> bind ('Hyn \ Tenancy \ Database\ Connection ',' App \ Vendor \ CustomConnection ');
Неустранимая ошибка PHP: объявление App \ Vendor \ CustomConnection :: get () должно быть совместимо с Hyn \ Tenancy \ Database \ Connection :: get (): Illuminate \ Database \ Connection, в этом и заключается ошибка iполучил
CustomConnectionServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Hyn\Tenancy\Providers\Tenants\ConnectionProvider as ConnectionProvider;
use Hyn\Tenancy\Database\Connection;
class CustomConnectionServiceProvider extends ConnectionProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
/*$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Hyn\Tenancy\Database\Connection', 'app\Vendor\CustomConnection');*/
$this->app->bind('Hyn\Tenancy\Database\Connection', 'App\Vendor\CustomConnection');
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
}
}
app / vendor / CustomConnection.php
<?php
namespace App\Vendor;
use Hyn\Tenancy\Database\Connection as Connection;
class CustomConnection extends Connection
{
public function generateConfigurationArray(Website $website): array
{
$clone = config(sprintf(
'database.connections.%s',
$website->managed_by_database_connection ?? $this->systemName()
));
$mode = config('tenancy.db.tenant-division-mode');
$this->emitEvent(new Events\Database\ConfigurationLoading($mode, $clone, $this));
// Even though username/password mutate, let's store website UUID so we can match it up.
$clone['uuid'] = $website->uuid;
switch ($mode) {
case static::DIVISION_MODE_SEPARATE_DATABASE:
$clone['username'] = 'username'
%clone['database'] = $website->uuid;
$clone['password'] = 'password';
break;
case static::DIVISION_MODE_SEPARATE_PREFIX:
$clone['prefix'] = sprintf('%d_', $website->id);
break;
case static::DIVISION_MODE_BYPASS:
break;
default:
throw new ConnectionException("Division mode '$mode' unknown.");
}
$this->emitEvent(new Events\Database\ConfigurationLoaded($clone, $this));
return $clone;
}
}