Facades
3 weeks ago
Traits
3 weeks ago
Arr.php
3 weeks ago
DataCaster.php
3 weeks ago
Flex.php
3 weeks ago
HigherOrderTapProxy.php
3 weeks ago
MediaAttachment.php
3 weeks ago
MessagesBag.php
3 weeks ago
Str.php
3 weeks ago
Url.php
3 weeks ago
Utils.php
3 weeks ago
HigherOrderTapProxy.php
54 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Proxy that invokes methods on a target object and always returns the target for chaining. |
| 5 | * Powers the tap helper pattern where side-effect calls should not break fluent pipelines. |
| 6 | * Delegates __call to the wrapped instance. |
| 7 | * |
| 8 | * @package Framework |
| 9 | * @subpackage Supports |
| 10 | * @since 1.0.0 |
| 11 | */ |
| 12 | namespace Kirki\Framework\Supports; |
| 13 | |
| 14 | \defined('ABSPATH') || exit; |
| 15 | class HigherOrderTapProxy |
| 16 | { |
| 17 | /** |
| 18 | * The target instance. |
| 19 | * |
| 20 | * @var object |
| 21 | * |
| 22 | * @since 1.0.0 |
| 23 | */ |
| 24 | protected $target; |
| 25 | /** |
| 26 | * Create a new proxy instance. |
| 27 | * |
| 28 | * @param mixed $target The target. |
| 29 | * |
| 30 | * @return void |
| 31 | * |
| 32 | * @since 1.0.0 |
| 33 | */ |
| 34 | public function __construct($target) |
| 35 | { |
| 36 | $this->target = $target; |
| 37 | } |
| 38 | /** |
| 39 | * Dynamically handle calls to the object. |
| 40 | * |
| 41 | * @param mixed $method The method name. |
| 42 | * @param mixed $parameters The parameters array. |
| 43 | * |
| 44 | * @return mixed |
| 45 | * |
| 46 | * @since 1.0.0 |
| 47 | */ |
| 48 | public function __call($method, $parameters) |
| 49 | { |
| 50 | $this->target->{$method}(...$parameters); |
| 51 | return $this->target; |
| 52 | } |
| 53 | } |
| 54 |