crojasaragonez / light-service
Php port for https://github.com/adomokos/light-service
Installs: 2 120
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/crojasaragonez/light-service
Requires
- php: >=8.2
Requires (Dev)
- phpunit/phpunit: ^12.1
- squizlabs/php_codesniffer: ^4.0
This package is auto-updated.
Last update: 2025-12-30 20:53:34 UTC
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.