modify plugin name

This commit is contained in:
2022-02-18 15:28:29 +08:00
parent 0bd7139232
commit 0278a4aac2
2 changed files with 21 additions and 74 deletions
+10 -43
View File
@@ -75,14 +75,18 @@ class Connection extends Component
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws Exception
*/
public function init()
{
$this->getEventProvider()->on(OnWorkerStop::class, [$this, 'clear_connection'], 0);
$this->getEventProvider()->on(OnWorkerExit::class, [$this, 'clear_connection'], 0);
$this->getEventProvider()->on(BeginTransaction::class, [$this, 'beginTransaction'], 0);
$this->getEventProvider()->on(Rollback::class, [$this, 'rollback'], 0);
$this->getEventProvider()->on(Commit::class, [$this, 'commit'], 0);
$provider = $this->getEventProvider();
$provider->on(OnWorkerStop::class, [$this, 'clear_connection'], 0);
$provider->on(OnWorkerExit::class, [$this, 'clear_connection'], 0);
$provider->on(BeginTransaction::class, [$this, 'beginTransaction'], 0);
$provider->on(Rollback::class, [$this, 'rollback'], 0);
$provider->on(Commit::class, [$this, 'commit'], 0);
$this->connectPoolInstance();
}
@@ -100,7 +104,7 @@ class Connection extends Component
/**
* @throws Exception
*/
public function fill()
public function connectPoolInstance()
{
$connections = $this->connections();
$pool = Config::get('databases.pool.max', 10);
@@ -109,43 +113,6 @@ class Connection extends Component
if (!empty($this->slaveConfig) && $this->cds != $this->slaveConfig['cds']) {
$connections->initConnections('Mysql:' . $this->slaveConfig['cds'], false, $pool);
}
// $name = $connections->name('Mysql:' . $this->cds, true);
//
// $config = $this->_config();
// for ($i = 0; $i < $pool; $i++) {
// $connections->addItem($name, $connections->create($name, $config)());
// }
//
// if (empty($this->slaveConfig)) {
// return;
// }
//
// $config['cds'] = $this->slaveConfig['cds'];
// $config['username'] = $this->slaveConfig['username'];
// $config['password'] = $this->slaveConfig['password'];
//
// $name = $connections->name('Mysql:' . $config['cds'], false);
// for ($i = 0; $i < $pool; $i++) {
// $connections->addItem($name, $connections->create($name, $config)());
// }
}
/**
* @return array
*/
private function _config(): array
{
return [
'cds' => $this->cds,
'username' => $this->username,
'password' => $this->password,
'attributes' => $this->attributes,
'connect_timeout' => $this->connect_timeout,
'read_timeout' => $this->read_timeout,
'dbname' => $this->database,
'pool' => $this->pool
];
}
+11 -31
View File
@@ -9,11 +9,7 @@ use Kiri;
use Kiri\Abstracts\Config;
use Kiri\Abstracts\Providers;
use Kiri\Application;
use Kiri\Events\OnBeforeCommandExecute;
use Kiri\Exception\ConfigException;
use Kiri\Server\Events\OnServerBeforeStart;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/**
* Class DatabasesProviders
@@ -26,12 +22,19 @@ class DatabasesProviders extends Providers
/**
* @param Application $application
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ConfigException
*/
public function onImport(Application $application)
{
$this->getEventProvider()->on(CreateConnectionPool::class, [$this, 'createPool']);
$databases = Config::get('databases.connections', []);
if (empty($databases)) {
return;
}
$app = Kiri::app();
foreach ($databases as $key => $database) {
$app->set($key, $this->_settings($database));
}
}
@@ -45,30 +48,6 @@ class DatabasesProviders extends Providers
return Kiri::app()->get($name);
}
/**
* @throws ConfigException
* @throws Exception
*/
public function createPool(OnServerBeforeStart $onWorkerStart)
{
$databases = Config::get('databases.connections', []);
if (empty($databases)) {
return;
}
$app = Kiri::app();
foreach ($databases as $key => $database) {
$database = $this->_settings($database);
$connection = Kiri::getDi()->create(Connection::class, [$database]);
$connection->fill();
$app->set($key, $connection);
}
}
/**
* @param $database
* @return array
@@ -79,6 +58,7 @@ class DatabasesProviders extends Providers
return [
'id' => $database['id'],
'cds' => $database['cds'],
'class' => Connection::class,
'username' => $database['username'],
'password' => $database['password'],
'tablePrefix' => $database['tablePrefix'],