Build Status Coverage Status

Consistent object representation of data types. Inheritance friendly implementation. Provides wrapper classes for array, object, string, float, int and bool, plus Queue and Stack collections.

Installation

Install with Composer;

composer require phrity/o

Classes

The package contain the following classes:

Class Reflects Implements
Arr array ArrayAccess Countable Iterator Traversable Comparable Equalable
Obj object Comparable Equalable
Str string Comparable Equalable
Integer int Comparable Equalable
Number float Comparable Equalable
Boolean bool Comparable Equalable
Queue Countable Iterator Traversable Comparable Equalable
Stack Countable Iterator Traversable Comparable Equalable

Examples

Brief examples below. The full documentation. contains more examples.

Scalar types

$str = new Str('hello world');
$str(); // Getter
$str('world'); // Setter

$int = new Integer(1234);
$int(); // Getter
$int(5678); // Setter

$num = new Number(12.34);
$num(); // Getter
$num(56.78); // Setter

$bool = new Boolean(true);
$bool(); // Getter
$bool(false); // Setter

Complex types

$array = new Arr([1, 2, 3]);
$array[] = 7; // ArrayAccess support
count($array); // Countable support
foreach ($array as $key => $value) {} // Iterator support
$array->equals(new Arr([2, 3, 4])); // Comparison support

$object = new Obj(['a' => 1, 'b' => 2, 'c' => 3]);
$object->b = 5; // Property access
$object->equals(new Obj(['c' => 1, 'd' => 2])); // Comparison support

Collection types

$queue = new Queue([1, 2, 3]);
$queue->enqueue(4);
$queue->dequeue();
count($queue); // Countable support
foreach ($queue as $item) {} // Consuming iterator support
$queue->equals(new Queue([2, 3, 4])); // Comparison support

$stack = new Stack([1, 2, 3]);
$stack->push(4);
$stack->pop();
count($stack); // Countable support
foreach ($stack as $item) {} // Consuming iterator support
$stack->equals(new Stack([2, 3, 4])); // Comparison support

Versions

Version PHP
1.3 ^7.1 Queue and Stack collection classes
1.2 ^7.1 Str (string), Number (float), Integer (int) and Boolean (bool) classes
1.1 >=5.6 Comparison support
1.0 >=5.6 Arr (array) and Obj (object) classes