-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows you to pass a single argument into tap, then call any method on that object, and return the object itself. I’ve found this primarily useful around Eloquent methods that I want to return $this…. For example: return tap($model)->update([‘foo’ => ‘bar’]);
- Loading branch information
1 parent
ac03097
commit 3abc4fb
Showing
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters