2017 © Pedro Peláez
 

library qub

PHP 5.5+ magic mediator and native state transformation utility

image

jgswift/qub

PHP 5.5+ magic mediator and native state transformation utility

  • Tuesday, April 22, 2014
  • by jgswift
  • Repository
  • 1 Watchers
  • 1 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

qub

PHP 5.5+ magic mediator and native state transformation utility, (*1)

Build Status Scrutinizer Code Quality, (*2)

Installation

Install via composer:, (*3)

php composer.phar require jgswift/qub:dev-master

Description

qub is a relatively simple utility that mediates state machines for any given object, (*4)

qub constitutes a flexible and non-invasive way to associate potentially disparate (well formed) systems, (*5)

qub is conceptually similar to the many-to-many or joint-table pattern found in relational database theory, (*6)

qub adds conceptually barely anything to object-oriented programming in php but has many conceivable applications, (*7)

qub uses 3 transformations to modify state and they are ASK, TELL, and TRANSLATE respectively, (*8)

qub provides 4 drivers to run transformations immediately (run-time) or from stored lists (collections/queues/stacks), (*9)

qub can mediate both object and arrayaccess magic with comparable performance, (*10)

Transformations

Ask - requests state information from mediator, (*11)

Tell - instructs mediator to update it's internal state, (*12)

Translate - requests translated information. should always result in identical output given the same arguments, (*13)

Usage

This is minimal example of a user being asked what it's name is using the run-time state driver, (*14)

<?php
class User {
    function getName() {
        return 'Bob';
    }
}

$system = new qub\System(new qub\Driver\Immediate);

$user = $system->mediate(new User);

$name = $user->getName();

var_dump($name); // returns "Bob"

Following that, here is an expanded example that also tells the user to update it's own internal state, (*15)

<?php
class User {
    private $name;

    function getName() {
        return $this->name;
    }

    function setName($name) {
        $this->name = $name;
    }
}

$system = new qub\System(new qub\Driver\Immediate);

$user = $system->mediate(new User);

$user->setName('Bob');

$name = $user->getName();

var_dump($name); // returns "Bob"

Most patterns can be addressed using qub, for example the view pattern commonly found in Model-View-Controller. This example relies on the TRANSLATE transformation for view rendering and the result should be identical given the same input, (*16)

<?php
class UserView {
    function render(User $user) {
        return '<html>';
    }
}

$system = new qub\System(new qub\Driver\Immediate);

$user = new User;

$view = $system->mediate(new UserView);

$html = $view('render',[$user]);

var_dump($html); // returns "<html>"

Note: TRANSLATE transformations are mediated by default through __invoke magic for both object and array mediators., (*17)

Note: Once PHP adds support for variadic arguments, TRANSLATE magic will be updated accordingly, (*18)

Note: All of the above examples use the run-time driver, please consult the unit tests for implementation details regarding delayed drivers, (*19)

The Versions

22/04 2014

dev-master

9999999-dev

PHP 5.5+ magic mediator and native state transformation utility

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

php magic oop state machine mediator

22/04 2014

0.1.1

0.1.1.0

PHP 5.5+ magic mediator and native state transformation utility

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

php magic oop state machine mediator