From fd59dbbef2eee315e09b41ad8c536e97759fe264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E5=A8=98?= <30471441@qq.com> Date: Fri, 26 Nov 2021 13:55:34 +0800 Subject: [PATCH] =?UTF-8?q?=20*=20=E4=BF=AE=E6=94=B9=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=EF=BC=8C=E4=BD=BF=E5=85=B6=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=80=A7=E6=9B=B4=E6=98=8E=E7=A1=AE=E3=80=82=20=20*=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=A3=E7=A0=81=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - .phpstorm.meta.php | 16 ++++++++++++++++ src/Validate.php | 20 +++++++++----------- 3 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 .phpstorm.meta.php diff --git a/.gitignore b/.gitignore index ae2b966..04a7bb3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ temp/ runtime/ *.lock .DS_Store -.phpstorm.meta* /.env /vendor /.idea diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php new file mode 100644 index 0000000..38cb6a2 --- /dev/null +++ b/.phpstorm.meta.php @@ -0,0 +1,16 @@ + + * + * This is not a free software + * Using it under the license terms + * visited https://www.w7.cc for more details + */ + +namespace PHPSTORM_META{ + expectedArguments(\W7\Validate\Validate::addCallback(), 0, 'event', 'before', 'after'); + expectedArguments(\W7\Validate\Validate::handleEventCallback(), 1, 'before', 'after'); +} diff --git a/src/Validate.php b/src/Validate.php index 6bfe99c..f287bb6 100644 --- a/src/Validate.php +++ b/src/Validate.php @@ -219,9 +219,9 @@ class Validate extends RuleManager if ($this->eventPriority) { $this->handleEvent($data, 'beforeValidate'); - $this->handleCallback($data, 1); + $this->handleEventCallback($data, 'before'); } else { - $this->handleCallback($data, 1); + $this->handleEventCallback($data, 'before'); $this->handleEvent($data, 'beforeValidate'); } @@ -232,11 +232,11 @@ class Validate extends RuleManager } if ($this->eventPriority) { - $this->handleCallback($validatedData, 2); + $this->handleEventCallback($validatedData, 'after'); $this->handleEvent($validatedData, 'afterValidate'); } else { $this->handleEvent($validatedData, 'afterValidate'); - $this->handleCallback($validatedData, 2); + $this->handleEventCallback($validatedData, 'after'); } $validatedData = $this->handlerFilter($validatedData, $fields); @@ -417,19 +417,17 @@ class Validate extends RuleManager * Processing method * * @param array $data - * @param int $type 1 before method 2 after method + * @param string $type 'before' or 'after' * @throws ValidateException */ - private function handleCallback(array $data, int $type) + private function handleEventCallback(array $data, string $type) { switch ($type) { - case 1: + case 'before': $callbacks = $this->befores; - $typeName = 'before'; break; - case 2: + case 'after': $callbacks = $this->afters; - $typeName = 'after'; break; } @@ -440,7 +438,7 @@ class Validate extends RuleManager foreach ($callbacks as $callback) { list($callback, $param) = $callback; if (!is_callable($callback)) { - $callback = $typeName . ucfirst($callback); + $callback = $type . ucfirst($callback); if (!method_exists($this, $callback)) { throw new ValidateRuntimeException('Method Not Found'); } -- Gitee