crojasaragonez / light-service
https://github.com/adomokos/light-service 的 PHP 端口
v1.0.4
2019-03-28 06:15 UTC
Requires
- php: >=7.0.10
Requires (Dev)
- phpunit/phpunit: >=7.0
- squizlabs/php_codesniffer: ^3.0
README
https://github.com/adomokos/light-service 的 PHP 端口
安装
通过 Composer
$ composer require crojasaragonez/light-service
用法
require_once 'vendor/autoload.php'; use crojasaragonez\LightService\Action; use crojasaragonez\LightService\Organizer; class CreateTmpFile extends Action { public $promises = ['file_path']; public function execute() { $this->context['file_path'] = tempnam(sys_get_temp_dir(), 'img_') . '.png'; } } class Download extends Action { public $expects = ['url', 'file_path']; public function execute() { if (!@file_put_contents($this->context['file_path'], file_get_contents($this->context['url']))) { $this->skipRemaining(); } } } class ZipFile extends Action { public $expects = ['file_path']; public $promises = ['zip_path']; public function execute() { $zip_path = str_replace('.png', '.zip', $this->context['file_path']); $zip = new ZipArchive(); $zip->open($zip_path, ZipArchive::CREATE); $zip->addFile($this->context['file_path'], basename($this->context['file_path'])); $zip->close(); $this->context['zip_path'] = $zip_path; } } $organizer = new Organizer(['url' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/PHP-logo.svg/100px-PHP-logo.svg.png']); $result = $organizer->reduce([ CreateTmpFile::class, Download::class, ZipFile::class ]); print_r($result);
变更日志
请参阅 CHANGELOG 了解最近的变化。
测试
$ composer test
贡献
请参阅 CONTRIBUTING 和 CODE_OF_CONDUCT 了解详情。
安全
如果您发现任何安全相关的问题,请通过电子邮件 crojas@go-labs.net 而不是使用问题跟踪器。
鸣谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。