Skip to content

Commit 17fb3da

Browse files
committed
:octocat: moved settings init
1 parent 8569fce commit 17fb3da

File tree

3 files changed

+45
-40
lines changed

3 files changed

+45
-40
lines changed

src/Imagetiler.php

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace chillerlan\Imagetiler;
1414

15-
use chillerlan\Traits\ContainerInterface;
15+
use chillerlan\Settings\SettingsContainerInterface;
1616
use ImageOptimizer\Optimizer;
1717
use Imagick;
1818
use Psr\Log\{LoggerAwareInterface, LoggerAwareTrait, LoggerInterface, NullLogger};
@@ -33,13 +33,13 @@ class Imagetiler implements LoggerAwareInterface{
3333
/**
3434
* Imagetiler constructor.
3535
*
36-
* @param \chillerlan\Traits\ContainerInterface|null $options
36+
* @param \chillerlan\Settings\SettingsContainerInterface|null $options
3737
* @param \ImageOptimizer\Optimizer $optimizer
3838
* @param \Psr\Log\LoggerInterface|null $logger
3939
*
4040
* @throws \chillerlan\Imagetiler\ImagetilerException
4141
*/
42-
public function __construct(ContainerInterface $options = null, Optimizer $optimizer = null, LoggerInterface $logger = null){
42+
public function __construct(SettingsContainerInterface $options = null, Optimizer $optimizer = null, LoggerInterface $logger = null){
4343

4444
if(!extension_loaded('imagick')){
4545
throw new ImagetilerException('Imagick extension is not available');
@@ -54,23 +54,12 @@ public function __construct(ContainerInterface $options = null, Optimizer $optim
5454
}
5555

5656
/**
57-
* @param \chillerlan\Traits\ContainerInterface $options
57+
* @param \chillerlan\Settings\SettingsContainerInterface $options
5858
*
5959
* @return \chillerlan\Imagetiler\Imagetiler
6060
* @throws \chillerlan\Imagetiler\ImagetilerException
6161
*/
62-
public function setOptions(ContainerInterface $options):Imagetiler{
63-
$options->zoom_min = max(0, $options->zoom_min);
64-
$options->zoom_max = max(1, $options->zoom_max);
65-
66-
if($options->zoom_normalize === null || $options->zoom_max < $options->zoom_normalize){
67-
$options->zoom_normalize = $options->zoom_max;
68-
}
69-
70-
if($options->tile_ext === null){
71-
$options->tile_ext = $this->getExtension($options->tile_format);
72-
}
73-
62+
public function setOptions(SettingsContainerInterface $options):Imagetiler{
7463
$this->options = $options;
7564

7665
if(ini_set('memory_limit', $this->options->memory_limit) === false){
@@ -86,7 +75,6 @@ public function setOptions(ContainerInterface $options):Imagetiler{
8675
putenv('MAGICK_TEMPORARY_PATH='.$this->options->imagick_tmp);
8776
}
8877

89-
9078
return $this;
9179
}
9280

@@ -350,25 +338,4 @@ protected function getSize(int $width, int $height, int $zoom):array{
350338
return [$width, $height];
351339
}
352340

353-
/**
354-
* return file extension depend of given format
355-
*
356-
* @param string $format
357-
*
358-
* @return string
359-
* @throws \chillerlan\Imagetiler\ImagetilerException
360-
*/
361-
protected function getExtension(string $format):string{
362-
363-
if(in_array($format, ['jpeg', 'jp2', 'jpc', 'jxr',], true)){
364-
return 'jpg';
365-
}
366-
367-
if(in_array($format, ['png', 'png00', 'png8', 'png24', 'png32', 'png64',], true)){
368-
return 'png';
369-
}
370-
371-
throw new ImagetilerException('invalid file format');
372-
}
373-
374341
}

src/ImagetilerOptions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace chillerlan\Imagetiler;
1414

15-
use chillerlan\Traits\ContainerAbstract;
15+
use chillerlan\Settings\SettingsContainerAbstract;
1616

1717
/**
1818
* @property int $tile_size
@@ -35,6 +35,6 @@
3535
* @property bool $clean_up
3636
* @property bool $optimize_output
3737
*/
38-
class ImagetilerOptions extends ContainerAbstract{
38+
class ImagetilerOptions extends SettingsContainerAbstract{
3939
use ImagetilerOptionsTrait;
4040
}

src/ImagetilerOptionsTrait.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,42 @@ trait ImagetilerOptionsTrait{
152152
*/
153153
protected $optimize_output = false;
154154

155+
/**
156+
* "constructor"
157+
*/
158+
public function ImagetilerOptionsTrait(){
159+
$this->zoom_min = max(0, $this->zoom_min);
160+
$this->zoom_max = max(1, $this->zoom_max);
161+
162+
if($this->zoom_normalize === null || $this->zoom_max < $this->zoom_normalize){
163+
$this->zoom_normalize = $this->zoom_max;
164+
}
165+
166+
if($this->tile_ext === null){
167+
$this->tile_ext = $this->getExtension($this->tile_format);
168+
}
169+
170+
}
171+
172+
/**
173+
* return file extension depend of given format
174+
*
175+
* @param string $format
176+
*
177+
* @return string
178+
* @throws \chillerlan\Imagetiler\ImagetilerException
179+
*/
180+
protected function getExtension(string $format):string{
181+
182+
if(in_array($format, ['jpeg', 'jp2', 'jpc', 'jxr',], true)){
183+
return 'jpg';
184+
}
185+
186+
if(in_array($format, ['png', 'png00', 'png8', 'png24', 'png32', 'png64',], true)){
187+
return 'png';
188+
}
189+
190+
throw new ImagetilerException('invalid file format');
191+
}
192+
155193
}

0 commit comments

Comments
 (0)