Skip to content

Commit

Permalink
改进
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Jul 21, 2021
1 parent 3ee8c59 commit 5d3d5c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
11 changes: 3 additions & 8 deletions src/DbManager.php
Expand Up @@ -17,7 +17,6 @@
use Psr\SimpleCache\CacheInterface;
use think\db\BaseQuery;
use think\db\ConnectionInterface;
use think\db\exception\DbEventException;
use think\db\Query;
use think\db\Raw;

Expand Down Expand Up @@ -363,14 +362,10 @@ public function event(string $event, callable $callback): void
*/
public function trigger(string $event, $params = null)
{
try {
if (isset($this->event[$event])) {
foreach ($this->event[$event] as $callback) {
call_user_func_array($callback, [$params]);
}
if (isset($this->event[$event])) {
foreach ($this->event[$event] as $callback) {
call_user_func_array($callback, [$params]);
}
} catch (DbEventException $e) {
return false;
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/db/PDOConnection.php
Expand Up @@ -16,6 +16,7 @@
use PDO;
use PDOStatement;
use think\db\exception\BindParamException;
use think\db\exception\DbEventException;
use think\db\exception\DbException;
use think\db\exception\PDOException;
use think\Model;
Expand Down Expand Up @@ -865,7 +866,9 @@ protected function queryPDOStatement(BaseQuery $query, string $sql, array $bind
public function find(BaseQuery $query): array
{
// 事件回调
if (false === $this->db->trigger('before_find', $query)) {
try {
$this->db->trigger('before_find', $query);
} catch (DbEventException $e) {
return [];
}

Expand Down Expand Up @@ -906,7 +909,9 @@ public function cursor(BaseQuery $query)
*/
public function select(BaseQuery $query): array
{
if (false === $this->db->trigger('before_select', $query)) {
try {
$this->db->trigger('before_select', $query);
} catch (DbEventException $e) {
return [];
}

Expand Down

0 comments on commit 5d3d5c1

Please sign in to comment.