next(...)` * at the end of the `format()` method. */ abstract class Formatter implements FormatterInterface { /** * @var Formatter|null */ protected $next; /** * {@inheritdoc} */ public abstract function format(array $record); /** * {@inheritdoc} */ public function formatBatch(array $records) { foreach ($records as $key => $record) { $records[$key] = $this->format($record); } return $records; } /** * Chain of responsibility pattern. * * @param Formatter $formatter */ public function setNext(Formatter $formatter) { $this->next = $formatter; } protected function next(array $record) { if (! $this->next) { return $record; } return $this->next->format($record); } }