extend(function($output, $input, $map) { * $output['example'] = $input->example; * return $output; * }) * */ public function extend(callable $cb): self { $this->extensions[] = $cb; return $this; } /** * Run extensions applied to this map * * Run the callback functions registered with extend. * * @param mixed $output The output the object is being mapped to * @param mixed $input The object that is being mapped from */ protected function withExtensions($output, $input) { foreach ($this->extensions as $extension) { $output = call_user_func($extension, $output, $input, $this); } return $output; } }