/laravel-helpers

Laravel 5 Helper function for Non-Laravel Projects

Primary LanguagePHP

Package Logo

Laravel Helpers for Non-Laravel Projects

Latest Version on Packagist Total Downloads

This project takes the useful Laravel helper functions and allows you to use them in Non-Laravel projects.

Enjoying this package? Buy me a beer 🍺

Installation

composer require rappasoft/laravel-helpers

Documentation

Arrays

/**
 * Determine whether the given value is array accessible.
 *
 * @param  mixed  $value
 *
 * @return bool
 */
function array_accessible($value): bool
/**
 * 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 $array, string $key, $value): array
/**
 * Collapse an array of arrays into a single array.
 *
 * @param  iterable  $array
 *
 * @return array
 */
function array_collapse(iterable $array): array
/**
 * Cross join the given arrays, returning all possible permutations.
 *
 * @param  iterable  ...$arrays
 *
 * @return array
 */
function array_cross_join(...$arrays): array
/**
 * Divide an array into two arrays. One with keys and the other with values.
 *
 * @param  array  $array
 *
 * @return array
 */
function array_divide(array $array): array
/**
 * Flatten a multi-dimensional associative array with dots.
 *
 * @param  iterable  $array
 * @param  string  $prepend
 *
 * @return array
 */
function array_dot(iterable $array, string $prepend = ''): array
/**
 * Get all of the given array except for a specified array of keys.
 *
 * @param  array  $array
 * @param  array|string  $keys
 *
 * @return array
 */
function array_except(array $array, $keys): array
/**
 * Determine if the given key exists in the provided array.
 *
 * @param  \ArrayAccess|array  $array
 * @param  string|int  $key
 *
 * @return bool
 */
function array_exists($array, $key): bool
/**
 * Return the first element in an array passing a given truth test.
 *
 * @param  iterable  $array
 * @param  callable|null  $callback
 * @param  mixed  $default
 *
 * @return mixed
 */
function array_first(iterable $array, callable $callback = null, $default = null)
/**
 * Return the last element in an array passing a given truth test.
 *
 * @param  array  $array
 * @param  callable|null  $callback
 * @param  mixed  $default
 *
 * @return mixed
 */
function array_last(array $array, callable $callback = null, $default = null)
/**
 * Flatten a multi-dimensional array into a single level.
 *
 * @param  iterable  $array
 * @param  int  $depth
 *
 * @return array
 */
function array_flatten(iterable $array, int $depth): array
/**
 * 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 &$array, $keys)
/**
 * Get an item from an array using "dot" notation.
 *
 * @param  \ArrayAccess|array  $array
 * @param  string|int|null  $key
 * @param  mixed  $default
 *
 * @return mixed
 */
function array_get($array, $key, $default = null)
/**
 * Check if an item or items exist in an array using "dot" notation.
 *
 * @param  \ArrayAccess|array  $array
 * @param  string|array  $keys
 *
 * @return bool
 */
function array_has($array, $keys): bool
 /**
 * Determine if any of the keys exist in an array using "dot" notation.
 *
 * @param  \ArrayAccess|array  $array
 * @param  string|array  $keys
 *
 * @return bool
 */
function array_has_any($array, $keys): bool
/**
 * Determines if an array is associative.
 *
 * An array is "associative" if it doesn't have sequential numerical keys beginning with zero.
 *
 * @param  array  $array
 *
 * @return bool
 */
function array_is_assoc(array $array): bool
/**
 * Get a subset of the items from the given array.
 *
 * @param  array  $array
 * @param  array|string  $keys
 *
 * @return array
 */
function array_only(array $array, $keys): array
/**
 * Pluck an array of values from an array.
 *
 * @param  iterable  $array
 * @param  string|array|int|null  $value
 * @param  string|array|null  $key
 *
 * @return array
 */
function array_pluck(iterable $array, $value, $key = null): array
/**
 * Push an item onto the beginning of an array.
 *
 * @param  array  $array
 * @param  mixed  $value
 * @param  mixed  $key
 *
 * @return array
 */
function array_prepend(array $array, $value, $key = null): array
/**
 * Get a value from the array, and remove it.
 *
 * @param  array  $array
 * @param  string  $key
 * @param  mixed  $default
 *
 * @return mixed
 */
function array_pull(array &$array, string $key, $default = null)
/**
 * Convert the array into a query string.
 *
 * @param  array  $array
 *
 * @return string
 */
function array_query(array $array): string
/**
 * Get one or a specified number of random values from an array.
 *
 * @param  array  $array
 * @param  int|null  $number
 * @param  bool|false  $preserveKeys
 *
 * @return mixed
 *
 * @throws \InvalidArgumentException
 */
