tchwork/closure-caster
Composer 安装命令:
composer require tchwork/closure-caster
包简介
Cast closures to single-method implementations
README 文档
README
This package provides a function named closure_cast_to() that allows
turning a closure into an object implementing a single-method interface.
Imagine you have an interface like this:
interface TranslatorInterface { public function translate(string $message, $parameters = []): string; }
And that the strtr() function is a correct implementation for the identity translator.
You can get an instance of TranslatorInterface delegating to strtr() like this:
$identityTranslator = closure_cast_to(strtr(...), TranslatorInterface::class);
This package is meant as a proof-of-concept implementation of
this RFC
which proposes to add a new castTo method to the native Closure
class so that the previous example could be written like this:
$identityTranslator = strtr(...)->castTo(TranslatorInterface::class);
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-25