setContent(str_replace('{img_list}', '', $tplContent->getContent()));
echo $tplContent->getContent(), PHP_EOL;
return $next();
}
}
class Title {
public static function handle($tplContent, Closure $next) {
$tplContent->setContent(str_replace('{title}', 'Test Title', $tplContent->getContent()));
echo $tplContent->getContent(), PHP_EOL;
return $next();
}
}
$parsers = ['ImageList', 'Title'];
class TplContent {
private $tplContent = '{title}
{img_list}';
public function setContent($content) {
$this->tplContent = $content;
}
public function getContent() {
return $this->tplContent;
}
}
$tplContent = new TplContent;
$callback = array_reduce(array_reverse($parsers), function($stack, $pipe) use ($tplContent) {
return function() use ($tplContent, $stack, $pipe) {
return $pipe::handle($tplContent, $stack);
};
}, function() use ($tplContent) {
echo 'real process result: ', $tplContent->getContent(), PHP_EOL;
});
call_user_func($callback);