Skip to content
This repository was archived by the owner on Apr 27, 2022. It is now read-only.

Events implementation #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/base/GraphQLField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
Expand Down Expand Up @@ -80,4 +81,4 @@ public function getAttributes($name = null, $except = null)

return $attributes;
}
}
}
4 changes: 3 additions & 1 deletion src/base/GraphQLModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
class GraphQLModel extends Model
{
const EVENT_BEFORE_RESOLVE = 'beforeResolve';

/**
* All of the attributes set on the container.
*
Expand Down Expand Up @@ -76,4 +78,4 @@ public function __unset($name)
}


}
}
1 change: 1 addition & 0 deletions src/traits/ShouldValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down