All methods in this class when attempting to access object properties first try to use getters (their names are built with ::getter) method) and then try to access them as public properties.

Methods This class defines the following methods:

static pluck (array|object $objects, string $key) -> array

Returns an array with a list of all values (not unique) assigned to a key in a collection of objects.

Arguments:
array|object $objects

Collection of objects - either an array or a collection object that implements toArray method.

string $key

Get values of this property.

Returns:
array
Throws:
MD\Foundation\Exceptions\InvalidArgumentException

When the $objects argument is not an array or cannot be converted to an array.

static keyFilter (array|object $objects, string $key) -> array

Deprecated! This method has been deprecated. Do not use it anymore!

Alias for ::pluck().

Arguments:
array|object $objects

Collection of objects - either an array or a collection object that implements toArray method.

string $key

Get values of this property.

Returns:
array

static indexBy (array|object $objects, string $key) -> array

Assigns a value under a key of a collection of objects to its main (top level) key.

Arguments:
array|object $objects

Collection of objects - either an array or a collection object that implements toArray method.

string $key

Key on which to index by.

Returns:
array
Throws:
MD\Foundation\Exceptions\InvalidArgumentException

When the $objects argument is not an array or cannot be converted to an array.

static keyExplode (array|object $objects, string $key) -> array

Deprecated! This method has been deprecated. Do not use it anymore!

Alias for ::indexBy().

Arguments:
array|object $objects

Collection of objects - either an array or a collection object that implements toArray method.

string $key

Key on which to index by.

Returns:
array

static filter (array|object $objects, string $key, mixed $value, bool $preserveKey = false) -> array

Filters out all values from a multidimensional array that contains objects that match the given value of the given associative level 2 key.

Arguments:
array|object $objects

Collection of objects - either an array or a collection object that implements toArray method.

string $key

Key to filter by.

mixed $value

Value to filter by.

bool $preserveKey

[optional] Should the level 1 key be preserved or not? Default: false.

Returns:
array
Throws:
MD\Foundation\Exceptions\InvalidArgumentException

When the $objects argument is not an array or cannot be converted to an array.

static filterByKeyValue (array|object $objects, string $key, mixed $value, bool $preserveKey = false) -> array

Deprecated! This method has been deprecated. Do not use it anymore!

Alias for ::filter().

Arguments:
array|object $objects

Collection of objects - either an array or a collection object that implements toArray method.

string $key

Key to filter by.

mixed $value

Value to filter by.

bool $preserveKey

[optional] Should the level 1 key be preserved or not? Default: false.

Returns:
array

static groupBy (array|object $objects, string $key, bool $preserveKey = false) -> array

Categorize all items from the collection of objects by the value of a specific key.

Arguments:
array|object $objects

Collection of objects - either an array or a collection object that implements toArray method.

string $key

Key to categorize by.

bool $preserveKey

[optional] Preserve keys? Default: false.

Returns:
array
Throws:
MD\Foundation\Exceptions\InvalidArgumentException

When the $objects argument is not an array or cannot be converted to an array.

static categorizeByKey (array|object $objects, string $key, bool $preserveKey = false) -> array

Deprecated! This method has been deprecated. Do not use it anymore!

Alias for ::groupBy().

Arguments:
array|object $objects

Collection of objects - either an array or a collection object that implements toArray method.

string $key

Key to categorize by.

bool $preserveKey

[optional] Preserve keys? Default: false.

Returns:
array

static multiSort (array|object $objects, string $key, bool $reverse = false) -> array

Sorts a collection of object based on the specified key.

Arguments:
array|object $objects

Collection of objects - either an array or a collection object that implements toArray method.

string $key

Key to sort by.

bool $reverse

[optional] true for descending order, false for ascending. Default: false.

Returns:
array
Throws:
MD\Foundation\Exceptions\InvalidArgumentException

When the $objects argument is not an array or cannot be converted to an array.

static resetKeys (array|object $objects) -> array

Resets keys of an array containing a collection of objects to numerical values starting with 0.

Arguments:
array|object $objects

Collection of objects - either an array or a collection object that implements toArray method.

Returns:
array
Throws:
MD\Foundation\Exceptions\InvalidArgumentException

When the $objects argument is not an array or cannot be converted to an array.

static getter (string $property) -> string

Creates a getter name for the given object property name.

Converts snake_notation to camelCase.

Example:

 echo \MD\Foundation\Utils\ObjectUtils::getter('property_name');
 // -> 'getPropertyName'
Arguments:
string $property

Property name.

Returns:
string

static setter (string $property) -> string

Creates a setter name for the given object property name.

Converts snake_notation to camelCase.

Example:

 echo \MD\Foundation\Utils\ObjectUtils::setter('property_name');
 // -> `setPropertyName`
Arguments:
string $property

Property name.

Returns:
string