예제 #1
0
 /**
  * @param string|object|array $type
  * @param bool $onlyOr
  * @return string
  */
 public static function getFor($type, $onlyOr = false)
 {
     if (is_array($type)) {
         $messagesFor = f\partial(f\map, ['\\nspl\\args\\_p\\ErrorMessage', 'getFor']);
         if ($onlyOr) {
             return implode(' or ', $messagesFor($type));
         } else {
             $isOr = function ($t) {
                 return isset(Checker::$isOr[$t]) || class_exists($t);
             };
             list($orTypes, $andTypes) = f\partition($isOr, $type);
             return implode(' and ', array_filter([implode(' or ', $messagesFor($orTypes)), implode(' and ', $messagesFor($andTypes))]));
         }
     }
     if ($type instanceof Constraint) {
         return $type->__toString();
     }
     return a\getByKey(self::$messages, $type, 'be ' . (class_exists($type) ? $type : end(explode('\\', $type))));
 }
예제 #2
0
파일: FTest.php 프로젝트: ihor/Nspl
 public function testPartition()
 {
     $this->assertEquals([[1, 2, 3], ['a', 'b', 'c']], partition('is_numeric', ['a', 1, 'b', 2, 'c', 3]));
     $this->assertEquals([array('b' => 2), array('a' => 1, 'c' => 3)], partition(function ($v) {
         return $v % 2 === 0;
     }, array('a' => 1, 'b' => 2, 'c' => 3)));
     $this->assertEquals([[], []], partition('is_int', []));
     $this->assertEquals([[1, 2, 3], ['a', 'b', 'c']], call_user_func(partition, 'is_numeric', ['a', 1, 'b', 2, 'c', 3]));
     $this->assertEquals('\\nspl\\a\\partition', partition);
 }