1<?php 2 3namespace DeepCopy\TypeFilter; 4 5/** 6 * @final 7 */ 8class ReplaceFilter implements TypeFilter 9{ 10 /** 11 * @var callable 12 */ 13 protected $callback; 14 15 /** 16 * @param callable $callable Will be called to get the new value for each element to replace 17 */ 18 public function __construct(callable $callable) 19 { 20 $this->callback = $callable; 21 } 22 23 /** 24 * {@inheritdoc} 25 */ 26 public function apply($element) 27 { 28 return call_user_func($this->callback, $element); 29 } 30} 31