HigherOrderTapProxy.php 864 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Utils;
  12. class HigherOrderTapProxy
  13. {
  14. /**
  15. * The target being tapped.
  16. *
  17. * @var mixed
  18. */
  19. public $target;
  20. /**
  21. * Create a new tap proxy instance.
  22. *
  23. * @param mixed $target
  24. */
  25. public function __construct($target)
  26. {
  27. $this->target = $target;
  28. }
  29. /**
  30. * Dynamically pass method calls to the target.
  31. *
  32. * @param string $method
  33. * @param array $parameters
  34. * @return mixed
  35. */
  36. public function __call($method, $parameters)
  37. {
  38. $this->target->{$method}(...$parameters);
  39. return $this->target;
  40. }
  41. }