|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Docsets; |
|
4
|
|
|
|
|
5
|
|
|
use App\Contracts\Docset; |
|
6
|
|
|
use Illuminate\Support\Collection; |
|
7
|
|
|
use Illuminate\Support\Facades\Storage; |
|
8
|
|
|
|
|
9
|
|
|
abstract class BaseDocset implements Docset |
|
10
|
|
|
{ |
|
11
|
|
|
public const CODE = self::CODE; |
|
12
|
|
|
public const NAME = self::NAME; |
|
13
|
|
|
public const URL = self::URL; |
|
14
|
|
|
public const INDEX = self::INDEX; |
|
15
|
|
|
public const PLAYGROUND = self::PLAYGROUND; |
|
16
|
|
|
public const ICON_16 = self::ICON_16; |
|
17
|
|
|
public const ICON_32 = self::ICON_32; |
|
18
|
|
|
public const EXTERNAL_DOMAINS = self::EXTERNAL_DOMAINS; |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
3 |
|
final public function code(): string |
|
22
|
|
|
{ |
|
23
|
3 |
|
return static::CODE; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
2 |
|
final public function name(): string |
|
27
|
|
|
{ |
|
28
|
2 |
|
return static::NAME; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
2 |
|
final public function url(): string |
|
32
|
|
|
{ |
|
33
|
2 |
|
return static::URL; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
2 |
|
final public function index(): string |
|
37
|
|
|
{ |
|
38
|
2 |
|
return static::INDEX; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
2 |
|
final public function playground(): string |
|
42
|
|
|
{ |
|
43
|
2 |
|
return static::PLAYGROUND; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
2 |
|
final public function icon16(): string |
|
47
|
|
|
{ |
|
48
|
2 |
|
return static::ICON_16; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
2 |
|
final public function icon32(): string |
|
52
|
|
|
{ |
|
53
|
2 |
|
return static::ICON_32; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
1 |
|
final public function externalDomains(): string |
|
57
|
|
|
{ |
|
58
|
1 |
|
return implode( |
|
59
|
1 |
|
',', |
|
60
|
1 |
|
array_merge((array) static::URL, (array) static::EXTERNAL_DOMAINS) |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
34 |
|
final public function file(): string |
|
65
|
|
|
{ |
|
66
|
34 |
|
return static::CODE . '/' . static::CODE . '.docset'; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
25 |
|
final public function innerDirectory(): string |
|
70
|
|
|
{ |
|
71
|
25 |
|
return self::file() . '/Contents/Resources/Documents'; |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
21 |
|
final public function innerIndex(): string |
|
75
|
|
|
{ |
|
76
|
21 |
|
return self::innerDirectory() . '/' . static::INDEX; |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
35 |
|
final public function downloadedDirectory(): string |
|
80
|
|
|
{ |
|
81
|
35 |
|
return static::CODE . '/docs/' . static::URL; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
21 |
|
final public function downloadedIndex(): string |
|
85
|
|
|
{ |
|
86
|
21 |
|
return self::downloadedDirectory() . '/' . static::INDEX; |
|
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
3 |
|
final public function infoPlistFile(): string |
|
90
|
|
|
{ |
|
91
|
3 |
|
return self::file() . '/Contents/Info.plist'; |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
8 |
|
final public function databaseFile(): string |
|
95
|
|
|
{ |
|
96
|
8 |
|
return self::file() . '/Contents/Resources/docSet.dsidx'; |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
2 |
|
final public function htmlFiles(): Collection |
|
100
|
|
|
{ |
|
101
|
2 |
|
$files = Storage::allFiles( |
|
102
|
2 |
|
self::innerDirectory() |
|
|
|
|
|
|
103
|
|
|
); |
|
104
|
|
|
|
|
105
|
|
|
return collect($files)->reject(static function ($file) { |
|
106
|
2 |
|
return substr($file, -5) !== '.html'; |
|
107
|
2 |
|
}); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
abstract public function entries(string $html): Collection; |
|
111
|
|
|
|
|
112
|
|
|
abstract public function format(string $html): string; |
|
113
|
|
|
} |
|
114
|
|
|
|