1 | <?php |
||
23 | class Product implements Arrayable, Jsonable |
||
24 | { |
||
25 | public const VERSION_MASTER = 'master'; |
||
26 | public const VERSION_UNKNOWN = 'unknown'; |
||
27 | |||
28 | private const ASSET_URL_PLACEHOLDER_1 = '{{docs}}'; |
||
29 | private const ASSET_URL_PLACEHOLDER_2 = '{{doc}}'; |
||
30 | private const ASSET_URL_PLACEHOLDERS = [ |
||
31 | self::ASSET_URL_PLACEHOLDER_1, |
||
32 | self::ASSET_URL_PLACEHOLDER_2, |
||
33 | ]; |
||
34 | private const META_FILE = '.docweaver.yml'; |
||
35 | |||
36 | /** |
||
37 | * Product key. |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | private $key; |
||
42 | |||
43 | /** |
||
44 | * Filesystem. |
||
45 | * |
||
46 | * @var Filesystem |
||
47 | */ |
||
48 | private $filesystem; |
||
49 | |||
50 | /** |
||
51 | * @var ConfigProvider |
||
52 | */ |
||
53 | private $configProvider; |
||
54 | |||
55 | /** |
||
56 | * Last time product was modified (timestamp). |
||
57 | * |
||
58 | * @var int |
||
59 | */ |
||
60 | private $lastModified; |
||
61 | |||
62 | /** |
||
63 | * Product name. |
||
64 | * |
||
65 | * @var string |
||
66 | */ |
||
67 | private $name; |
||
68 | |||
69 | /** |
||
70 | * Product description. |
||
71 | * |
||
72 | * @var null|string |
||
73 | */ |
||
74 | private $description; |
||
75 | |||
76 | /** |
||
77 | * Product image url. |
||
78 | * |
||
79 | * @var null|string |
||
80 | */ |
||
81 | private $imageUrl; |
||
82 | |||
83 | /** |
||
84 | * Product resource directory. |
||
85 | * |
||
86 | * @var string |
||
87 | */ |
||
88 | private $directory; |
||
89 | |||
90 | /** |
||
91 | * Product meta (from file). |
||
92 | * |
||
93 | * @var array |
||
94 | */ |
||
95 | private $meta; |
||
96 | |||
97 | /** |
||
98 | * List of available product versions. |
||
99 | * |
||
100 | * @var array |
||
101 | */ |
||
102 | private $versions; |
||
103 | |||
104 | /** |
||
105 | * Create product instance. |
||
106 | * |
||
107 | * @param Filesystem $filesystem |
||
108 | * @param ConfigProvider $configProvider |
||
109 | * @param string $directory |
||
110 | */ |
||
111 | public function __construct(Filesystem $filesystem, ConfigProvider $configProvider, string $directory) |
||
121 | |||
122 | /** |
||
123 | * Populate product. |
||
124 | * |
||
125 | * @throws Exception if meta file could not be parsed |
||
126 | */ |
||
127 | public function populate(): void |
||
132 | |||
133 | /** |
||
134 | * @return string |
||
135 | */ |
||
136 | public function getKey(): string |
||
140 | |||
141 | /** |
||
142 | * Get default version for product. |
||
143 | * |
||
144 | * @param bool $allowWordedDefault whether a worded version should be accepted as default |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | public function getDefaultVersion(bool $allowWordedDefault = false): string |
||
170 | |||
171 | /** |
||
172 | * Get product directory. |
||
173 | * |
||
174 | * @return string |
||
175 | */ |
||
176 | public function getDirectory(): string |
||
180 | |||
181 | /** |
||
182 | * Get product name. |
||
183 | * |
||
184 | * @return string |
||
185 | */ |
||
186 | public function getName(): string |
||
190 | |||
191 | /** |
||
192 | * Get product description. |
||
193 | * |
||
194 | * @return null|string |
||
195 | */ |
||
196 | public function getDescription(): ?string |
||
200 | |||
201 | /** |
||
202 | * Get product image url. |
||
203 | * |
||
204 | * @return null|string |
||
205 | */ |
||
206 | public function getImageUrl(): ?string |
||
210 | |||
211 | /** |
||
212 | * Get the publicly available versions of the product. |
||
213 | * |
||
214 | * @return array |
||
215 | */ |
||
216 | public function getVersions(): array |
||
220 | |||
221 | /** |
||
222 | * Get last modified time. |
||
223 | * |
||
224 | * @return Carbon |
||
225 | */ |
||
226 | public function getLastModified(): Carbon |
||
230 | |||
231 | /** |
||
232 | * Determine if the given string is a valid version. |
||
233 | * |
||
234 | * @param string $version |
||
235 | * |
||
236 | * @return bool |
||
237 | */ |
||
238 | public function hasVersion(string $version): bool |
||
242 | |||
243 | /** |
||
244 | * Publish product public assets. |
||
245 | * |
||
246 | * @param string $version |
||
247 | * |
||
248 | * @throws Exception if products asset directory is invalid or assets could not be published |
||
249 | */ |
||
250 | public function publishAssets(string $version): void |
||
266 | |||
267 | /** |
||
268 | * Get the instance as an array. |
||
269 | * |
||
270 | * @return array |
||
271 | */ |
||
272 | public function toArray(): array |
||
285 | |||
286 | /** |
||
287 | * Convert the object to its JSON representation. |
||
288 | * |
||
289 | * @param int $options |
||
290 | * |
||
291 | * @return string |
||
292 | */ |
||
293 | public function toJson($options = 0): string |
||
297 | |||
298 | /** |
||
299 | * @return string |
||
300 | */ |
||
301 | public function getMasterDirectory(): string |
||
305 | |||
306 | /** |
||
307 | * Convert url string to asset url relative to current product. |
||
308 | * |
||
309 | * @param string $url |
||
310 | * @param string $version |
||
311 | * |
||
312 | * @return string |
||
313 | */ |
||
314 | private function getAssetUrl(string $url, string $version): string |
||
330 | |||
331 | /** |
||
332 | * Load meta onto product. |
||
333 | * |
||
334 | * @param string $version Version to load configuration from. (optional) |
||
335 | * |
||
336 | * @throws Exception if meta file could not be parsed |
||
337 | */ |
||
338 | private function loadMeta(string $version = null): void |
||
369 | |||
370 | /** |
||
371 | * Load product versions. |
||
372 | */ |
||
373 | private function loadVersions(): void |
||
396 | } |
||
397 |
This check looks for accesses to local static members using the fully qualified name instead of
self::
.While this is perfectly valid, the fully qualified name of
Certificate::TRIPLEDES_CBC
could just as well be replaced byself::TRIPLEDES_CBC
. Referencing local members withself::
assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.