Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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