$params]; } elseif ($params === false) { $params = ['not' => true]; } elseif (is_string($params)) { $params = ['message' => $params]; } return $params; } /** * Set callback * @param Closure $callback * @return bool */ protected function setCallback(Closure $callback): bool { if (! ($callback instanceof Closure)) { return false; } $this->callback = $callback; return true; } /** * Check if rule is optional * @param mixed $data * @return bool */ public function isOptional($data): bool { if ($this->isNot()) { return true; } elseif ($this->callback instanceof Closure) { $callback = $this->callback; if ($callback($data, $this->validator) === false) { $this->setNot(true); return true; } else { return false; } } return false; } /** * Set callback * @param Closure $callback * @return static */ public function callback(Closure $callback) { $this->setCallback($callback); return $this; } public function check(&$value) { if ($this->isNot()) { return true; } return ! $this->isEmpty($value); } /** * Default message * @return string */ public function defaultMessage(): string { return _t('error', 'The [attribute] is required'); } }