Defining prototypes methods

Prototype methods can be defined using a global configuration; through the prototype property
of an Object instance; or using the Prototype instance associated with classes using
the PrototypeTrait trait.

Defining prototypes methods using a global configuration

All prototypes can be configured using a single global configuration. For each class you can
define the methods that the prototype implements.

The following example demonstrate how the meow() method is defined for instances of the Cat
and FierceCat classes. Although they are defined using closure in the example, methods can be
defined using any callable such as "Website\Hooks::cat_meow".

As mentioned before, façade properties are also exported. The to_array() method should be
overrode to alter this behavior.

Additionally the to_array_recursive() method can be used to recursively convert an instance
into an array, in which case all the instances of the tree implementing ToArray
or ToArrayRecursive are converted into arrays.

Getting a JSON representation of an object

The to_json() method can be used to get a JSON representation of an object. The method is
really straight forward, it invokes to_array_recursive() and pass the result to
json_encode().

<?php
echo $a->to_json(); // {"a":"a","c":"c"}

Creating an instance from an array of properties

The Object::from() method creates an instance from an array of properties:

Instances are created in the same fashion PDO
creates instances when fetching objects using the FETCH_CLASS mode, that is the properties
of the instance are set before its constructor is invoked.

Object sub-classes might want to override the Object::from method to allow creating
instances from different kind of sources, just like the Operation::from method creates an
Operation instance from a Request:

Installation

Cloning the repository

The package is available on GitHub, its repository can
be cloned with the following command line:

$ git clone https://github.com/ICanBoogie/Prototype.git

Documentation

The package is documented as part of the ICanBoogie framework
documentation. You can generate the documentation for the package
and its dependencies with the make doc command. The documentation is generated in the docs
directory. ApiGen is required. The directory can later by cleaned with
the make clean command.

Testing

The test suite is ran with the make test command. Composer is
automatically installed as well as all the dependencies required to run the suite.
The directory can later be cleaned with the make clean command.