Php port for https://github.com/adomokos/light-service
Via 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);
Please see CHANGELOG for more information on what has changed recently.
$ composer test
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.