diff --git a/.gitignore b/.gitignore index ae2b966f76002225bf0b817504201e7a2a99bd0b..04a7bb3ee1b49c7d98db860d49be2553c799a240 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 0000000000000000000000000000000000000000..38cb6a24545ae06fbda5a660c9b1ad42f58e6ee4 --- /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 6bfe99cb6096f7d76aa5e96f9e004406d94d1cfd..f287bb6755a0c8d1006630f34dce23f122a80458 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'); }