mobileka/mosaiq-helpers

This package is abandoned and no longer maintained. No replacement package was suggested.

A set of useful classes for PHP developers

dev-master 2014-08-04 17:03 UTC

This package is not auto-updated.

Last update: 2018-05-08 17:23:35 UTC


README

Build Status Code Climate Coverage Status

This repository is created to collect simple libraries implementing some commonly needed functionality.

All the classes follow PSR-2, covered with unit tests, provide Laravel service providers and contain comments above every single method.

If comments are not clear, I recommend to look through the tests directory to explore usage examples.

Requirements:

PHP >= 5.4.*

Some examples:

A very common case when you need to do something like this:

if (isset($arr['key']) {
    $result = $arr['key'];
} else {
    $result = 'default';
}

// another way to write the same thing
$result = isset($arr['key']) ? $arr['key'] : 'default';

With MosaiqArray class you can do the same thing more elegantly:

$result = MosaiqArray::make($arr)->getItem('key', 'default');
//or
$ma = new MosaiqArray($arr);
$result = $ma->getItem('key', 'default');

MosaiqArray class implements ArrayAccess, IteratorAggregate, Countable and Serializable interfaces, so you can access an instance of this class as an array, iterate over it, count elements, serialize and unserialize it:

$numbers = new MosaiqArray([1, 2, 3]);

echo $numbers[0]; //1

foreach ($numbers as $number) {
    // do something
}

echo $count($numbers); // 3

serialize($numbers);
unserialize($numbers);

License

Mosaiq Helpers are open-source and licensed under the MIT License