master

laravel/framework

Last updated at: 29/12/2023 09:25

HigherOrderTapProxy.php

TLDR

This file defines a class called HigherOrderTapProxy in the Illuminate\Support namespace. The class allows for method calls to be dynamically passed to its target.

Classes

HigherOrderTapProxy

The HigherOrderTapProxy class is used to create a tap proxy instance. It has the following properties and methods:

Properties

  • $target: The target being tapped.

Methods

  • __construct($target): Constructs a new tap proxy instance with the given target.
  • __call($method, $parameters): Dynamically passes method calls to the target. The method name and parameters are taken as arguments. The method call is then made on the target using the given method name and parameters. The target is then returned.
<?php

namespace Illuminate\Support;

class HigherOrderTapProxy
{
    /**
     * The target being tapped.
     *
     * @var mixed
     */
    public $target;

    /**
     * Create a new tap proxy instance.
     *
     * @param  mixed  $target
     * @return void
     */
    public function __construct($target)
    {
        $this->target = $target;
    }

    /**
     * Dynamically pass method calls to the target.
     *
     * @param  string  $method
     * @param  array  $parameters
     * @return mixed
     */
    public function __call($method, $parameters)
    {
        $this->target->{$method}(...$parameters);

        return $this->target;
    }
}