$value) { if (is_numeric($key)) { $start++; $array[$start] = array_pull($array, $key); } } return $array; } } if (!function_exists('array_add')) { /** * Add an element to an array using "dot" notation if it doesn't exist. * * @param array $array * @param string $key * @param mixed $value * @return array */ function array_add($array, $key, $value) { if (is_null(get($array, $key))) { set($array, $key, $value); } return $array; } } if (!function_exists('array_build')) { /** * Build a new array using a callback. * * @param array $array * @param \Closure $callback * @return array */ function array_build($array, Closure $callback) { $results = array(); foreach ($array as $key => $value) { list($innerKey, $innerValue) = call_user_func($callback, $key, $value); $results[$innerKey] = $innerValue; } return $results; } } if (!function_exists('array_divide')) { /** * Divide an array into two arrays. One with keys and the other with values. * * @param array $array * @return array */ function array_divide($array) { return array(array_keys($array), array_values($array)); } } if (!function_exists('array_dot')) { /** * Flatten a multi-dimensional associative array with dots. * * @param array $array * @param string $prepend * @return array */ function array_dot($array, $prepend = '') { $results = array(); foreach ($array as $key => $value) { if (is_array($value)) { $results = array_merge($results, dot($value, $prepend . $key . '.')); } else { $results[$prepend . $key] = $value; } } return $results; } } if (!function_exists('array_except')) { /** * Get all of the given array except for a specified array of items. * * @param array $array * @param array|string $keys * @return array */ function array_except($array, $keys) { return array_diff_key($array, array_flip((array)$keys)); } } if (!function_exists('array_fetch')) { /** * Fetch a flattened array of a nested array element. * * @param array $array * @param string $key * @return array */ function array_fetch($array, $key) { $results = array(); foreach (explode('.', $key) as $segment) { foreach ($array as $value) { if (array_key_exists($segment, $value = (array)$value)) { $results[] = $value[$segment]; } } $array = array_values($results); } return array_values($results); } } if (!function_exists('array_first')) { /** * Return the first element in an array passing a given truth test. * * @param array $array * @param \Closure $callback * @param mixed $default * @return mixed */ function array_first($array, $callback, $default = null) { foreach ($array as $key => $value) { if (call_user_func($callback, $key, $value)) { return $value; } } return value($default); } } if (!function_exists('array_last')) { /** * Return the last element in an array passing a given truth test. * * @param array $array * @param \Closure $callback * @param mixed $default * @return mixed */ function array_last($array, $callback, $default = null) { return first(array_reverse($array), $callback, $default); } } if (!function_exists('array_flatten')) { /** * Flatten a multi-dimensional array into a single level. * * @param array $array * @return array */ function array_flatten($array) { $return = array(); array_walk_recursive($array, function ($x) use (&$return) { $return[] = $x; }); return $return; } } if (!function_exists('array_forget')) { /** * Remove one or many array items from a given array using "dot" notation. * * @param array $array * @param array|string $keys * @return void */ function array_forget(&$array, $keys) { $original =& $array; foreach ((array)$keys as $key) { $parts = explode('.', $key); while (count($parts) > 1) { $part = array_shift($parts); if (isset($array[$part]) && is_array($array[$part])) { $array =& $array[$part]; } } unset($array[array_shift($parts)]); // clean up after each pass $array =& $original; } } } if (!function_exists('array_get')) { /** * Get an item from an array using "dot" notation. * * @param array $array * @param string $key * @param mixed $default * @return mixed */ function array_get($array, $key, $default = null) { if (is_null($key)) { return $array; } if (isset($array[$key])) { return $array[$key]; } foreach (explode('.', $key) as $segment) { if (!is_array($array) || !array_key_exists($segment, $array)) { return value($default); } $array = $array[$segment]; } return $array; } } if (!function_exists('array_has')) { /** * Check if an item exists in an array using "dot" notation. * * @param array $array * @param string $key * @return bool */ function array_has($array, $key) { if (empty($array) || is_null($key)) { return false; } if (array_key_exists($key, $array)) { return true; } foreach (explode('.', $key) as $segment) { if (!is_array($array) || !array_key_exists($segment, $array)) { return false; } $array = $array[$segment]; } return true; } } if (!function_exists('array_only')) { /** * Get a subset of the items from the given array. * * @param array $array * @param array|string $keys * @return array */ function array_only($array, $keys) { return array_intersect_key($array, array_flip((array)$keys)); } } if (!function_exists('array_pluck')) { /** * Pluck an array of values from an array. * * @param array $array * @param string $value * @param string $key * @return array */ function array_pluck($array, $value, $key = null) { $results = array(); foreach ($array as $item) { $itemValue = data_get($item, $value); // If the key is "null", we will just append the value to the array and keep // looping. Otherwise we will key the array using the value of the key we // received from the developer. Then we'll return the final array form. if (is_null($key)) { $results[] = $itemValue; } else { $itemKey = data_get($item, $key); $results[$itemKey] = $itemValue; } } return $results; } } if (!function_exists('array_pull')) { /** * Get a value from the array, and remove it. * * @param array $array * @param string $key * @param mixed $default * @return mixed */ function array_pull(&$array, $key, $default = null) { $value = get($array, $key, $default); forget($array, $key); return $value; } } if (!function_exists('array_set')) { /** * Set an array item to a given value using "dot" notation. * * If no key is given to the method, the entire array will be replaced. * * @param array $array * @param string $key * @param mixed $value * @return array */ function array_set(&$array, $key, $value) { if (is_null($key)) { return $array = $value; } $keys = explode('.', $key); while (count($keys) > 1) { $key = array_shift($keys); // If the key doesn't exist at this depth, we will just create an empty array // to hold the next value, allowing us to create the arrays to hold final // values at the correct depth. Then we'll keep digging into the array. if (!isset($array[$key]) || !is_array($array[$key])) { $array[$key] = array(); } $array =& $array[$key]; } $array[array_shift($keys)] = $value; return $array; } } if (!function_exists('array_where')) { /** * Filter the array using the given Closure. * * @param array $array * @param \Closure $callback * @return array */ function array_where($array, Closure $callback) { $filtered = array(); foreach ($array as $key => $value) { if (call_user_func($callback, $key, $value)) { $filtered[$key] = $value; } } return $filtered; } } if (!function_exists('camel_case')) { /** * Convert a value to camel case. * * @param string $value * @return string */ function camel_case($value) { static $camelCache = []; if (isset($camelCache[$value])) { return $camelCache[$value]; } return $camelCache[$value] = lcfirst(studly($value)); } } if (!function_exists('class_basename')) { /** * Get the class "basename" of the given object / class. * * @param string|object $class * @return string */ function class_basename($class) { $class = is_object($class) ? get_class($class) : $class; return basename(str_replace('\\', '/', $class)); } } if (!function_exists('class_uses_recursive')) { /** * Returns all traits used by a class, it's subclasses and trait of their traits * * @param string $class * @return array */ function class_uses_recursive($class) { $results = []; foreach (array_merge([$class => $class], class_parents($class)) as $class) { $results += trait_uses_recursive($class); } return array_unique($results); } } if (!function_exists('data_get')) { /** * Get an item from an array or object using "dot" notation. * * @param mixed $target * @param string $key * @param mixed $default * @return mixed */ function data_get($target, $key, $default = null) { if (is_null($key)) { return $target; } foreach (explode('.', $key) as $segment) { if (is_array($target)) { if (!array_key_exists($segment, $target)) { return value($default); } $target = $target[$segment]; } elseif ($target instanceof ArrayAccess) { if (!isset($target[$segment])) { return value($default); } $target = $target[$segment]; } elseif (is_object($target)) { if (!isset($target->{$segment})) { return value($default); } $target = $target->{$segment}; } else { return value($default); } } return $target; } } if (!function_exists('e')) { /** * Escape HTML entities in a string. * * @param string $value * @return string */ function e($value) { return htmlentities($value, ENT_QUOTES, 'UTF-8', false); } } if (!function_exists('ends_with')) { /** * Determine if a given string ends with a given substring. * * @param string $haystack * @param string|array $needles * @return bool */ function ends_with($haystack, $needles) { foreach ((array)$needles as $needle) { if ((string)$needle === substr($haystack, -strlen($needle))) { return true; } } return false; } } if (!function_exists('head')) { /** * Get the first element of an array. Useful for method chaining. * * @param array $array * @return mixed */ function head($array) { return reset($array); } } if (!function_exists('last')) { /** * Get the last element from an array. * * @param array $array * @return mixed */ function last($array) { return end($array); } } if (!function_exists('object_get')) { /** * Get an item from an object using "dot" notation. * * @param object $object * @param string $key * @param mixed $default * @return mixed */ function object_get($object, $key, $default = null) { if (is_null($key) || trim($key) == '') { return $object; } foreach (explode('.', $key) as $segment) { if (!is_object($object) || !isset($object->{$segment})) { return value($default); } $object = $object->{$segment}; } return $object; } } if (!function_exists('preg_replace_sub')) { /** * Replace a given pattern with each value in the array in sequentially. * * @param string $pattern * @param array $replacements * @param string $subject * @return string */ function preg_replace_sub($pattern, &$replacements, $subject) { return preg_replace_callback($pattern, function () use (&$replacements) { return array_shift($replacements); }, $subject); } } if (!function_exists('snake_case')) { /** * Convert a string to snake case. * * @param string $value * @param string $delimiter * @return string */ function snake_case($value, $delimiter = '_') { static $snakeCache = []; $key = $value . $delimiter; if (isset($snakeCache[$key])) { return $snakeCache[$key]; } if (!ctype_lower($value)) { $value = strtolower(preg_replace('/(.)(?=[A-Z])/', '$1' . $delimiter, $value)); } return $snakeCache[$key] = $value; } } if (!function_exists('starts_with')) { /** * Determine if a given string starts with a given substring. * * @param string $haystack * @param string|array $needles * @return bool */ function starts_with($haystack, $needles) { foreach ((array)$needles as $needle) { if ($needle != '' && strpos($haystack, $needle) === 0) { return true; } } return false; } } if (!function_exists('str_contains')) { /** * Determine if a given string contains a given substring. * * @param string $haystack * @param string|array $needles * @return bool */ function str_contains($haystack, $needles) { foreach ((array)$needles as $needle) { if ($needle != '' && strpos($haystack, $needle) !== false) { return true; } } return false; } } if (!function_exists('str_finish')) { /** * Cap a string with a single instance of a given value. * * @param string $value * @param string $cap * @return string */ function str_finish($value, $cap) { $quoted = preg_quote($cap, '/'); return preg_replace('/(?:' . $quoted . ')+$/', '', $value) . $cap; } } if (!function_exists('str_is')) { /** * Determine if a given string matches a given pattern. * * @param string $pattern * @param string $value * @return bool */ function str_is($pattern, $value) { if ($pattern == $value) { return true; } $pattern = preg_quote($pattern, '#'); // Asterisks are translated into zero-or-more regular expression wildcards // to make it convenient to check if the strings starts with the given // pattern such as "library/*", making any string check convenient. $pattern = str_replace('\*', '.*', $pattern) . '\z'; return (bool)preg_match('#^' . $pattern . '#', $value); } } if (!function_exists('str_limit')) { /** * Limit the number of characters in a string. * * @param string $value * @param int $limit * @param string $end * @return string */ function str_limit($value, $limit = 100, $end = '...') { if (mb_strlen($value) <= $limit) { return $value; } return rtrim(mb_substr($value, 0, $limit, 'UTF-8')) . $end; } } if (!function_exists('str_random')) { /** * Generate a more truly "random" alpha-numeric string. * * @param int $length * @return string * * @throws \RuntimeException */ function str_random($length = 16) { if (!function_exists('openssl_random_pseudo_bytes')) { throw new RuntimeException('OpenSSL extension is required.'); } $bytes = openssl_random_pseudo_bytes($length * 2); if ($bytes === false) { throw new RuntimeException('Unable to generate random string.'); } return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $length); } } if (!function_exists('str_replace_array')) { /** * Replace a given value in the string sequentially with an array. * * @param string $search * @param array $replace * @param string $subject * @return string */ function str_replace_array($search, array $replace, $subject) { foreach ($replace as $value) { $subject = preg_replace('/' . $search . '/', $value, $subject, 1); } return $subject; } } if (!function_exists('str_slug')) { /** * Generate a URL friendly "slug" from a given string. * * @param string $title * @param string $separator * @return string */ function str_slug($title, $separator = '-') { $title = ascii($title); // Convert all dashes/underscores into separator $flip = $separator == '-' ? '_' : '-'; $title = preg_replace('![' . preg_quote($flip) . ']+!u', $separator, $title); // Remove all characters that are not the separator, letters, numbers, or whitespace. $title = preg_replace('![^' . preg_quote($separator) . '\pL\pN\s]+!u', '', mb_strtolower($title)); // Replace all separator characters and whitespace by a single separator $title = preg_replace('![' . preg_quote($separator) . '\s]+!u', $separator, $title); return trim($title, $separator); } } if (!function_exists('ascii')) { /** * Transliterate a UTF-8 value to ASCII. * * @param string $value * @return string */ function ascii($value) { foreach (charsArray() as $key => $val) { $value = str_replace($val, $key, $value); } return preg_replace('/[^\x20-\x7E]/u', '', $value); } } if (!function_exists('charsArray')) { /** * Returns the replacements for the ascii method. * * Note: Adapted from Stringy\Stringy. * * @see https://github.com/danielstjules/Stringy/blob/2.3.1/LICENSE.txt * * @return array */ function charsArray() { static $charsArray; if (isset($charsArray)) { return $charsArray; } return $charsArray = [ '0' => ['°', '₀', '۰'], '1' => ['¹', '₁', '۱'], '2' => ['²', '₂', '۲'], '3' => ['³', '₃', '۳'], '4' => ['⁴', '₄', '۴', '٤'], '5' => ['⁵', '₅', '۵', '٥'], '6' => ['⁶', '₆', '۶', '٦'], '7' => ['⁷', '₇', '۷'], '8' => ['⁸', '₈', '۸'], '9' => ['⁹', '₉', '۹'], 'a' => [ 'à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ', 'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ā', 'ą', 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ', 'ာ', 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا' ], 'b' => ['б', 'β', 'Ъ', 'Ь', 'ب', 'ဗ', 'ბ'], 'c' => ['ç', 'ć', 'č', 'ĉ', 'ċ'], 'd' => ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ'], 'e' => [ 'é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', 'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є', 'ə', 'ဧ', 'ေ', 'ဲ', 'ე', 'ए', 'إ', 'ئ' ], 'f' => ['ф', 'φ', 'ف', 'ƒ', 'ფ'], 'g' => ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ'], 'h' => ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ'], 'i' => [ 'í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į', 'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и', 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი', 'इ' ], 'j' => ['ĵ', 'ј', 'Ј', 'ჯ', 'ج'], 'k' => ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک'], 'l' => ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ'], 'm' => ['м', 'μ', 'م', 'မ', 'მ'], 'n' => ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န', 'ნ'], 'o' => [ 'ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ' ], 'p' => ['п', 'π', 'ပ', 'პ', 'پ'], 'q' => ['ყ'], 'r' => ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ'], 's' => ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ', 'ſ', 'ს'], 't' => ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ', 'თ', 'ტ'], 'u' => [ 'ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', 'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', 'ဉ', 'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ' ], 'v' => ['в', 'ვ', 'ϐ'], 'w' => ['ŵ', 'ω', 'ώ', 'ဝ', 'ွ'], 'x' => ['χ', 'ξ'], 'y' => ['ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ', 'ϋ', 'ύ', 'ΰ', 'ي', 'ယ'], 'z' => ['ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ'], 'aa' => ['ع', 'आ', 'آ'], 'ae' => ['ä', 'æ', 'ǽ'], 'ai' => ['ऐ'], 'at' => ['@'], 'ch' => ['ч', 'ჩ', 'ჭ', 'چ'], 'dj' =>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 'У', 'Ǔ', 'Ǖ', 'Ǘ', 'Ǚ', 'Ǜ' ], 'V' => ['В'], 'W' => ['Ω', 'Ώ', 'Ŵ'], 'X' => ['Χ', 'Ξ'], 'Y' => ['Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ'], 'Z' => ['Ź', 'Ž', 'Ż', 'З', 'Ζ'], 'AE' => ['Ä', 'Æ', 'Ǽ'], 'CH' => ['Ч'], 'DJ' => ['Ђ'], 'DZ' => ['Џ'], 'GX' => ['Ĝ'], 'HX' => ['Ĥ'], 'IJ' => ['IJ'], 'JX' => ['Ĵ'], 'KH' => ['Х'], 'LJ' => ['Љ'], 'NJ' => ['Њ'], 'OE' => ['Ö', 'Œ'], 'PS' => ['Ψ'], 'SH' => ['Ш'], 'SHCH' => ['Щ'], 'SS' => ['ẞ'], 'TH' => ['Þ'], 'TS' => ['Ц'], 'UE' => ['Ü'], 'YA' => ['Я'], 'YU' => ['Ю'], 'ZH' => ['Ж'], ' ' => [ "\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81", "\xE2\x80\x82", "\xE2\x80\x83", "\xE2\x80\x84", "\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87", "\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A", "\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80" ], ]; } } if (!function_exists('studly_case')) { /** * Convert a value to studly caps case. * * @param string $value * @return string */ function studly_case($value) { static $studlyCache = []; $key = $value; if (isset($studlyCache[$key])) { return $studlyCache[$key]; } $value = ucwords(str_replace(array('-', '_'), ' ', $value)); return $studlyCache[$key] = str_replace(' ', '', $value); } } if (!function_exists('title_case')) { /** * Convert a value to title case. * * @param string $value * @return string */ function title_case($value) { return mb_convert_case($value, MB_CASE_TITLE, 'UTF-8'); } } if (!function_exists('trait_uses_recursive')) { /** * Returns all traits used by a trait and its traits * * @param string $trait * @return array */ function trait_uses_recursive($trait) { $traits = class_uses($trait); foreach ($traits as $trait) { $traits += trait_uses_recursive($trait); } return $traits; } } if (!function_exists('value')) { /** * Return the default value of the given value. * * @param mixed $value * @return mixed */ function value($value) { return $value instanceof Closure ? $value() : $value; } } if (!function_exists('with')) { /** * Return the given object. Useful for chaining. * * @param mixed $object * @return mixed */ function with($object) { return $object; } } /** * Helper functions for the helper functions, that can still be used standalone */ if (!function_exists('studly')) { /** * Convert a value to studly caps case. * * @param string $value * @return string */ function studly($value) { static $studlyCache = []; $key = $value; if (isset($studlyCache[$key])) { return $studlyCache[$key]; } $value = ucwords(str_replace(array('-', '_'), ' ', $value)); return $studlyCache[$key] = str_replace(' ', '', $value); } } if (!function_exists('get')) { /** * Get an item from an array using "dot" notation. * * @param array $array * @param string $key * @param mixed $default * @return mixed */ function get($array, $key, $default = null) { if (is_null($key)) { return $array; } if (isset($array[$key])) { return $array[$key]; } foreach (explode('.', $key) as $segment) { if (!is_array($array) || !array_key_exists($segment, $array)) { return value($default); } $array = $array[$segment]; } return $array; } } if (!function_exists('set')) { /** * Set an array item to a given value using "dot" notation. * * If no key is given to the method, the entire array will be replaced. * * @param array $array * @param string $key * @param mixed $value * @return array */ function set(&$array, $key, $value) { if (is_null($key)) { return $array = $value; } $keys = explode('.', $key); while (count($keys) > 1) { $key = array_shift($keys); // If the key doesn't exist at this depth, we will just create an empty array // to hold the next value, allowing us to create the arrays to hold final // values at the correct depth. Then we'll keep digging into the array. if (!isset($array[$key]) || !is_array($array[$key])) { $array[$key] = array(); } $array =& $array[$key]; } $array[array_shift($keys)] = $value; return $array; } } if (!function_exists('dot')) { /** * Flatten a multi-dimensional associative array with dots. * * @param array $array * @param string $prepend * @return array */ function dot($array, $prepend = '') { $results = array(); foreach ($array as $key => $value) { if (is_array($value)) { $results = array_merge($results, dot($value, $prepend . $key . '.')); } else { $results[$prepend . $key] = $value; } } return $results; } } if (!function_exists('first')) { /** * Return the first element in an array passing a given truth test. * * @param array $array * @param \Closure $callback * @param mixed $default * @return mixed */ function first($array, $callback, $default = null) { foreach ($array as $key => $value) { if (call_user_func($callback, $key, $value)) { return $value; } } return value($default); } } if (!function_exists('forget')) { /** * Remove one or many array items from a given array using "dot" notation. * * @param array $array * @param array|string $keys * @return void */ function forget(&$array, $keys) { $original =& $array; foreach ((array)$keys as $key) { $parts = explode('.', $key); while (count($parts) > 1) { $part = array_shift($parts); if (isset($array[$part]) && is_array($array[$part])) { $array =& $array[$part]; } } unset($array[array_shift($parts)]); // clean up after each pass $array =& $original; } } } if (!function_exists('bcrypt')) { /** * Password hash the given value. * * @param string $value * @param array $options * @return string * * @throws \RuntimeException */ function bcrypt($value, $options = []) { $cost = isset($options['rounds']) ? $options['rounds'] : 10; $hashedValue = password_hash($value, PASSWORD_BCRYPT, ['cost' => $cost]); if ($hashedValue === false) { throw new RuntimeException('Bcrypt hashing not supported.'); } return $hashedValue; } } if (!function_exists('tap')) { /** * Call the given Closure with the given value then return the value. * * @param mixed $value * @param callable $callback * @return mixed */ function tap($value, $callback) { $callback($value); return $value; } } if (!function_exists('dd')) { /** * Dump the passed variables and end the script. * * @param mixed * @return void */ function dd() { array_map(function ($x) { var_dump($x); }, func_get_args()); die(1); } } if (!function_exists('data_fill')) { /** * Fill in data where it's missing. * * @param mixed $target * @param string|array $key * @param mixed $value * @return mixed */ function data_fill(&$target, $key, $value) { return data_set($target, $key, $value, false); } } if (! function_exists('data_set')) { /** * Set an item on an array or object using dot notation. * * @param mixed $target * @param string|array $key * @param mixed $value * @param bool $overwrite * @return mixed */ function data_set(&$target, $key, $value, $overwrite = true) { $segments = is_array($key) ? $key : explode('.', $key); if (($segment = array_shift($segments)) === '*') { if (! accessible($target)) { $target = []; } if ($segments) { foreach ($target as &$inner) { data_set($inner, $segments, $value, $overwrite); } } elseif ($overwrite) { foreach ($target as &$inner) { $inner = $value; } } } elseif (accessible($target)) { if ($segments) { if (! exists($target, $segment)) { $target[$segment] = []; } data_set($target[$segment], $segments, $value, $overwrite); } elseif ($overwrite || ! exists($target, $segment)) { $target[$segment] = $value; } } elseif (is_object($target)) { if ($segments) { if (! isset($target->{$segment})) { $target->{$segment} = []; } data_set($target->{$segment}, $segments, $value, $overwrite); } elseif ($overwrite || ! isset($target->{$segment})) { $target->{$segment} = $value; } } else { $target = []; if ($segments) { data_set($target[$segment], $segments, $value, $overwrite); } elseif ($overwrite) { $target[$segment] = $value; } } return $target; } /** * Determine whether the given value is array accessible. * * @param mixed $value * @return bool */ function accessible($value) { return is_array($value) || $value instanceof ArrayAccess; } /** * Determine if the given key exists in the provided array. * * @param \ArrayAccess|array $array * @param string|int $key * @return bool */ function exists($array, $key) { if ($array instanceof ArrayAccess) { return $array->offsetExists($key); } return array_key_exists($key, $array); } }