-
-
Notifications
You must be signed in to change notification settings - Fork 221
/
Adjustment.php
97 lines (84 loc) · 2.09 KB
/
Adjustment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
declare(strict_types=1);
namespace Neos\Media\Domain\ValueObject\Configuration;
/*
* This file is part of the Neos.Media package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
final class Adjustment
{
/**
* @var string
*/
private $identifier;
/**
* @var string
*/
private $type;
/**
* @var array
*/
private $options = [];
/**
* @param string $identifier
* @param string $type
*/
public function __construct(string $identifier, string $type)
{
$this->setIdentifier($identifier);
$this->type = $type;
}
/**
* @param string $identifier
* @param array $configuration
* @return Adjustment
*/
public static function fromConfiguration(string $identifier, array $configuration): Adjustment
{
if (!isset($configuration['type'])) {
throw new \InvalidArgumentException(sprintf('Missing type in configuration for adjustment "%s".', $identifier), 1549276551);
}
$adjustment = new static(
$identifier,
$configuration['type']
);
$adjustment->options = $configuration['options'] ?? [];
return $adjustment;
}
/**
* @param string $identifier
*/
private function setIdentifier(string $identifier): void
{
if (preg_match('/^[a-zA-Z0-9-]+$/', $identifier) !== 1) {
throw new \InvalidArgumentException(sprintf('Invalid adjustment identifier "%s".', $identifier), 1548066064);
}
$this->identifier = $identifier;
}
/**
* @return string
*/
public function identifier(): string
{
return $this->identifier;
}
/**
* @return string
*/
public function type(): string
{
return $this->type;
}
/**
* @return array
*/
public function options(): array
{
return $this->options;
}
}