function array_random(array $array, int $number = null, bool $preserveKeys)
/**
 * 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|null  $key
 * @param  mixed  $value
 *
 * @return array
 */
function array_set(array &$array, ?string $key, $value): array
 /**
 * Shuffle the given array and return the result.
 *
 * @param  array  $array
 * @param  int|null  $seed
 *
 * @return array
 */
function array_shuffle(array $array, int $seed = null): array
/**
 * Recursively sort an array by keys and values.
 *
 * @param  array  $array
 * @param  int  $options
 * @param  bool  $descending
 *
 * @return array
 */
function array_sort_recursive(array $array, int $options = SORT_REGULAR, bool $descending): array
/**
 * Conditionally compile classes from an array into a CSS class list.
 *
 * @param  array  $array
 *
 * @return string
 */
function array_to_css_classes(array $array): string
/**
 * Filter the array using the given callback.
 *
 * @param  array  $array
 * @param  callable  $callback
 *
 * @return array
 */
function array_where(array $array, callable $callback): array
/**
 * If the given value is not an array and not null, wrap it in one.
 *
 * @param  mixed  $value
 *
 * @return array
 */
function array_wrap($value): array
/**
 * 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)
/**
 * Get an item from an array or object using "dot" notation.
 *
 * @param  mixed  $target
 * @param  string|array|int|null  $key
 * @param  mixed  $default
 * @return mixed
 */
function data_get($target, $key, $default = null)
/**
 * 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, bool $overwrite = true)
/**
 * Get the first element of an array. Useful for method chaining.
 *
 * @param  array  $array
 *
 * @return mixed
 */
function head(array $array)
/**
 * Get the last element from an array.
 *
 * @param  array  $array
 *
 * @return mixed
 */
function last(array $array)
/**
 * 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_array(string $pattern, array $replacements, string $subject): string
/**
 * Return the remainder of a string after the first occurrence of a given value.
 *
 * @param  string  $subject
 * @param  string  $search
 *
 * @return string
 */
function str_after(string $subject, string $search): string
/**
 * Return the remainder of a string after the last occurrence of a given value.
 *
 * @param  string  $subject
 * @param  string  $search
 *
 * @return string
 */
function str_after_last(string $subject, string $search): string
/**
 * Get the portion of a string before the first occurrence of a given value.
 *
 * @param  string  $subject
 * @param  string  $search
 *
 * @return string
 */
function str_before(string $subject, string $search): string
/**
 * Get the portion of a string before the last occurrence of a given value.
 *
 * @param  string  $subject
 * @param  string  $search
 *
 * @return string
 */
function str_before_last(string $subject, string $search): string
/**
 * Get the portion of a string between two given values.
 *
 * @param  string  $subject
 * @param  string  $from
 * @param  string  $to
 *
 * @return string
 */
function str_between(string $subject, string $from, string $to): string
 /**
 * Determine if a given string contains a given substring.
 *
 * @param  string  $haystack
 * @param  string|string[]  $needles
 *
 * @return bool
 */
function str_contains(string $haystack, $needles): bool
/**
 * Determine if a given string contains all array values.
 *
 * @param  string  $haystack
 * @param  string[]  $needles
 *
 * @return bool
 */
function str_contains_all(string $haystack, array $needles): bool
/**
 * Determine if a given string ends with a given substring.
 *
 * @param  string  $haystack
 * @param  string|string[]  $needles
 *
 * @return bool
 */
function str_ends_with(string $haystack, $needles): bool
/**
 * Cap a string with a single instance of a given value.
 *
 * @param  string  $value
 * @param  string  $cap
 *
 * @return string
 */
function str_finish(string $value, string $cap): string
/**
 * Determine if a given string matches a given pattern.
 *
 * @param  string|array  $pattern
 * @param  string  $value
 *
 * @return bool
 */
function str_is($pattern, string $value): bool
/**
 * Determine if a given string is a valid UUID.
 *
 * @param  string  $value
 *
 * @return bool
 */
function str_is_uuid(string $value): bool
/**
 * Convert a string to kebab case.
 *
 * @param  string  $value
 *
 * @return string
 */
function str_kebab(string $value): string
/**
 * Return the length of the given string.
 *
 * @param  string  $value
 * @param  string|null  $encoding
 *
 * @return int
 */
function str_length(string $value, string $encoding = null): int
/**
 * Limit the number of characters in a string.
 *
 * @param  string  $value
 * @param  int  $limit
 * @param  string  $end
 *
 * @return string
 */
function str_limit(string $value, int $limit = 100, string $end = '...'): string
/**
 * Convert the given string to lower-case.
 *
 * @param  string  $value
 *
 * @return string
 */
