diff --git a/src/ImageEditOptions.php b/src/ImageEditOptions.php index f9501d7..6bac311 100644 --- a/src/ImageEditOptions.php +++ b/src/ImageEditOptions.php @@ -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) { - return $watermark->toArray(); - }, $declinations); + 'watermarks' => array_map(function (Watermark $watermark) { + return $watermark->toArray(); }, $this->watermarks), ]); } diff --git a/src/Watermark.php b/src/Watermark.php index 118ecf2..f59a783 100644 --- a/src/Watermark.php +++ b/src/Watermark.php @@ -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; - } - - public function fallbackUrl(string $fallbackUrl) - { - $this->fallbackUrl = $fallbackUrl; + foreach ($options as $option) { + $this->addOption($option); + } 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_filter([ - 'url' => $this->url, - 'fallbackUrl' => $this->fallbackUrl, - 'width' => $this->width, - 'height' => $this->height - ]); + return array_map(function (WatermarkOption $option) { + return array_filter([ + 'url' => $option->getUrl(), + 'fallbackUrl' => $option->getFallbackUrl(), + 'width' => $option->getWidth(), + 'height' => $option->getHeight() + ]); + }, $this->options); } } diff --git a/src/WatermarkOption.php b/src/WatermarkOption.php new file mode 100644 index 0000000..a4f81b5 --- /dev/null +++ b/src/WatermarkOption.php @@ -0,0 +1,91 @@ +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 + ]); + } +} diff --git a/testDownloadTo.zip b/testDownloadTo.zip deleted file mode 100644 index 6767252..0000000 Binary files a/testDownloadTo.zip and /dev/null differ diff --git a/tests/MultiDownloaderClientTest.php b/tests/MultiDownloaderClientTest.php index 5196a56..ef4cac7 100644 --- a/tests/MultiDownloaderClientTest.php +++ b/tests/MultiDownloaderClientTest.php @@ -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));