terpomoj / pipe
管道操作符替代方案。
v0.1.0
2022-06-09 10:22 UTC
Requires
- php: ^8.1
Requires (Dev)
- pestphp/pest: ^1.21
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 许可证