| 1 |
<?php |
| 2 |
|
| 3 |
namespace Tableberg\Renderer\Attrs; |
| 4 |
|
| 5 |
class NumberAttr { |
| 6 |
/** @var int|float */ |
| 7 |
private $value; |
| 8 |
|
| 9 |
/** |
| 10 |
* @param int|float $value |
| 11 |
* @param int|float $default |
| 12 |
*/ |
| 13 |
public function __construct($value, $default) { |
| 14 |
if ($value === null || $value === '') { |
| 15 |
$this->value = $default; |
| 16 |
} else { |
| 17 |
$this->value = is_float($default) ? (float) $value : (int) $value; |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
/** @return int|float */ |
| 22 |
public function value() { |
| 23 |
return $this->value; |
| 24 |
} |
| 25 |
|
| 26 |
/** @return string */ |
| 27 |
public function asAttr() { |
| 28 |
return esc_attr((string) $this->value); |
| 29 |
} |
| 30 |
} |
| 31 |
|