| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Imagify\Dependencies\League\Container\Argument; |
| 6 |
|
| 7 |
use InvalidArgumentException; |
| 8 |
|
| 9 |
class LiteralArgument implements LiteralArgumentInterface |
| 10 |
{ |
| 11 |
public const TYPE_ARRAY = 'array'; |
| 12 |
public const TYPE_BOOL = 'boolean'; |
| 13 |
public const TYPE_BOOLEAN = 'boolean'; |
| 14 |
public const TYPE_CALLABLE = 'callable'; |
| 15 |
public const TYPE_DOUBLE = 'double'; |
| 16 |
public const TYPE_FLOAT = 'double'; |
| 17 |
public const TYPE_INT = 'integer'; |
| 18 |
public const TYPE_INTEGER = 'integer'; |
| 19 |
public const TYPE_OBJECT = 'object'; |
| 20 |
public const TYPE_STRING = 'string'; |
| 21 |
|
| 22 |
/** |
| 23 |
* @var mixed |
| 24 |
*/ |
| 25 |
protected $value; |
| 26 |
|
| 27 |
public function __construct($value, ?string $type = null) |
| 28 |
{ |
| 29 |
if ( |
| 30 |
null === $type |
| 31 |
|| ($type === self::TYPE_CALLABLE && is_callable($value)) |
| 32 |
|| ($type === self::TYPE_OBJECT && is_object($value)) |
| 33 |
|| gettype($value) === $type |
| 34 |
) { |
| 35 |
$this->value = $value; |
| 36 |
} else { |
| 37 |
throw new InvalidArgumentException('Incorrect type for value.'); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* {@inheritdoc} |
| 43 |
*/ |
| 44 |
public function getValue() |
| 45 |
{ |
| 46 |
return $this->value; |
| 47 |
} |
| 48 |
} |
| 49 |
|