1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,118 +0,0 @@ |
1 |
-<?php declare(strict_types=1); |
|
2 |
-/** |
|
3 |
- * Part of earth project. |
|
4 |
- * |
|
5 |
- * @copyright Copyright (C) 2019 $Asikart. |
|
6 |
- * @license LGPL-2.0-or-later |
|
7 |
- */ |
|
8 |
- |
|
9 |
-namespace Windwalker\Structure; |
|
10 |
- |
|
11 |
-/** |
|
12 |
- * The ValueReference class. |
|
13 |
- * |
|
14 |
- * @since 3.5.1 |
|
15 |
- */ |
|
16 |
-class ValueReference |
|
17 |
-{ |
|
18 |
- /** |
|
19 |
- * Property path. |
|
20 |
- * |
|
21 |
- * @var string |
|
22 |
- */ |
|
23 |
- protected $path; |
|
24 |
- |
|
25 |
- /** |
|
26 |
- * Property separator. |
|
27 |
- * |
|
28 |
- * @var string |
|
29 |
- */ |
|
30 |
- protected $separator; |
|
31 |
- |
|
32 |
- /** |
|
33 |
- * ValueReference constructor. |
|
34 |
- * |
|
35 |
- * @param string $path |
|
36 |
- * @param string $separator |
|
37 |
- */ |
|
38 |
- public function __construct(string $path, ?string $separator = null) |
|
39 |
- { |
|
40 |
- $this->path = $path; |
|
41 |
- $this->separator = $separator; |
|
42 |
- } |
|
43 |
- |
|
44 |
- /** |
|
45 |
- * Get from Structure. |
|
46 |
- * |
|
47 |
- * @param Structure|array|object $structure |
|
48 |
- * @param mixed $default |
|
49 |
- * |
|
50 |
- * @return mixed |
|
51 |
- * |
|
52 |
- * @since 3.5.1 |
|
53 |
- */ |
|
54 |
- public function get($structure, $default = null) |
|
55 |
- { |
|
56 |
- if ($structure instanceof Structure) { |
|
57 |
- return $structure->get($this->path, $default, $this->separator); |
|
58 |
- } |
|
59 |
- |
|
60 |
- return StructureHelper::getByPath($structure, $this->path, $this->separator ?: '.'); |
|
61 |
- } |
|
62 |
- |
|
63 |
- /** |
|
64 |
- * Method to get property Path |
|
65 |
- * |
|
66 |
- * @return string |
|
67 |
- * |
|
68 |
- * @since 3.5.1 |
|
69 |
- */ |
|
70 |
- public function getPath(): string |
|
71 |
- { |
|
72 |
- return $this->path; |
|
73 |
- } |
|
74 |
- |
|
75 |
- /** |
|
76 |
- * Method to set property path |
|
77 |
- * |
|
78 |
- * @param string $path |
|
79 |
- * |
|
80 |
- * @return static Return self to support chaining. |
|
81 |
- * |
|
82 |
- * @since 3.5.1 |
|
83 |
- */ |
|
84 |
- public function setPath(string $path) |
|
85 |
- { |
|
86 |
- $this->path = $path; |
|
87 |
- |
|
88 |
- return $this; |
|
89 |
- } |
|
90 |
- |
|
91 |
- /** |
|
92 |
- * Method to get property Separator |
|
93 |
- * |
|
94 |
- * @return string |
|
95 |
- * |
|
96 |
- * @since 3.5.1 |
|
97 |
- */ |
|
98 |
- public function getSeparator(): string |
|
99 |
- { |
|
100 |
- return $this->separator; |
|
101 |
- } |
|
102 |
- |
|
103 |
- /** |
|
104 |
- * Method to set property separator |
|
105 |
- * |
|
106 |
- * @param string $separator |
|
107 |
- * |
|
108 |
- * @return static Return self to support chaining. |
|
109 |
- * |
|
110 |
- * @since 3.5.1 |
|
111 |
- */ |
|
112 |
- public function setSeparator(string $separator) |
|
113 |
- { |
|
114 |
- $this->separator = $separator; |
|
115 |
- |
|
116 |
- return $this; |
|
117 |
- } |
|
118 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,118 @@ |
1 |
+<?php declare(strict_types=1); |
|
2 |
+/** |
|
3 |
+ * Part of earth project. |
|
4 |
+ * |
|
5 |
+ * @copyright Copyright (C) 2019 $Asikart. |
|
6 |
+ * @license LGPL-2.0-or-later |
|
7 |
+ */ |
|
8 |
+ |
|
9 |
+namespace Windwalker\Structure; |
|
10 |
+ |
|
11 |
+/** |
|
12 |
+ * The ValueReference class. |
|
13 |
+ * |
|
14 |
+ * @since 3.5.1 |
|
15 |
+ */ |
|
16 |
+class ValueReference |
|
17 |
+{ |
|
18 |
+ /** |
|
19 |
+ * Property path. |
|
20 |
+ * |
|
21 |
+ * @var string |
|
22 |
+ */ |
|
23 |
+ protected $path; |
|
24 |
+ |
|
25 |
+ /** |
|
26 |
+ * Property separator. |
|
27 |
+ * |
|
28 |
+ * @var string |
|
29 |
+ */ |
|
30 |
+ protected $separator; |
|
31 |
+ |
|
32 |
+ /** |
|
33 |
+ * ValueReference constructor. |
|
34 |
+ * |
|
35 |
+ * @param string $path |
|
36 |
+ * @param string $separator |
|
37 |
+ */ |
|
38 |
+ public function __construct(string $path, ?string $separator = null) |
|
39 |
+ { |
|
40 |
+ $this->path = $path; |
|
41 |
+ $this->separator = $separator; |
|
42 |
+ } |
|
43 |
+ |
|
44 |
+ /** |
|
45 |
+ * Get from Structure. |
|
46 |
+ * |
|
47 |
+ * @param Structure|array|object $structure |
|
48 |
+ * @param mixed $default |
|
49 |
+ * |
|
50 |
+ * @return mixed |
|
51 |
+ * |
|
52 |
+ * @since 3.5.1 |
|
53 |
+ */ |
|
54 |
+ public function get($structure, $default = null) |
|
55 |
+ { |
|
56 |
+ if ($structure instanceof Structure) { |
|
57 |
+ return $structure->get($this->path, $default, $this->separator); |
|
58 |
+ } |
|
59 |
+ |
|
60 |
+ return StructureHelper::getByPath($structure, $this->path, $this->separator ?: '.'); |
|
61 |
+ } |
|
62 |
+ |
|
63 |
+ /** |
|
64 |
+ * Method to get property Path |
|
65 |
+ * |
|
66 |
+ * @return string |
|
67 |
+ * |
|
68 |
+ * @since 3.5.1 |
|
69 |
+ */ |
|
70 |
+ public function getPath(): string |
|
71 |
+ { |
|
72 |
+ return $this->path; |
|
73 |
+ } |
|
74 |
+ |
|
75 |
+ /** |
|
76 |
+ * Method to set property path |
|
77 |
+ * |
|
78 |
+ * @param string $path |
|
79 |
+ * |
|
80 |
+ * @return static Return self to support chaining. |
|
81 |
+ * |
|
82 |
+ * @since 3.5.1 |
|
83 |
+ */ |
|
84 |
+ public function setPath(string $path) |
|
85 |
+ { |
|
86 |
+ $this->path = $path; |
|
87 |
+ |
|
88 |
+ return $this; |
|
89 |
+ } |
|
90 |
+ |
|
91 |
+ /** |
|
92 |
+ * Method to get property Separator |
|
93 |
+ * |
|
94 |
+ * @return string |
|
95 |
+ * |
|
96 |
+ * @since 3.5.1 |
|
97 |
+ */ |
|
98 |
+ public function getSeparator(): string |
|
99 |
+ { |
|
100 |
+ return $this->separator; |
|
101 |
+ } |
|
102 |
+ |
|
103 |
+ /** |
|
104 |
+ * Method to set property separator |
|
105 |
+ * |
|
106 |
+ * @param string $separator |
|
107 |
+ * |
|
108 |
+ * @return static Return self to support chaining. |
|
109 |
+ * |
|
110 |
+ * @since 3.5.1 |
|
111 |
+ */ |
|
112 |
+ public function setSeparator(string $separator) |
|
113 |
+ { |
|
114 |
+ $this->separator = $separator; |
|
115 |
+ |
|
116 |
+ return $this; |
|
117 |
+ } |
|
118 |
+} |