chiroruxx/php-scope-function

Scope functions for PHP.

0.1 2021-09-27 07:04 UTC

This package is auto-updated.

Last update: 2025-05-27 15:44:43 UTC


README

Installation

composer require chiroruxx/php-scope-function

Usage

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 ?? '';

also

$user->also(function (User $it): void {
    $it->created_at = new DateTime();
    $it->updated_at = new DateTime();
})
    ->save();