Пример #1
0
Файл: args.php Проект: ihor/Nspl
 /**
  * @param string|object|array $type
  * @param bool $onlyOr
  * @return string
  */
 public static function getFor($type, $onlyOr = false)
 {
     if (is_array($type)) {
         $messagesFor = f\partial(a\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) || interface_exists($t);
             };
             list($orTypes, $andTypes) = a\partition($isOr, $type);
             return implode(' and ', array_filter([implode(' or ', $messagesFor($orTypes)), implode(' and ', $messagesFor($andTypes))]));
         }
     }
     if ($type instanceof Constraint) {
         return $type->__toString();
     }
     $default = class_exists($type) || interface_exists($type) ? $type : implode(' ', array_map('strtolower', preg_split('/(?=[A-Z])/', a\last(explode('\\', $type)))));
     return a\value(self::$messages, $type, 'be ' . $default);
 }
Пример #2
0
 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);
 }