adrianschubek / with
Adds with() functionality
1.0
2020-07-18 14:21 UTC
Requires
- php: >=7.4
This package is auto-updated.
Last update: 2025-02-21 06:34:08 UTC
README
function with($val, callable $callback = null) : $val | WithProxy
Passes $val
through $callback
and returns $val
.
Returns a WithProxy
instead if $callback
= null.
Installation
composer require adrianschubek/with
Example
Using Arrow function/Closure
$user = with(UserRepository::findById(123), function (User $us) { $us->setBalance(10); $us->sendConfirmation(); });
$deletedUser = with(UserRepository::findById(123), fn(User $user) => $user->deleteAccount());
Using Proxy
// sendWelcomeMail() is a method of User. $randomUser = with(UserRepository::createRandomUser())->sendWelcomeMail();