/** * @param mixed $fragment, ... * @return Path */ public final function prepend($fragment) : Path { foreach (Arr::simplify(func_get_args()) as $fragment) { $this->Fragments = Arr::prepend($this->Fragments, preg_split('/' . preg_quote(DIRECTORY_SEPARATOR, '/') . '/', trim($fragment), -1, PREG_SPLIT_NO_EMPTY)); } return $this; }
/** * @param int $type * @param string $value * @return bool * @throws \Exception */ public static final function make($type, $value) { switch ((int) $type) { case self::HASH_TYPE_MD5: return md5(implode(Arr::simplify(array_slice(func_get_args(), 1)))); } throw new \Exception('Unknown validation type "' . $type . '"!'); }
/** * Join all given arguments into one single string. * * @attention Type Casting is provided so this method cant throw an exception * if one or more arguments cannot be represented as a string. * * @param string $separator * @param mixed $source, ... * @return string */ public static final function join($separator, $source) { return implode($separator, array_map(function ($value) { return Str::cast($value); }, array_filter(Arr::simplify(array_slice(func_get_args(), 1))))); }
/** * @param string $path * @return array */ public static function files($path) { return Arr::simplify(array_map(function ($value) { return $value[strlen($value) - 1] == '/' ? [Fs::files($value)] : $value; }, glob(rtrim($path, '/') . '/*', GLOB_NOSORT | GLOB_MARK))); }
/** * @param array $Source * @param \Closure $Callback * @param array|string $keys, ... * @return array */ public static final function each(array $Source, \Closure $Callback, $keys = null) { return array_walk($Source, function (&$value, $key, $keys) use($Callback) { $value = count($keys) < 1 || in_array($key, $keys) ? $Callback($key, $value) : $value; }, Arr::simplify(array_slice(func_get_args(), 2))) ? $Source : []; }