Search by

ah-b / oil

ahbaqdadi

flexible package for manage complex domain logic

0.1 2019-05-31 12:18 UTC

README

  • PHP 8.3 or later for the current development branch

Installation

composer require ah-b/oil "0.1"

Development

Install dependencies and run the test suite:

composer install
composer test

Usage

$pipelineService = new OilService(new Pipeline());

$pipelineService->add(new Test());

$pipelineService->run('my payload');

Stages are consumed by the next run() call. They are cleared whether the run returns successfully or throws, so add the stages again for each execution.

class Test
{
    public function __invoke($payload)
    {
        return $payload;
    }
}

mediate

$pipelineService = new OilService(new Mediator());

$pipelineService->add(function($payload){ echo $payload; });

$pipelineService->run('my payload');

Scenario

    public function indexController()
    {
    
        $databaseRecord = "test";
        
        if($databaseRecord == "test")
        {
            // do some logic
        
        }
        
        if($databaseRecord == "foo")
        {
            // do some logic
        
        }        
        
        if($databaseRecord == "bar")
        {
            // do some logic
        
        }  
        
        
        ...
    
    }
    public function indexController()
    {
    
        $databaseRecord = "test";
        
        $pipelineService = new OilService(new Pipeline());
        
        $pipelineService->add(new Test());
        
        $pipelineService->add(new Foo());
        
        $pipelineService->add(new Bar());
        
        $pipelineService->run($databaseRecord);
        
        ...
    
    }