chiroruxx / php-scope-function
PHP 的作用域函数。
0.1
2021-09-27 07:04 UTC
Requires (Dev)
- phpunit/phpunit: ^9.5.10
This package is auto-updated.
Last update: 2024-09-27 14:12:59 UTC
README
安装
composer require chiroruxx/php-scope-function
使用
class User { use \Chiroruxx\ScopeFunction\ScopeFunction; // ... }
let
$user = User::find($id); $json = $user?->let(function (User $it): string { $formatter = new UserFormatter(); return $formatter->formatToJson($it); }); return $json ?? '';
也
$user->also(function (User $it): void { $it->created_at = new DateTime(); $it->updated_at = new DateTime(); }) ->save();