HigherOrderTapProxy.php 909 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\Tappable;
  12. /**
  13. * @template TValue
  14. */
  15. class HigherOrderTapProxy
  16. {
  17. /**
  18. * The target being tapped.
  19. *
  20. * @var TValue
  21. */
  22. public $target;
  23. /**
  24. * Create a new tap proxy instance.
  25. *
  26. * @param TValue of object $target
  27. */
  28. public function __construct($target)
  29. {
  30. $this->target = $target;
  31. }
  32. /**
  33. * Dynamically pass method calls to the target.
  34. *
  35. * @param string $method
  36. * @param array $parameters
  37. * @return TValue
  38. */
  39. public function __call($method, $parameters)
  40. {
  41. $this->target->{$method}(...$parameters);
  42. return $this->target;
  43. }
  44. }