|
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
|
|
|
public function grab(): bool |
|
21
|
3 |
|
{ |
|
22
|
|
|
return false; |
|
23
|
3 |
|
} |
|
24
|
|
|
|
|
25
|
|
|
final public function code(): string |
|
26
|
2 |
|
{ |
|
27
|
|
|
return static::CODE; |
|
28
|
2 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
final public function name(): string |
|
31
|
32 |
|
{ |
|
32
|
|
|
return static::NAME; |
|
33
|
32 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
final public function url(): string |
|
36
|
2 |
|
{ |
|
37
|
|
|
return static::URL; |
|
38
|
2 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
final public function index(): string |
|
41
|
2 |
|
{ |
|
42
|
|
|
return static::URL . '/' . static::INDEX; |
|
43
|
2 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
final public function playground(): string |
|
46
|
2 |
|
{ |
|
47
|
|
|
return static::PLAYGROUND; |
|
48
|
2 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
final public function icon16(): string |
|
51
|
2 |
|
{ |
|
52
|
|
|
return static::URL . '/' . static::ICON_16; |
|
53
|
2 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
final public function icon32(): string |
|
56
|
1 |
|
{ |
|
57
|
|
|
return static::URL . '/' . static::ICON_32; |
|
58
|
1 |
|
} |
|
59
|
1 |
|
|
|
60
|
1 |
|
final public function externalDomains(): string |
|
61
|
|
|
{ |
|
62
|
|
|
return implode( |
|
63
|
|
|
',', |
|
64
|
37 |
|
array_merge((array) static::URL, (array) static::EXTERNAL_DOMAINS) |
|
65
|
|
|
); |
|
66
|
37 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
final public function file(): string |
|
69
|
29 |
|
{ |
|
70
|
|
|
return static::CODE . '/' . static::CODE . '.docset'; |
|
71
|
29 |
|
} |
|
72
|
|
|
|
|
73
|
|
|
final public function innerDirectory(): string |
|
74
|
23 |
|
{ |
|
75
|
|
|
return $this->file() . '/Contents/Resources/Documents'; |
|
76
|
23 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
final public function innerIndex(): string |
|
79
|
34 |
|
{ |
|
80
|
|
|
return $this->innerDirectory() . '/' . $this->url() . '/' . static::INDEX; |
|
81
|
34 |
|
} |
|
82
|
|
|
|
|
83
|
|
|
final public function downloadedDirectory(): string |
|
84
|
22 |
|
{ |
|
85
|
|
|
return static::CODE . '/docs'; |
|
86
|
22 |
|
} |
|
87
|
|
|
|
|
88
|
|
|
final public function downloadedIndex(): string |
|
89
|
3 |
|
{ |
|
90
|
|
|
return $this->downloadedDirectory() . '/' . $this->url() . '/' . static::INDEX; |
|
91
|
3 |
|
} |
|
92
|
|
|
|
|
93
|
|
|
final public function infoPlistFile(): string |
|
94
|
7 |
|
{ |
|
95
|
|
|
return $this->file() . '/Contents/Info.plist'; |
|
96
|
7 |
|
} |
|
97
|
|
|
|
|
98
|
|
|
final public function databaseFile(): string |
|
99
|
2 |
|
{ |
|
100
|
|
|
return $this->file() . '/Contents/Resources/docSet.dsidx'; |
|
101
|
2 |
|
} |
|
102
|
2 |
|
|
|
103
|
|
|
final public function htmlFiles(): Collection |
|
104
|
|
|
{ |
|
105
|
|
|
$files = Storage::allFiles( |
|
106
|
2 |
|
$this->innerDirectory() |
|
107
|
2 |
|
); |
|
108
|
|
|
|
|
109
|
|
|
return collect($files)->reject(static function ($file) { |
|
110
|
|
|
return substr($file, -5) !== '.html'; |
|
111
|
|
|
}); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
abstract public function entries(string $html): Collection; |
|
115
|
|
|
|
|
116
|
|
|
abstract public function format(string $html): string; |
|
117
|
|
|
} |
|
118
|
|
|
|