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