adrianschubek / with
Adds with() functionality
Installs: 10
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/adrianschubek/with
Requires
- php: >=7.4
This package is auto-updated.
Last update: 2025-10-21 08:04:30 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();