refactor
This commit is contained in:
parent
3decfae78f
commit
ac0ec41f8d
@ -51,12 +51,9 @@ class ImageEditOptions
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $declinations Tableau de déclinaisons d'une watermark dans plusieurs tailles
|
||||
*/
|
||||
public function addWatermark(array $declinations)
|
||||
public function addWatermark(Watermark $watermark)
|
||||
{
|
||||
$this->watermarks[] = $declinations;
|
||||
$this->watermarks[] = $watermark;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -80,10 +77,8 @@ class ImageEditOptions
|
||||
return array_filter([
|
||||
'width' => $this->width,
|
||||
'height' => $this->height,
|
||||
'watermarks' => array_map(function (array $declinations) {
|
||||
return array_map(function (Watermark $watermark) {
|
||||
'watermarks' => array_map(function (Watermark $watermark) {
|
||||
return $watermark->toArray();
|
||||
}, $declinations);
|
||||
}, $this->watermarks),
|
||||
]);
|
||||
}
|
||||
|
@ -5,87 +5,53 @@ namespace Nwb\MultiDownloaderClient;
|
||||
class Watermark
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @var WatermarkOption[]
|
||||
*/
|
||||
private $url;
|
||||
private $options = [];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $fallbackUrl;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $width;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $height;
|
||||
|
||||
public function __construct(string $url, int $width, int $height)
|
||||
public function __construct(array $options)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
$this->addOptions($options);
|
||||
}
|
||||
|
||||
public function url(string $url)
|
||||
public function addOption(WatermarkOption $option)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->options[] = $option;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUrl(): string
|
||||
public function addOptions(array $options)
|
||||
{
|
||||
return $this->url;
|
||||
foreach ($options as $option) {
|
||||
$this->addOption($option);
|
||||
}
|
||||
|
||||
public function fallbackUrl(string $fallbackUrl)
|
||||
{
|
||||
$this->fallbackUrl = $fallbackUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFallbackUrl(): string
|
||||
public function getOptions(): array
|
||||
{
|
||||
return $this->fallbackUrl;
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
public function width(int $width)
|
||||
public function options(array $options)
|
||||
{
|
||||
$this->width = $width;
|
||||
$this->options = [];
|
||||
$this->options = $options;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWidth(): int
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
public function height(int $height)
|
||||
{
|
||||
$this->height = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHeight(): int
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return array_map(function (WatermarkOption $option) {
|
||||
return array_filter([
|
||||
'url' => $this->url,
|
||||
'fallbackUrl' => $this->fallbackUrl,
|
||||
'width' => $this->width,
|
||||
'height' => $this->height
|
||||
'url' => $option->getUrl(),
|
||||
'fallbackUrl' => $option->getFallbackUrl(),
|
||||
'width' => $option->getWidth(),
|
||||
'height' => $option->getHeight()
|
||||
]);
|
||||
}, $this->options);
|
||||
}
|
||||
}
|
||||
|
91
src/WatermarkOption.php
Normal file
91
src/WatermarkOption.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Nwb\MultiDownloaderClient;
|
||||
|
||||
class WatermarkOption
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $fallbackUrl;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $width;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $height;
|
||||
|
||||
public function __construct(string $url, int $width, int $height)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
}
|
||||
|
||||
public function url(string $url)
|
||||
{
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function fallbackUrl(string $fallbackUrl)
|
||||
{
|
||||
$this->fallbackUrl = $fallbackUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFallbackUrl()
|
||||
{
|
||||
return $this->fallbackUrl;
|
||||
}
|
||||
|
||||
public function width(int $width)
|
||||
{
|
||||
$this->width = $width;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWidth()
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
public function height(int $height)
|
||||
{
|
||||
$this->height = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHeight()
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return array_filter([
|
||||
'url' => $this->url,
|
||||
'fallbackUrl' => $this->fallbackUrl,
|
||||
'width' => $this->width,
|
||||
'height' => $this->height
|
||||
]);
|
||||
}
|
||||
}
|
Binary file not shown.
@ -5,6 +5,7 @@ include __DIR__ . '/../vendor/autoload.php';
|
||||
use Nwb\MultiDownloaderClient\FileRequest;
|
||||
use Nwb\MultiDownloaderClient\MultiDownloaderClient;
|
||||
use Nwb\MultiDownloaderClient\Watermark;
|
||||
use Nwb\MultiDownloaderClient\WatermarkOption;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class MultiDownloaderClientTest extends TestCase
|
||||
@ -20,9 +21,11 @@ class MultiDownloaderClientTest extends TestCase
|
||||
$file = new FileRequest($url);
|
||||
$file->getFileOptions()->name('test' . $i . '.png');
|
||||
|
||||
$watermark = new Watermark('https://dev-data-nwb.s3.eu-central-1.wasabisys.com/multi-downloader-sat/tests/img/watermarks/watermark.png', 100, 100);
|
||||
$watermark = new Watermark([
|
||||
new WatermarkOption('https://dev-data-nwb.s3.eu-central-1.wasabisys.com/multi-downloader-sat/tests/img/watermarks/watermark.png', 100, 100)
|
||||
]);
|
||||
|
||||
$file->getImageEditOptions()->addWatermark([$watermark]);
|
||||
$file->getImageEditOptions()->addWatermark($watermark);
|
||||
|
||||
return $file;
|
||||
}, $this->testFiles, array_keys($this->testFiles));
|
||||
|
Loading…
Reference in New Issue
Block a user