terpomoj/pipe

管道操作符替代方案。

v0.1.0 2022-06-09 10:22 UTC

This package is auto-updated.

Last update: 2024-09-09 15:26:26 UTC


README

这是对已驳回的 PHP 管道操作符 RFC 的替代方案。

这个想法最初由 Taylor Otwell 在 Twitter 上提出 。我添加了一些功能,例如直接在管道值上调用函数,并直接访问管道值的属性。

使用示例

基本用法

pipe('test@example.com')
    (md5(...))
    (fn ($md5) => 'https://gravatar.com/avatar/' . $md5)
    ->endpipe;

访问对象属性

pipe('test@example.com')
    (GravatarUrl::make(...))
    ->url // `url` is an attribute of GravatarUrl
    ->endpipe;

调用对象方法

pipe('test@example.com')
    (GravatarUrl::make(...))
    ->size(200) // `size` is a method of GravatarUrl
    ->endpipe;

许可证

MIT 许可证