PHP Class Yosymfony\Spress\Core\Support\ArrayWrapper

Based on https://github.com/laravel/framework/blob/5.0/src/Illuminate/Support/Arr.php
Author: Victor Puertas ([email protected])
Mostrar archivo Open project: spress/spress Class Usage Examples

Protected Properties

Property Type Description
$array

Public Methods

Method Description
__construct ( array $array = [] ) Constructor.
add ( $key, $value ) : array Adds an element using "dot" notation if doesn't exists.
flatten ( ) : array Flatten a multi-dimensional array into a single level.
get ( string $key, mixed $default = null ) : mixed Gets a value from a deeply nested array using "dot" notation.
getArray ( ) : array Gets the working array.
has ( string $key ) : boolean Checks if an item exists in using "dot" notation.
paginate ( integer $maxPerPage, integer $initialPage = 1, string $key = null ) : array Paginates the array.
remove ( string $key ) : array Removes an item using "dot" notation.
set ( string $key, mixed $value ) : array Sets an item using "dot" notation.
setArray ( array $array ) : ArrayWrapper Sets the working array.
sort ( string $key = null, callable $callback = null ) : array Sorts the array (ascendant by default).
sortBy ( callable $callback, string $key = null, integer $options = SORT_REGULAR, boolean $isDescending = false ) : array Sort the array sing the given callback.
where ( callable $filter ) : array Filter using the given callback function.

Protected Methods

Method Description
escapedDotKeyToUnderscore ( $key )
underscoreDotKeyToDot ( $key )
unescapeDotKey ( $key )

Method Details

__construct() public method

Constructor.
public __construct ( array $array = [] )
$array array

add() public method

You can to escape a dot in a key surrendering with brackets: "[.]".
public add ( $key, $value ) : array
$key
$value
return array

escapedDotKeyToUnderscore() protected method

protected escapedDotKeyToUnderscore ( $key )

flatten() public method

Flatten a multi-dimensional array into a single level.
public flatten ( ) : array
return array A single level array

get() public method

You can to escape a dot in a key surrendering with brackets: "[.]". e.g: $a->get('site.data') or $a->get('site.pages.index[.]html')
public get ( string $key, mixed $default = null ) : mixed
$key string
$default mixed
return mixed

getArray() public method

Gets the working array.
public getArray ( ) : array
return array

has() public method

You can to escape a dot in a key surrendering with brackets: "[.]".
public has ( string $key ) : boolean
$key string
return boolean

paginate() public method

Paginates the array.
public paginate ( integer $maxPerPage, integer $initialPage = 1, string $key = null ) : array
$maxPerPage integer Max items per page. If this value is minor than 1 the result will be an empty array
$initialPage integer Initial page. Page 1 by default
$key string Element to paginate using "dot" notation
return array A list of pages with an array of elements associated with each page

remove() public method

Removes an item using "dot" notation.
public remove ( string $key ) : array
$key string
return array

set() public method

You can to escape a dot in a key surrendering with brackets: "[.]".
public set ( string $key, mixed $value ) : array
$key string
$value mixed
return array

setArray() public method

Sets the working array.
public setArray ( array $array ) : ArrayWrapper
$array array
return ArrayWrapper This instance

sort() public method

Sorts the array (ascendant by default).
public sort ( string $key = null, callable $callback = null ) : array
$key string Element to sort using "dot" notation. You can to escape a dot in a key surrendering with brackets: "[.]"
$callback callable Callback should be a function with the following signature: ```php function($element1, $element2) { // returns -1, 0 or 1 } ```
return array

sortBy() public method

Sort the array sing the given callback.
public sortBy ( callable $callback, string $key = null, integer $options = SORT_REGULAR, boolean $isDescending = false ) : array
$callback callable Callback should be a function with the following signature: ```php function($key, $value) { // return $processedValue; } ```
$key string Element to sort using "dot" notation. You can to escape a dot in a key surrendering with brackets: "[.]"
$options integer See sort_flags at http://php.net/manual/es/function.sort.php
$isDescending boolean
return array

underscoreDotKeyToDot() protected method

protected underscoreDotKeyToDot ( $key )

unescapeDotKey() protected method

protected unescapeDotKey ( $key )

where() public method

Filter using the given callback function.
public where ( callable $filter ) : array
$filter callable The filter function should be a function with the following signature: ```php function($key, $value) { // returns true if the value is matching your criteria. } ```
return array

Property Details

$array protected_oe property

protected $array