Giter Site home page Giter Site logo

ameliorate-nexus's Introduction

CircleCI

Ameliorate Nexus

A package to setup a nexus of stops which are processed based on the result of the previous stop.

Note: Passing an object that is already initialized is not supported. That type of functionality should be handled by the container.

Dependencies

A container to resolve class instance such as: https://github.com/illuminate/container

Nexus Contract

Send a traveler (payload) through an array of jobs.

public function send(TravelerContract $traveler);

Set the destinations the traveler (payload) will travel to. Not all destinations will be executed. See "destinations" below.

public function to(array $destinations);

Set the method the destinations should execute.

public function via(string $method);

Set the final destination of the traveler (payload).

public function arrive(Closure $destination);

Destination Contract

Handle the traveler at the destination.

public function handle(TravelerContract $traveler, Closure $next);

Destinations

Each destination should return either true or false. This return value will determine which destination is executed next.

$destinations = [
    Addition::class         => [Nexus::UNINHABITED, Multiplication::class],
    Multiplication::class   => [Subtraction::class, Nexus::UNINHABITED],
    Subtraction::class      => [Nexus::UNINHABITED, Division::class],
    Division::class         => [Nexus::STOP,        Nexus::STOP]
];

Halt processing

Use the constant Nexus::STOP in order for the execution to jump to the final destination.

No job to process

Use the constant Nexus::UNINHABITED to fill the job array in unreachable locations, but the array must be filled.

Usage

$rules = new DestinationRules(false);

$container = new Container();

$nexus = new Nexus($rules, $container);

$traveler = new Math(5); // starts with initial value of 5

/**
 * Destination path is as follows:
 * - start with 5
 * - add 3, then take truthy path
 * - multiply by 6, then take falsy path
 * - subtract 3, then take truthy path
 * - divide 4, then stop
 */
$destinations = [

    // Class to process        // False             // True

    // Container returns new Addition(3) - adds 3
    Addition::class         => [Nexus::UNINHABITED, Multiplication::class],
    
    // Container returns new Multiplication(6, false) - multiplies by 6
    Multiplication::class   => [Subtraction::class, Nexus::UNINHABITED],
    
    // Container returns new Subtraction(2) - subtracts 2
    Subtraction::class      => [Nexus::UNINHABITED, Division::class],
    
    // Container returns new Division(4) - divides by 4
    Division::class         => [Nexus::STOP,        Nexus::STOP]
];

$nexus->send($traveler)
    ->to($destinations)
    ->arrive(function(Math $traveler) {
        Assert::assertEquals(11.5, $traveler->getValue());
    });

Credits

Laravel's pipeline contract for a common API interface.

ameliorate-nexus's People

Contributors

exilesprx avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.