1 | <?php |
||
2 | |||
3 | namespace Erykai\Translate; |
||
4 | |||
5 | use stdClass; |
||
6 | |||
7 | /** |
||
8 | * class get and set |
||
9 | */ |
||
10 | abstract class Resource |
||
11 | { |
||
12 | use TraitTranslate; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
13 | |||
14 | /** |
||
15 | * @var object |
||
16 | */ |
||
17 | private object $data; |
||
18 | /** |
||
19 | * @var string|array |
||
20 | */ |
||
21 | private string|array $dynamic; |
||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | private string $path; |
||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private string $source; |
||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private string $sourceFile; |
||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | private string $target; |
||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | private string $targetFile; |
||
42 | /** |
||
43 | * @var object |
||
44 | */ |
||
45 | private object $response; |
||
46 | |||
47 | /** |
||
48 | * |
||
49 | */ |
||
50 | public function __construct(string $path = null) |
||
51 | { |
||
52 | if(!$path){ |
||
53 | $path = dirname(__DIR__, 4)."/".TRANSLATE_PATH; |
||
54 | } |
||
55 | $this->setPath($path); |
||
56 | $this->setSource('en'); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @return object |
||
61 | */ |
||
62 | protected function getData(): object |
||
63 | { |
||
64 | return $this->data; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @param object $data |
||
69 | */ |
||
70 | protected function setData(object $data): void |
||
71 | { |
||
72 | $this->data = $data; |
||
73 | } |
||
74 | |||
75 | |||
76 | |||
77 | /** |
||
78 | * @return string|array |
||
79 | */ |
||
80 | protected function getDynamic(): string|array |
||
81 | { |
||
82 | return $this->dynamic; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @param string|array $dynamic |
||
87 | */ |
||
88 | protected function setDynamic(string|array $dynamic): void |
||
89 | { |
||
90 | $this->dynamic = $dynamic; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @return string |
||
95 | */ |
||
96 | protected function getPath(): string |
||
97 | { |
||
98 | return $this->path; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @param string $path |
||
103 | */ |
||
104 | protected function setPath(string $path): void |
||
105 | { |
||
106 | $this->path = $path; |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @return string |
||
111 | */ |
||
112 | protected function getSource(): string |
||
113 | { |
||
114 | return $this->source; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * @param string $source |
||
119 | */ |
||
120 | protected function setSource(string $source): void |
||
121 | { |
||
122 | $this->source = $source; |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * @return string |
||
127 | */ |
||
128 | protected function getSourceFile(): string |
||
129 | { |
||
130 | return $this->sourceFile; |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * @param string $sourceFile |
||
135 | */ |
||
136 | protected function setSourceFile(string $sourceFile): void |
||
137 | { |
||
138 | $this->sourceFile = $sourceFile; |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * @return string |
||
143 | */ |
||
144 | protected function getTarget(): string |
||
145 | { |
||
146 | return $this->target; |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * @param string $target |
||
151 | */ |
||
152 | protected function setTarget(string $target): void |
||
153 | { |
||
154 | $this->target = $target; |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * @return string |
||
159 | */ |
||
160 | protected function getTargetFile(): string |
||
161 | { |
||
162 | return $this->targetFile; |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * @param string $targetFile |
||
167 | */ |
||
168 | protected function setTargetFile(string $targetFile): void |
||
169 | { |
||
170 | $this->targetFile = $targetFile; |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * @return object |
||
175 | */ |
||
176 | protected function getResponse(): object |
||
177 | { |
||
178 | return $this->response; |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * set response translator |
||
183 | */ |
||
184 | protected function setResponse(): void |
||
185 | { |
||
186 | $source = file($this->getSourceFile()); |
||
187 | $target = file($this->getTargetFile()); |
||
188 | $key = array_search($this->getData()->text . PHP_EOL, $source, true); |
||
189 | $translate = new stdClass(); |
||
190 | $translate->translate = $target[$key]; |
||
191 | $this->response = $translate; |
||
192 | } |
||
193 | } |