添加 with() 功能

1.0 2020-07-18 14:21 UTC

This package is auto-updated.

Last update: 2024-09-21 05:27:51 UTC


README

Latest Stable Version License

function with($val, callable $callback = null) : $val | WithProxy

$val 传递给 $callback 并返回 $val
如果 $callback = null,则返回一个 WithProxy

安装

composer require adrianschubek/with

示例

使用箭头函数/闭包

$user = with(UserRepository::findById(123), function (User $us) {
    $us->setBalance(10);
    $us->sendConfirmation();
});
$deletedUser = with(UserRepository::findById(123), fn(User $user) => $user->deleteAccount());

使用代理

// sendWelcomeMail() is a method of User.
$randomUser = with(UserRepository::createRandomUser())->sendWelcomeMail();