diff --git a/src/base/GraphQLField.php b/src/base/GraphQLField.php index 7c57fbe..13eb33b 100644 --- a/src/base/GraphQLField.php +++ b/src/base/GraphQLField.php @@ -45,6 +45,7 @@ protected function getResolver() $resolver = array($this, 'resolve'); return function () use ($resolver) { $args = func_get_args(); + $this->trigger(GraphQLModel::EVENT_BEFORE_RESOLVE); return $resolver(...$args); }; } @@ -80,4 +81,4 @@ public function getAttributes($name = null, $except = null) return $attributes; } -} \ No newline at end of file +} diff --git a/src/base/GraphQLModel.php b/src/base/GraphQLModel.php index 0f2bc57..d2e7bc4 100644 --- a/src/base/GraphQLModel.php +++ b/src/base/GraphQLModel.php @@ -16,6 +16,8 @@ */ class GraphQLModel extends Model { + const EVENT_BEFORE_RESOLVE = 'beforeResolve'; + /** * All of the attributes set on the container. * @@ -76,4 +78,4 @@ public function __unset($name) } -} \ No newline at end of file +} diff --git a/src/traits/ShouldValidate.php b/src/traits/ShouldValidate.php index 63866f2..5d6ca7d 100644 --- a/src/traits/ShouldValidate.php +++ b/src/traits/ShouldValidate.php @@ -27,6 +27,7 @@ protected function getResolver() $rules = $this->rules(); if (sizeof($rules)) { + $this->trigger(\yii\base\Model::EVENT_BEFORE_VALIDATE); //索引1的为args参数. $args = ArrayHelper::getValue($arguments, 1, []); $val = DynamicModel::validateData($args, $rules);