예제 #1
0
 /**
  * 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());
 }
예제 #2
0
 public function testNonempty()
 {
     $this->assertEqualsMatrix([['hello', Std::nonempty(0, '', 'hello', [])], ['hello', Std::nonempty(0, '', [], 'hello')], [[1, 2, 3], Std::nonempty(0, '', [], '', [1, 2, 3])], [[1, 2, 3], Std::nonempty(0, '', false, '', [1, 2, 3])]]);
 }