Giter VIP home page Giter VIP logo

chain's Introduction

Build Status Minimum PHP Version Dependency Status

About

This is a simple library that makes it easier to chain actions/processors. Useful for any kind of data processing with reusable pieces of code in a specific order.

The library is inspired with Chain of Responsibility design pattern and middleware-like approach where one middleware executes its logic and, conditionally, runs next middleware.

How do I install it?

composer require bartosz-maciaszek/chain

How do I use it?

In three simple steps:

  1. Create a context class that implements BM\Chain\ChainContextInterface.
  2. Create an instance of BM\Chain\ProcessorsQueue and register processor with it.
  3. Execute the chain by invoking execute() method and passing the context object.

What is the context class?

This is a class that stores some information and is being passed to each of the registered processor. Context can contain some initial input data of any type. Processors are meant to use that data during execution. Obviously, they can always store anything in the context. You're in charge here.

What are the processors?

Processors are callable's that contain some logic to be executed. They can be closures or classes implementing __invoke method. The processors always take two arguments: context and next processor in the queue. They are responsible for execution of next one, otherwise the chain breaks.

What is the processor queue?

Processor queue is an object that aggregates processors in the given order. It exposes methods that allow managing processors.

What is the chain?

Chain is a class that is responsible for execution of the processor queue and passing the context object to them.

Any examples?

Have a look here.

chain's People

Contributors

bartosz-maciaszek avatar

Watchers

James Cloos 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.