crojasaragonez/light-service
最新稳定版本:2.1.0
Composer 安装命令:
composer require crojasaragonez/light-service
包简介
Php port for https://github.com/adomokos/light-service
README 文档
README
Php port for https://github.com/adomokos/light-service
Install
Via Composer
$ composer require crojasaragonez/light-service
Usage
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);
Progress Tracking
You can track the progress of action execution by passing a callback to reduce():
$organizer = new Organizer(['url' => 'https://example.com/image.png']); $result = $organizer->reduce([ CreateTmpFile::class, Download::class, ZipFile::class ], function(int $current, int $total, string $action, bool $skipped) { echo "[{$current}/{$total}] {$action}" . ($skipped ? ' (skipped)' : '') . "\n"; });
The callback receives:
$current- Number of actions processed so far (1-indexed)$total- Total number of actions$action- The class name of the action just processed$skipped- Whether the action was skipped (due toskipRemaining())
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email crojas@go-labs.net instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 2.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-28