/** * @param string $method * @param array $values * @param array $methodArgs * @return \Closure */ function methodReturnAnyOf($method, array $values, array $methodArgs = []) { if (empty($values)) { return never(); } return combine(isObject(), hasMethod($method), function ($object) use($method, $values, $methodArgs) { return in_array(callOnClone($object, $method, $methodArgs), $values, true); }); }
/** * @param int $min * @return \Closure */ function sizeMinStrict($min) { if (!is_numeric($min)) { return never(); } return function ($value) use($min) { $size = polymorphicSize($value); return is_int($size) && $size > (int) $min; }; }
/** * @param string $regex * @return \Closure */ function match($regex) { if (!is_string($regex) || $regex === '') { return never(); } $first = substr($regex, 0, 1); $last = substr($regex, -1, 1); if ($first !== $last || strlen($regex) === 1) { $regex = "/{$regex}/"; } return function ($value) use($regex) { return is_string($value) && @preg_match($regex, $value) === 1; }; }
/** * @param string $type * @return \Closure */ function isType($type) { if (is_object($type)) { $type = get_class($type); } if (!is_string($type)) { return never(); } if (class_exists($type) || interface_exists($type)) { return function ($value) use($type) { return is_object($value) && is_a($value, $type, false); }; } return function ($value) use($type) { $nType = strtolower($type); $nType === 'float' and $nType = 'double'; $nType === 'bool' and $nType = 'boolean'; $nType === 'int' and $nType = 'integer'; $nType === 'null' and $nType = 'NULL'; return gettype($value) === $nType; }; }
/** * @param array $values * @return \Closure */ function hasAnyOfValues(array $values) { if (empty($values)) { return never(); } return poolFactory($values, '\\Pentothal\\hasValue'); }
/** * @param callable[] $callbacks * @return \Closure */ function poolMap(array $callbacks) { $callbacks = array_filter($callbacks, 'is_callable'); if (empty($callbacks)) { return never(); } return function ($item) use($callbacks) { if (!is_array($item) && !is_object($item)) { return false; } foreach ($callbacks as $key => $callback) { if (variadicCallBoolVal(keyApply($key, $callback), func_get_args())) { return true; } } return false; }; }