| 1 |
<?php |
| 2 |
|
| 3 |
namespace TablePress\PhpOffice\PhpSpreadsheet\Helper; |
| 4 |
|
| 5 |
use Stringable; |
| 6 |
|
| 7 |
class Size |
| 8 |
{ |
| 9 |
const REGEXP_SIZE_VALIDATION = '/^(?P<size>\d*\.?\d+)(?P<unit>pt|px|em)?$/i'; |
| 10 |
protected bool $valid = false; |
| 11 |
protected string $size = ''; |
| 12 |
protected string $unit = ''; |
| 13 |
public function __construct(string $size) |
| 14 |
{ |
| 15 |
if (1 === preg_match(self::REGEXP_SIZE_VALIDATION, $size, $matches)) { |
| 16 |
$this->valid = true; |
| 17 |
$this->size = $matches['size']; |
| 18 |
$this->unit = $matches['unit'] ?? 'pt'; |
| 19 |
} |
| 20 |
} |
| 21 |
public function valid(): bool |
| 22 |
{ |
| 23 |
return $this->valid; |
| 24 |
} |
| 25 |
public function size(): string |
| 26 |
{ |
| 27 |
return $this->size; |
| 28 |
} |
| 29 |
public function unit(): string |
| 30 |
{ |
| 31 |
return $this->unit; |
| 32 |
} |
| 33 |
public function __toString(): string |
| 34 |
{ |
| 35 |
return $this->size . $this->unit; |
| 36 |
} |
| 37 |
} |
| 38 |
|