avonnadozie/liteonion

Maintainers

👁 avonnadozie

Package info

github.com/AVONnadozie/liteonion

pkg:composer/avonnadozie/liteonion

Statistics

Installs: 307

Dependents: 1

Suggesters: 0

Stars: 1

2.0.0 2018-09-06 00:20 UTC

Requires

None

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT a75d0dbb2f7a0dd7d27c47c7e1df1673fffb0213

This package is not auto-updated.

Last update: 2026-06-16 09:02:31 UTC


README

Installation

composer require avonnadozie/liteonion

Usage

class BeforeLayer implements LayerInterface {

 public function peel($object, Closure $next)
 {
 $object->runs[] = 'before';

 return $next($object);
 }

}

class AfterLayer implements LayerInterface {

 public function peel($object, Closure $next)
 {
 $response = $next($object);

 $object->runs[] = 'after';

 return $response;
 }

}

$object = new StdClass;
$object->runs = [];

$onion = new Onion;
$end = $onion->layer([
 new AfterLayer(),
 new BeforeLayer(),
 new AfterLayer(),
 new BeforeLayer()
 ])
 ->peel($object, function($object){
 $object->runs[] = 'core';
 return $object;
 });

var_dump($end);

Will output

..object(stdClass)#161 (1) {
 ["runs"]=>
 array(5) {
 [0]=>
 string(6) "before"
 [1]=>
 string(6) "before"
 [2]=>
 string(4) "core"
 [3]=>
 string(5) "after"
 [4]=>
 string(5) "after"
 }
}