|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* AbstractLibrary.php |
|
5
|
|
|
* |
|
6
|
|
|
* Base class for javascript dialog libraries. |
|
7
|
|
|
* |
|
8
|
|
|
* @package jaxon-dialogs |
|
9
|
|
|
* @author Thierry Feuzeu <[email protected]> |
|
10
|
|
|
* @copyright 2016 Thierry Feuzeu <[email protected]> |
|
11
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License |
|
12
|
|
|
* @link https://github.com/jaxon-php/jaxon-dialogs |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Jaxon\Dialogs\Dialog; |
|
16
|
|
|
|
|
17
|
|
|
use Jaxon\App\Dialog\Library\LibraryInterface; |
|
18
|
|
|
|
|
19
|
|
|
use function array_map; |
|
20
|
|
|
use function rtrim; |
|
21
|
|
|
use function Jaxon\Dialogs\dialog; |
|
22
|
|
|
|
|
23
|
|
|
abstract class AbstractLibrary implements LibraryInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* The dialog library helper |
|
27
|
|
|
* |
|
28
|
|
|
* @var LibraryHelper|null |
|
29
|
|
|
*/ |
|
30
|
|
|
private $xHelper = null; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The css files |
|
34
|
|
|
* |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $aCssFiles = []; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The js files |
|
41
|
|
|
* |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $aJsFiles = []; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Get the library name |
|
48
|
|
|
* |
|
49
|
|
|
* @return string |
|
50
|
|
|
*/ |
|
51
|
|
|
abstract public function getName(): string; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get the helper |
|
55
|
|
|
* |
|
56
|
|
|
* @return LibraryHelper |
|
57
|
|
|
*/ |
|
58
|
|
|
public function helper(): LibraryHelper |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->xHelper ??= dialog()->getLibraryHelper($this->getName()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get the library base URL |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getBaseUrl(): string |
|
69
|
|
|
{ |
|
70
|
|
|
return ''; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param string $sFile The javascript file name |
|
75
|
|
|
* |
|
76
|
|
|
* @return string|null |
|
77
|
|
|
*/ |
|
78
|
|
|
private function getFileUrl(string $sFile): ?string |
|
79
|
|
|
{ |
|
80
|
|
|
return rtrim($this->helper()->getBaseUrl(), '/') . "/$sFile"; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Get the CSS urls |
|
85
|
|
|
* |
|
86
|
|
|
* @return array |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getCssUrls(): array |
|
89
|
|
|
{ |
|
90
|
|
|
return array_map(fn($sFile) => $this->getFileUrl($sFile), $this->aCssFiles); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Get the CSS header code |
|
95
|
|
|
* |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getCssCode(): string |
|
99
|
|
|
{ |
|
100
|
|
|
return ''; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Get the javascript files |
|
105
|
|
|
* |
|
106
|
|
|
* @return array |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getJsUrls(): array |
|
109
|
|
|
{ |
|
110
|
|
|
return array_map(fn($sFile) => $this->getFileUrl($sFile), $this->aJsFiles); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Get the javascript code |
|
115
|
|
|
* |
|
116
|
|
|
* @return string |
|
117
|
|
|
*/ |
|
118
|
|
|
public function getJsCode(): string |
|
119
|
|
|
{ |
|
120
|
|
|
return dialog()->renderLibraryScript($this->getName()); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Get the options of the js library |
|
125
|
|
|
* |
|
126
|
|
|
* @return array |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getJsOptions(): array |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->helper()->getJsOptions(); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|