PHP code example of crojasaragonez / light-service
1. Go to this page and download the library: Download crojasaragonez/light-service library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
crojasaragonez / light-service example snippets
php
e 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);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.