function str_lower(string $value): string
/**
 * Limit the number of words in a string.
 *
 * @param  string  $value
 * @param  int  $words
 * @param  string  $end
 *
 * @return string
 */
function str_words(string $value, int $words = 100, string $end = '...'): string
/**
 * Get the string matching the given pattern.
 *
 * @param  string  $pattern
 * @param  string  $subject
 *
 * @return string
 */
function str_match(string $pattern, string $subject): string
/**
 * Pad both sides of a string with another.
 *
 * @param  string  $value
 * @param  int  $length
 * @param  string  $pad
 *
 * @return string
 */
function str_pad_both(string $value, int $length, string $pad = ' '): string
/**
 * Pad the left side of a string with another.
 *
 * @param  string  $value
 * @param  int  $length
 * @param  string  $pad
 *
 * @return string
 */
function str_pad_left(string $value, int $length, string $pad = ' '): string
/**
 * Pad the right side of a string with another.
 *
 * @param  string  $value
 * @param  int  $length
 * @param  string  $pad
 *
 * @return string
 */
function str_pad_right(string $value, int $length, string $pad = ' '): string
/**
 * Generate a more truly "random" alpha-numeric string.
 *
 * @param  int  $length
 *
 * @return string
 */
function str_random(int $length = 16): string
/**
 * Replace a given value in the string sequentially with an array.
 *
 * @param  string  $search
 * @param  array<int|string, string>  $replace
 * @param  string  $subject
 *
 * @return string
 */
function str_replace_array(string $search, array $replace, string $subject): string
/**
 * Replace the first occurrence of a given value in the string.
 *
 * @param  string  $search
 * @param  string  $replace
 * @param  string  $subject
 *
 * @return string
 */
function str_replace_first(string $search, string $replace, string $subject): string
/**
 * Replace the last occurrence of a given value in the string.
 *
 * @param  string  $search
 * @param  string  $replace
 * @param  string  $subject
 *
 * @return string
 */
function str_replace_last(string $search, string $replace, string $subject): string
/**
 * Remove any occurrence of the given string in the subject.
 *
 * @param  string|array<string>  $search
 * @param  string  $subject
 * @param  bool  $caseSensitive
 *
 * @return string
 */
function str_remove($search, string $subject, bool $caseSensitive = true): string
/**
 * Begin a string with a single instance of a given value.
 *
 * @param  string  $value
 * @param  string  $prefix
 *
 * @return string
 */
function str_start(string $value, string $prefix): string
/**
 * Convert the given string to upper-case.
 *
 * @param  string  $value
 *
 * @return string
 */
function str_upper(string $value): string
/**
 * Convert the given string to title case.
 *
 * @param  string  $value
 *
 * @return string
 */
function str_title(string $value): string
/**
 * Convert a string to snake case.
 *
 * @param  string  $value
 * @param  string  $delimiter
 *
 * @return string
 */
function str_snake(string $value, string $delimiter = '_'): string
/**
 * Determine if a given string starts with a given substring.
 *
 * @param  string  $haystack
 * @param  string|string[]  $needles
 *
 * @return bool
 */
function str_starts_with(string $haystack, $needles): bool
 /**
 * Convert a value to studly caps case.
 *
 * @param  string  $value
 *
 * @return string
 */
function str_studly(string $value): string
/**
 * Get the class "basename" of the given object / class.
 *
 * @param  string|object  $class
 * @return string
 */
function class_basename($class): string
/**
 * Returns all traits used by a class, its parent classes and trait of their traits.
 *
 * @param  object|string  $class
 * @return array
 */
function class_uses_recursive($class): array
/**
 * Returns all traits used by a trait and its traits.
 *
 * @param  string  $trait
 * @return array
 */
function trait_uses_recursive($trait): array
/**
 * Dump the passed variables and end the script.
 *
 * @param  mixed
 * @return void
 */
function dd()
/**
 * Escape HTML entities in a string.
 *
 * @param  string  $value
 *
 * @return string
 */
function e(string $value): string
 /**
 * Get an item from an object using "dot" notation.
 *
 * @param  object  $object
 * @param  string  $key
 * @param  mixed $default
 *
 * @return mixed
 */
function object_get(object $object, string $key, $default = null)
/**
 * Call the given Closure with the given value then return the value.
 *
 * @param  mixed $value
 * @param  callable  $callback
 *
 * @return mixed
 */
function tap($value, callable $callback)
/**
 * Return the default value of the given value.
 *
 * @param  mixed $value
 * @return mixed
 */
function value($value)
/**
 * Return the given object. Useful for chaining.
 *
 * @param  mixed $object
 * @return mixed
 */
function with($object)

Since the Laravel framework is open-sourced software licensed under the MIT license, this project is licensed under the same license.