/** * Check that the spec matches and overlay help messaged. * * The resulting SpecResult instance should have more user-friendly * messages. This allows one to use Specs for validation on a website or * even an API. * * @param array $input * * @return SpecResult */ public function check(array $input) { $result = $this->spec->check($input); return new SpecResult($result->getMissing(), Arr::walkCopy($result->getFailed(), function ($key, $value, &$array, $path) { $array[$key] = Std::coalesce(Std::firstBias(Arr::dotGet($this->messages, Std::nonempty($path, $key)) !== null, [Arr::dotGet($this->messages, Std::nonempty($path, $key))], null), Std::firstBias($value instanceof AbstractConstraint, function () use($value) { return $value->getDescription(); }, null), Std::firstBias(is_array($value), function () use($value) { return array_map(function (AbstractConstraint $item) { return $item->getDescription(); }, $value); }, $value)); }, true, '', false), $result->getStatus()); }