1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the SexyField package. |
5
|
|
|
* |
6
|
|
|
* (c) Dion Snoeijen <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare (strict_types = 1); |
13
|
|
|
|
14
|
|
|
namespace Tardigrades\SectionField\ValueObject; |
15
|
|
|
|
16
|
|
|
use Assert\Assertion; |
17
|
|
|
|
18
|
|
|
final class SectionFormOptions |
19
|
|
|
{ |
20
|
|
|
/** @var $options */ |
|
|
|
|
21
|
|
|
private $options; |
22
|
|
|
|
23
|
|
|
private function __construct(array $options) |
24
|
|
|
{ |
25
|
|
|
$this->options = $options; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getId(): Id |
29
|
|
|
{ |
30
|
|
|
Assertion::keyIsset($this->options, 'id', 'The id is not set'); |
31
|
|
|
Assertion::digit($this->options['id'], 'The id must be a digit'); |
32
|
|
|
|
33
|
|
|
return Id::fromInt((int) $this->options['id']); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getSlug(): Slug |
37
|
|
|
{ |
38
|
|
|
Assertion::keyIsset($this->options, 'slug', 'The slug is not set'); |
39
|
|
|
Assertion::string($this->options['slug'], 'The slug must be a string'); |
40
|
|
|
Assertion::notEmpty($this->options['slug'], 'The slug is empty'); |
41
|
|
|
|
42
|
|
|
return Slug::fromString($this->options['slug']); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getRedirect(): string |
46
|
|
|
{ |
47
|
|
|
Assertion::keyIsset($this->options, 'redirect', 'The redirect is not set'); |
48
|
|
|
Assertion::string($this->options['redirect'], 'The redirect must be a string'); |
49
|
|
|
|
50
|
|
|
return $this->options['redirect']; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public static function fromArray(array $options): self |
54
|
|
|
{ |
55
|
|
|
return new self($options); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|