PluginProbe ʕ •ᴥ•ʔ
Transferito: WP Migration / trunk
Transferito: WP Migration vtrunk
trunk 11.4.0 12.0.0 13.1.0 14.0.0 14.0.11 14.0.7 14.1.0 14.1.1 14.1.2 14.1.3 14.1.4
transferito / vendor / aws / aws-sdk-php / src / EndpointV2 / Ruleset / RulesetParameter.php
transferito / vendor / aws / aws-sdk-php / src / EndpointV2 / Ruleset Last commit date
Ruleset.php 11 months ago RulesetEndpoint.php 11 months ago RulesetParameter.php 11 months ago RulesetStandardLibrary.php 11 months ago
RulesetParameter.php
149 lines
1 <?php
2
3 namespace Aws\EndpointV2\Ruleset;
4
5 use Aws\Exception\UnresolvedEndpointException;
6
7 /**
8 * Houses properties of an individual parameter definition.
9 */
10 class RulesetParameter
11 {
12 /** @var string */
13 private $name;
14
15 /** @var string */
16 private $type;
17
18 /** @var string */
19 private $builtIn;
20
21 /** @var string */
22 private $default;
23
24 /** @var array */
25 private $required;
26
27 /** @var string */
28 private $documentation;
29
30 /** @var boolean */
31 private $deprecated;
32
33 public function __construct($name, array $definition)
34 {
35 $type = ucfirst($definition['type']);
36 if ($this->isValidType($type)) {
37 $this->type = $type;
38 } else {
39 throw new UnresolvedEndpointException(
40 'Unknown parameter type ' . "`{$type}`" .
41 '. Parameters must be of type `String` or `Boolean`.'
42 );
43 }
44 $this->name = $name;
45 $this->builtIn = isset($definition['builtIn']) ? $definition['builtIn'] : null;
46 $this->default = isset($definition['default']) ? $definition['default'] : null;
47 $this->required = isset($definition['required']) ?
48 $definition['required'] : false;
49 $this->documentation = isset($definition['documentation']) ?
50 $definition['documentation'] : null;
51 $this->deprecated = isset($definition['deprecated']) ?
52 $definition['deprecated'] : false;
53 }
54
55 /**
56 * @return mixed
57 */
58 public function getName()
59 {
60 return $this->name;
61 }
62
63 /**
64 * @return mixed
65 */
66 public function getType()
67 {
68 return $this->type;
69 }
70
71 /**
72 * @return mixed
73 */
74 public function getBuiltIn()
75 {
76 return $this->builtIn;
77 }
78
79 /**
80 * @return mixed
81 */
82 public function getDefault()
83 {
84 return $this->default;
85 }
86
87 /**
88 * @return boolean
89 */
90 public function getRequired()
91 {
92 return $this->required;
93 }
94
95 /**
96 * @return string
97 */
98 public function getDocumentation()
99 {
100 return $this->documentation;
101 }
102
103 /**
104 * @return boolean
105 */
106 public function getDeprecated()
107 {
108 return $this->deprecated;
109 }
110
111 /**
112 * Validates that an input parameter matches the type provided in its definition.
113 *
114 * @return void
115 * @throws InvalidArgumentException
116 */
117 public function validateInputParam($inputParam)
118 {
119 $typeMap = [
120 'String' => 'is_string',
121 'Boolean' => 'is_bool'
122 ];
123
124 if ($typeMap[$this->type]($inputParam) === false) {
125 throw new UnresolvedEndpointException(
126 "Input parameter `{$this->name}` is the wrong type. Must be a {$this->type}."
127 );
128 }
129
130 if ($this->deprecated) {
131 $deprecated = $this->deprecated;
132 $deprecationString = "{$this->name} has been deprecated ";
133 $msg = isset($deprecated['message']) ? $deprecated['message'] : null;
134 $since = isset($deprecated['since']) ? $deprecated['since'] : null;
135
136 if (!is_null($since)) $deprecationString = $deprecationString
137 . 'since '. $since . '. ';
138 if (!is_null($msg)) $deprecationString = $deprecationString . $msg;
139
140 trigger_error($deprecationString, E_USER_WARNING);
141 }
142 }
143
144 private function isValidType($type)
145 {
146 return in_array($type, ['String', 'Boolean']);
147 }
148 }
149