/light-service

Port of https://github.com/adomokos/light-service for Php

Primary LanguagePHPMIT LicenseMIT

LightService

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

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);

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.