guglielmopepe / rings
用于管道、宏和中间件的软件包
2.0.1
2023-03-31 07:58 UTC
Requires
- php: ^7.2.0 || ^8.0.0
README
Rings 允许您创建和调度顺序、可装饰、可过滤和/或可组合的管道。
目录
优点
- 高度可组合。
- 不可变。
功能
Rings 以不可变链的形式实现。当您入队一个新的装饰器时,将创建一个新的阶段,并添加该装饰器。
您可以入队添加功能到管道的装饰器。您可以入队过滤数据上要执行的操作的装饰器。您可以入队添加子管道的装饰器。
这使得管道易于重用,高度可组合,并最小化了副作用。
先决条件
- PHP 7.2.0
是的,这是唯一的硬性要求。
安装
使用 Composer
$ composer require guglielmopepe/rings
使用
// create pipeline $pipeline = new \Rings\Classes\Pipeline(new \SplQueue()); // add decorators: $pipeline->addDecorator(new \Rings\Classes\Decorator(function (\Rings\Interfaces\Data $data) {echo 'Stage 1 <br />';return $data;})); $pipeline->addDecorator(new \Rings\Classes\Decorator(function (\Rings\Interfaces\Data $data) {echo 'Stage 2 <br />';return $data;})); $pipeline->addDecorator(new \Rings\Classes\Decorator(function (\Rings\Interfaces\Data $data) {echo 'Stage 3 <br />';return $data;})); // execute command $data = $pipeline->execute(new \Rings\Classes\Data([]));
文档
像宏一样创建管道
// create pipeline $pipeline = new \Rings\Classes\Pipeline(new \SplQueue()); // add decorators: $pipeline->addDecorator(new \Rings\Classes\Decorator( function (\Rings\Interfaces\Data $data) { return new \Rings\Classes\Data(['foo' => '***' . $data['foo'] . '***']); }) ); $pipeline->addDecorator(new \Rings\Classes\Decorator( function (\Rings\Interfaces\Data $data) { return new \Rings\Classes\Data(['foo' => '___' . $data['foo'] . '___']); }) ); // execute command $data = $pipeline->execute(new \Rings\Classes\Data(['foo' => 'bar'])); // print ___***bar***___ echo $data['foo'];
使用过滤器创建管道
// create pipeline $pipeline = new \Rings\Classes\Pipeline(new \SplQueue()); // add decorators: $pipeline->addDecorator(new \Rings\Classes\Decorator( function (\Rings\Interfaces\Data $data) { if (strpos($data['foo'], '***') !== FALSE) { return $data; } return new \Rings\Classes\Data(['foo' => '***' . $data['foo'] . '***']); }) ); $pipeline->addDecorator(new \Rings\Classes\Decorator( function (\Rings\Interfaces\Data $data) { if (strpos($data['foo'], '___') !== FALSE) { return $data; } return new \Rings\Classes\Data(['foo' => '___' . $data['foo'] . '___']); }) ); // execute command $data = $pipeline->execute(new \Rings\Classes\Data(['foo' => 'bar'])); // print ___***bar***___ echo $data['foo']; // execute command $data = $pipeline->execute(new \Rings\Classes\Data(['foo' => '***bar***'])); // print ***bar*** echo $data['foo']; // execute command $data = $pipeline->execute(new \Rings\Classes\Data(['foo' => '___bar___'])); // print ***bar*** echo $data['foo'];
支持
如果您有请求,请创建 GitHub 问题。
如果您发现安全漏洞,请将电子邮件发送至 Guglielmo Pepe(info@guglielmopepe.com)。所有安全漏洞都将得到及时处理。
常见问题解答
待办事项
贡献
如果您想表示感谢或/和支持 Rings 的积极开发
- 向项目添加 GitHub 星标。
- 在社交媒体上分享项目。
- 在 Medium、Dev.to 或个人博客上撰写评论或教程。
联系方式
如果您需要信息,请发送电子邮件至 info@guglielmopepe.com。
路线图
查看 开放问题 列表
变更日志
有关最近更改的更多信息,请参阅 变更日志文件。
许可
在 MIT 许可下分发。有关更多信息,请参阅 许可文件。