1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jaxon\Dialogs; |
4
|
|
|
|
5
|
|
|
use Jaxon\App\Config\ConfigManager; |
6
|
|
|
use Jaxon\App\Dialog\Manager\LibraryRegistryInterface; |
7
|
|
|
use Jaxon\App\I18n\Translator; |
8
|
|
|
use Jaxon\Dialogs\Dialog\Library\Alert; |
9
|
|
|
use Jaxon\Exception\SetupException; |
10
|
|
|
|
11
|
|
|
use function Jaxon\jaxon; |
12
|
|
|
use function php_sapi_name; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Get the dialog library manager |
16
|
|
|
* |
17
|
|
|
* @return DialogManager |
18
|
|
|
*/ |
19
|
|
|
function dialog(): DialogManager |
20
|
|
|
{ |
21
|
|
|
return jaxon()->di()->g(DialogManager::class); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
|
|
function _register() |
28
|
|
|
{ |
29
|
|
|
$jaxon = jaxon(); |
30
|
|
|
$xDi = $jaxon->di(); |
31
|
|
|
|
32
|
|
|
// Dialog library manager |
33
|
|
|
$xDi->set(DialogManager::class, function($di) { |
34
|
|
|
// Register the template dir into the template renderer |
35
|
|
|
jaxon()->template()->addNamespace('jaxon::dialogs', dirname(__DIR__) . '/js'); |
36
|
|
|
|
37
|
|
|
$xDialog = new DialogManager($di, $di->g(ConfigManager::class), $di->g(Translator::class)); |
38
|
|
|
// Register the provided libraries. |
39
|
|
|
$aLibraries = [ |
40
|
|
|
Dialog\Library\Alertify::class, // Alertify |
41
|
|
|
Dialog\Library\Bootbox::class, // Bootbox |
42
|
|
|
Dialog\Library\Bootstrap3::class, // Bootstrap 3 |
43
|
|
|
Dialog\Library\Bootstrap4::class, // Bootstrap 4 |
44
|
|
|
Dialog\Library\Bootstrap5::class, // Bootstrap 5 |
45
|
|
|
Dialog\Library\Toastr::class, // Toastr |
46
|
|
|
Dialog\Library\JAlert::class, // JAlert |
47
|
|
|
Dialog\Library\Tingle::class, // Tingle |
48
|
|
|
Dialog\Library\Noty::class, // Noty |
49
|
|
|
Dialog\Library\Notify::class, // Notify |
50
|
|
|
Dialog\Library\SweetAlert::class, // SweetAlert |
51
|
|
|
Dialog\Library\JQueryConfirm::class, // JQuery Confirm |
52
|
|
|
Dialog\Library\CuteAlert::class, // CuteAlert |
53
|
|
|
Dialog\Library\Notyf::class, // Notyf |
54
|
|
|
Dialog\Library\Quantum::class, // QuantumAlert |
55
|
|
|
Dialog\Library\Butterup::class, // Butterup |
56
|
|
|
Dialog\Library\IziToast::class, // IziToast |
57
|
|
|
]; |
58
|
|
|
foreach($aLibraries as $sClass) |
59
|
|
|
{ |
60
|
|
|
try |
61
|
|
|
{ |
62
|
|
|
$xDialog->registerLibrary($sClass, $sClass::NAME); |
63
|
|
|
} |
64
|
|
|
catch(SetupException $_){} |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $xDialog; |
68
|
|
|
}); |
69
|
|
|
|
70
|
|
|
$xDi->alias(LibraryRegistryInterface::class, DialogManager::class); |
71
|
|
|
$xDi->set(Alert::class, fn() => new Alert()); |
72
|
|
|
|
73
|
|
|
// Listener for app config changes. |
74
|
|
|
$jaxon->config()->addAppEventListener(DialogManager::class); |
75
|
|
|
// Register the plugin |
76
|
|
|
$jaxon->registerPlugin(DialogPlugin::class, DialogPlugin::NAME, 900); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
function register() |
80
|
|
|
{ |
81
|
|
|
// Do nothing if running in cli. |
82
|
|
|
if(php_sapi_name() !== 'cli') |
83
|
|
|
{ |
84
|
|
|
_register(); |
85
|
|
|
}; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
register(); |
89
|
|
|
|