| 1 |
<?php |
| 2 |
|
| 3 |
namespace WebPConvert\Options; |
| 4 |
|
| 5 |
use WebPConvert\Options\IntegerOption; |
| 6 |
use WebPConvert\Options\Exceptions\InvalidOptionValueException; |
| 7 |
|
| 8 |
/** |
| 9 |
* Abstract option class |
| 10 |
* |
| 11 |
* @package WebPConvert |
| 12 |
* @author Bjørn Rosell <[email protected]> |
| 13 |
* @since Class available since Release 2.0.0 |
| 14 |
*/ |
| 15 |
class IntegerOrNullOption extends IntegerOption |
| 16 |
{ |
| 17 |
protected $schemaType = ['integer', 'null']; |
| 18 |
|
| 19 |
public function __construct($id, $defaultValue, $minValue = null, $maxValue = null) |
| 20 |
{ |
| 21 |
parent::__construct($id, $defaultValue, $minValue, $maxValue); |
| 22 |
} |
| 23 |
|
| 24 |
public function check() |
| 25 |
{ |
| 26 |
$this->checkMinMax(); |
| 27 |
|
| 28 |
$valueType = gettype($this->getValue()); |
| 29 |
if (!in_array($valueType, ['integer', 'NULL'])) { |
| 30 |
throw new InvalidOptionValueException( |
| 31 |
'The "' . $this->id . '" option must be either integer or NULL. ' . |
| 32 |
'You however provided a value of type: ' . $valueType |
| 33 |
); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
public function getValueForPrint() |
| 38 |
{ |
| 39 |
if (gettype($this->getValue() == 'NULL')) { |
| 40 |
return 'null (not set)'; |
| 41 |
} |
| 42 |
return parent::getValueForPrint(); |
| 43 |
} |
| 44 |
|
| 45 |
public function getDefinition() |
| 46 |
{ |
| 47 |
$obj = parent::getDefinition(); |
| 48 |
return $obj; |
| 49 |
} |
| 50 |
} |
| 51 |
|