dev-master
9999999-devLibrairy for implementing a Flux-like one-direction flow architecture server-side
FreeBSD
The Requires
- php >=5.4.0
- evenement/evenement ~2.0
The Development Requires
by Matthias Jouan
Wallogit.com
2017 © Pedro Peláez
Librairy for implementing a Flux-like one-direction flow architecture server-side
plux is a PHP library created to answer a simple question:, (*2)
Does implementing a Flux-like, one-direction flow architecture server-side make any sense?, (*3)
composer require mattjmattj/plux
Somewhere in the bootstrap of your application/framework you need to call, (*4)
\Plux\Plux::initialize();
Plux will then create a Dispatcher that will have to handle the Actions and pass them to your registerd Stores., (*5)
Stores are like the ones in Flux. They should do the business part according to
an action that is given to them through their handle method. Note that using
the handle method is just a shortcut provided by the StoreTrait, but any
callable can be used with the Dispatcher., (*6)
You must register your Stores to Plux and give them a name :, (*7)
\Plux\Plux::addStore('Foo', new \My\Super\Store\Bar());
The name will allow other parts of your application to call, (*8)
\Plux\Plux::getStore('Foo');
Stores are supposed to emit events whenever they perform an action. Plux depends on evenement/evenement to implement Store events., (*9)
Actions must be created and dispatched to allow registered Stores to do their job. Actions are composed of two elements:, (*10)
After creating an action, you must dispatch it :, (*11)
$action = new \Plux\Action ('type', ['foo' => 'bar']);
\Plux\Plux::getDispatcher()->dispatch($action);
Theoretically everybody can listen to Store events, but to make things easier
Plux provides a Component trait with a single render function. When render
is called the Component should output whatever it needs to. This part is left
very opened and you are not forced to use the Component trait at all., (*12)
A small but complete example of implementation is available here, (*13)
You think that even in a per-request context like in PHP, implementing a one-direction flow architecture is a great idea? You think that it is absurd? Do not hesitate and leave a comment in the dedicated issue, (*14)
plux is released under the FreeBSD License, (*15)
Librairy for implementing a Flux-like one-direction flow architecture server-side
FreeBSD