2017 © Pedro Peláez
 

library laravel-helpers

Laravel Helpers for Non-Laravel Projects

image

kun391/laravel-helpers

Laravel Helpers for Non-Laravel Projects

  • Thursday, April 20, 2017
  • by kun391
  • Repository
  • 1 Watchers
  • 1 Stars
  • 4,352 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 46 Forks
  • 0 Open issues
  • 2 Versions
  • 26 % Grown

The README.md

Laravel 5 Helpers for Non-Laravel Projects

This project takes the useful Laravel helper functions and allows you to use them in Non-Laravel projects., (*1)

All dependencies have been extracted out to a single helpers file. No need to import half of Symphony and Laravel to make these work., (*2)

Setup

In the require key of composer.json file add the following, (*3)

"rappasoft/laravel-helpers": "dev-master"

Documentation

, (*4)

Arrays

, (*5)

append_config

/**
     * Assign high numeric IDs to a config item to force appending.
     *
     * @param  array  $array
     * @return array
*/
function append_config(array $array)

, (*6)

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)

, (*7)

array_build

/**
     * Build a new array using a callback.
     *
     * @param  array     $array
     * @param  \Closure  $callback
     * @return array
*/
function array_build($array, Closure $callback)

, (*8)

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)

, (*9)

array_dot

/**
     * Flatten a multi-dimensional associative array with dots.
     *
     * @param  array   $array
     * @param  string  $prepend
     * @return array
*/
function array_dot($array, $prepend = '')

, (*10)

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)

, (*11)

array_fetch

/**
     * Fetch a flattened array of a nested array element.
     *
     * @param  array   $array
     * @param  string  $key
     * @return array
*/
function array_fetch($array, $key)

, (*12)

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)

, (*13)

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)

, (*14)

array_flatten

/**
     * Flatten a multi-dimensional array into a single level.
     *
     * @param  array  $array
     * @return array
*/
function array_flatten($array)

, (*15)

array_forgot

/**
     * 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)

, (*16)

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)

, (*17)

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)

, (*18)

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)

, (*19)

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)

, (*20)

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)

, (*21)

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)

, (*22)

array_where

/**
     * Filter the array using the given Closure.
     *
     * @param  array     $array
     * @param  \Closure  $callback
     * @return array
*/
function array_where($array, Closure $callback)

, (*23)

/**
     * Get the first element of an array. Useful for method chaining.
     *
     * @param  array  $array
     * @return mixed
*/
function head($array)

, (*24)

last

/**
     * Get the last element from an array.
     *
     * @param  array  $array
     * @return mixed
*/
function last($array)

, (*25)

Strings

, (*26)

ascii

/**
     * Transliterate a UTF-8 value to ASCII.
     *
     * @param  string  $value
     * @return string
 */
function ascii($value)

, (*27)

camel_case

/**
     * Convert a value to camel case.
     *
     * @param  string  $value
     * @return string
*/
function camel_case($value)

, (*28)

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()

, (*29)

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)

, (*30)

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)

, (*31)

snake_case

/**
     * Convert a string to snake case.
     *
     * @param  string  $value
     * @param  string  $delimiter
     * @return string
*/
function snake_case($value, $delimiter = '_')

, (*32)

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)

, (*33)

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)

, (*34)

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)

, (*35)

str_is

/**
     * Determine if a given string matches a given pattern.
     *
     * @param  string  $pattern
     * @param  string  $value
     * @return bool
*/
function str_is($pattern, $value)

, (*36)

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 = '...')

, (*37)

str_random

/**
     * Generate a more truly "random" alpha-numeric string.
     *
     * @param  int  $length
     * @return string
     *
     * @throws \RuntimeException
*/
function str_random($length = 16)

, (*38)

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)

, (*39)

str_slug

/**
     * Generate a URL friendly "slug" from a given string.
     *
     * @param  string  $title
     * @param  string  $separator
     * @return string
*/
function str_slug(string $title, string $separator = '-')

, (*40)

studly_case

/**
     * Convert a value to studly caps case.
     *
     * @param  string  $value
     * @return string
*/
function studly_case($value)

, (*41)

Classes

, (*42)

class_basename

/**
     * Get the class "basename" of the given object / class.
     *
     * @param  string|object  $class
     * @return string
*/
function class_basename($class)

, (*43)

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)

, (*44)

trait_uses_recursive

/**
     * Returns all traits used by a trait and its traits
     *
     * @param  string  $trait
     * @return array
*/
function trait_uses_recursive($trait)

, (*45)

Misc.

, (*46)

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)

, (*47)

e

/**
     * Escape HTML entities in a string.
     *
     * @param  string  $value
     * @return string
*/
function e($value)

, (*48)

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)

, (*49)

value

/**
     * Return the default value of the given value.
     *
     * @param  mixed  $value
     * @return mixed
*/
function value($value)

, (*50)

with

/**
     * Return the given object. Useful for chaining.
     *
     * @param  mixed  $object
     * @return mixed
*/
function with($object)

The Versions

20/04 2017

dev-master

9999999-dev

Laravel Helpers for Non-Laravel Projects

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Anthony Rappa

laravel helpers

19/10 2016

v1.0

1.0.0.0

Laravel Helpers for Non-Laravel Projects

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Anthony Rappa

laravel helpers