Debian Codegraph @

lib/3rdParty/composer/aws/aws-crt-php/src/AWS/CRT/Options.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 * SPDX-License-Identifier: Apache-2.0.
5 */
6 namespace AWS\CRT;
7
8 final class OptionValue {
9 private $value;
10 function __construct($value) {
11 $this->value = $value;
12 }
13
14 public function asObject() {
15 return $this->value;
16 }
17
18 public function asMixed() {
19 return $this->value;
20 }
21
22 public function asInt() {
23 return empty($this->value) ? 0 : (int)$this->value;
24 }
25
26 public function asBool() {
27 return boolval($this->value);
28 }
29
30 public function asString() {
31 return !empty($this->value) ? strval($this->value) : "";
32 }
33
34 public function asArray() {
35 return is_array($this->value) ? $this->value : (!empty($this->value) ? [$this->value] : []);
36 }
37
38 public function asCallable() {
39 return is_callable($this->value) ? $this->value : null;
40 }
41 }
42
43 final class Options {
44 private $options;
45
46 public function __construct($opts = [], $defaults = []) {
47 $this->options = array_replace($defaults, empty($opts) ? [] : $opts);
48 }
49
50 public function __get($name) {
51 return $this->get($name);
52 }
53
54 public function asArray() {
55 return $this->options;
56 }
57
58 public function toArray() {
59 return array_merge_recursive([], $this->options);
60 }
61
62 public function get($name) {
63 return new OptionValue($this->options[$name]);
64 }
65
66 public function getInt($name) {
67 return $this->get($name)->asInt();
68 }
69
70 public function getString($name) {
71 return $this->get($name)->asString();
72 }
73
74 public function getBool($name) {
75 return $this->get($name)->asBool();
76 }
77 }