blob: 363a396c4c9aa61e569d52ccc554c8c8af31c944 (
plain)
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
|
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
namespace AWS\CRT;
final class OptionValue {
private $value;
function __construct($value) {
$this->value = $value;
}
public function asObject() {
return $this->value;
}
public function asMixed() {
return $this->value;
}
public function asInt() {
return empty($this->value) ? 0 : (int)$this->value;
}
public function asBool() {
return boolval($this->value);
}
public function asString() {
return !empty($this->value) ? strval($this->value) : "";
}
public function asArray() {
return is_array($this->value) ? $this->value : (!empty($this->value) ? [$this->value] : []);
}
public function asCallable() {
return is_callable($this->value) ? $this->value : null;
}
}
final class Options {
private $options;
public function __construct($opts = [], $defaults = []) {
$this->options = array_replace($defaults, empty($opts) ? [] : $opts);
}
public function __get($name) {
return $this->get($name);
}
public function asArray() {
return $this->options;
}
public function toArray() {
return array_merge_recursive([], $this->options);
}
public function get($name) {
return new OptionValue($this->options[$name]);
}
public function getInt($name) {
return $this->get($name)->asInt();
}
public function getString($name) {
return $this->get($name)->asString();
}
public function getBool($name) {
return $this->get($name)->asBool();
}
}
|