Skip to content

Commit

Permalink
fix lib
Browse files Browse the repository at this point in the history
  • Loading branch information
lidanyang committed May 27, 2019
1 parent 066ea11 commit 05bc752
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 24 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"require": {
"esd/base-server":"~0.1",
"thingengineer/mysqli-database-class": "~2.9.2",
"esd/aop-plugin":"~0.1"
"esd/esd-core":"~0.1",
"esd/aop-plugin":"~0.1",

"thingengineer/mysqli-database-class": "~2.9.2"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 2 additions & 4 deletions src/Mysql/Aspect/MysqlAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace ESD\Plugins\Mysql\Aspect;


use ESD\BaseServer\Coroutine\Channel;
use ESD\Core\Channel\Channel;
use ESD\Plugins\Aop\OrderAspect;
use ESD\Plugins\Mysql\Annotation\Isolation;
use ESD\Plugins\Mysql\Annotation\Propagation;
Expand All @@ -28,7 +28,6 @@ class MysqlAspect extends OrderAspect
*
* @Around("@execution(ESD\Plugins\Mysql\Annotation\Transactional)")
* @return mixed
* @throws \ESD\BaseServer\Exception
* @throws \Throwable
*/
public function aroundTransactional(MethodInvocation $invocation)
Expand Down Expand Up @@ -98,7 +97,7 @@ public function aroundTransactional(MethodInvocation $invocation)
}
if ($needNewGo) {
//需要创建一个新的协程来执行mysql
$channel = new Channel();
$channel = DIGet(Channel::class);
goWithContext(function () use ($transactional, $invocation, $needTransaction, $channel) {
$db = $this->mysql($transactional->name);
try {
Expand Down Expand Up @@ -134,7 +133,6 @@ public function aroundTransactional(MethodInvocation $invocation)
* @param MethodInvocation $invocation
* @return mixed|null
* @throws TransactionException
* @throws \ESD\BaseServer\Exception
* @throws \Throwable
*/
private function startTransaction(Transactional $transactional, \MysqliDb $db, MethodInvocation $invocation)
Expand Down
2 changes: 1 addition & 1 deletion src/Mysql/GetMysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait GetMysql
/**
* @param string $name
* @return MysqliDb
* @throws \ESD\BaseServer\Exception
* @throws MysqlException
*/
public function mysql($name = "default")
{
Expand Down
2 changes: 1 addition & 1 deletion src/Mysql/MysqlConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace ESD\Plugins\Mysql;


use ESD\BaseServer\Plugins\Config\BaseConfig;
use ESD\Core\Plugins\Config\BaseConfig;

class MysqlConfig extends BaseConfig
{
Expand Down
2 changes: 1 addition & 1 deletion src/Mysql/MysqlException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace ESD\Plugins\Mysql;


use ESD\BaseServer\Exception;
use ESD\Core\Exception;

class MysqlException extends Exception
{
Expand Down
1 change: 0 additions & 1 deletion src/Mysql/MysqlManyPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function addPool(MysqlPool $mysqlPool)
/**
* @return MysqliDb
* @throws MysqlException
* @throws \ESD\BaseServer\Exception
*/
public function db(): MysqliDb
{
Expand Down
26 changes: 17 additions & 9 deletions src/Mysql/MysqlPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

namespace ESD\Plugins\Mysql;

use ESD\BaseServer\Plugins\Logger\GetLogger;
use ESD\BaseServer\Server\Context;
use ESD\BaseServer\Server\Plugin\AbstractPlugin;
use ESD\BaseServer\Server\Server;
use ESD\Core\Plugins\Logger\GetLogger;
use ESD\Core\Context\Context;
use ESD\Core\PlugIn\AbstractPlugin;
use ESD\Core\Server\Server;
use ESD\Plugins\Aop\AopConfig;
use ESD\Plugins\Aop\AopPlugin;
use ESD\Plugins\Mysql\Aspect\MysqlAspect;
Expand Down Expand Up @@ -39,18 +39,25 @@ public function __construct()
$this->atAfter(AopPlugin::class);
}

/**
* @param Context $context
* @return mixed|void
* @throws \DI\DependencyException
* @throws \DI\NotFoundException
*/
public function init(Context $context)
{
parent::init($context);
$aopConfig = Server::$instance->getContainer()->get(AopConfig::class);
$aopConfig = DIget(AopConfig::class);
$aopConfig->addAspect(new MysqlAspect());
}

/**
* 在服务启动前
* @param Context $context
* @return mixed
* @throws \ESD\BaseServer\Server\Exception\ConfigException
* @throws \DI\DependencyException
* @throws \DI\NotFoundException
* @throws \ESD\Core\Plugins\Config\ConfigException
*/
public function beforeServerStart(Context $context)
{
Expand All @@ -66,8 +73,9 @@ public function beforeServerStart(Context $context)
/**
* 在进程启动前
* @param Context $context
* @return mixed
* @throws \ESD\BaseServer\Exception
* @throws MysqlException
* @throws \DI\DependencyException
* @throws \DI\NotFoundException
* @throws \ReflectionException
*/
public function beforeProcessStart(Context $context)
Expand Down
7 changes: 4 additions & 3 deletions src/Mysql/MysqlPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace ESD\Plugins\Mysql;


use ESD\BaseServer\Coroutine\Channel;
use ESD\Core\Channel\Channel;

class MysqlPool
{
Expand All @@ -26,12 +26,14 @@ class MysqlPool
* MysqlPool constructor.
* @param MysqlConfig $mysqlConfig
* @throws MysqlException
* @throws \DI\DependencyException
* @throws \DI\NotFoundException
*/
public function __construct(MysqlConfig $mysqlConfig)
{
$this->mysqlConfig = $mysqlConfig;
$config = $mysqlConfig->buildConfig();
$this->pool = new Channel($mysqlConfig->getPoolMaxNumber());
$this->pool = DIGet(Channel::class, [$mysqlConfig->getPoolMaxNumber()]);
for ($i = 0; $i < $mysqlConfig->getPoolMaxNumber(); $i++) {
$db = new MysqliDb($config);
$this->pool->push($db);
Expand All @@ -40,7 +42,6 @@ public function __construct(MysqlConfig $mysqlConfig)

/**
* @return MysqliDb
* @throws \ESD\BaseServer\Exception
*/
public function db(): MysqliDb
{
Expand Down
2 changes: 1 addition & 1 deletion src/Mysql/TransactionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace ESD\Plugins\Mysql;


use ESD\BaseServer\Exception;
use ESD\Core\Exception;

class TransactionException extends Exception
{
Expand Down

0 comments on commit 05bc752

Please sign in to comment.