@@ -1,18 +1,18 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - 'app' => [ |
|
| 5 | - 'dialogs' => [ |
|
| 6 | - 'default' => [ |
|
| 7 | - 'confirm' => TestDialogLibrary::NAME, |
|
| 8 | - ], |
|
| 9 | - 'lib' => [ |
|
| 10 | - 'ext' => [ |
|
| 11 | - TestDialogLibrary::NAME => TestDialogLibrary::class, |
|
| 12 | - ], |
|
| 13 | - ], |
|
| 14 | - ], |
|
| 15 | - ], |
|
| 16 | - 'lib' => [ |
|
| 4 | +'app' => [ |
|
| 5 | +'dialogs' => [ |
|
| 6 | +'default' => [ |
|
| 7 | + 'confirm' => TestDialogLibrary::NAME, |
|
| 8 | +], |
|
| 9 | +'lib' => [ |
|
| 10 | + 'ext' => [ |
|
| 11 | + TestDialogLibrary::NAME => TestDialogLibrary::class, |
|
| 17 | 12 | ], |
| 13 | +], |
|
| 14 | +], |
|
| 15 | +], |
|
| 16 | +'lib' => [ |
|
| 17 | +], |
|
| 18 | 18 | ]; |
@@ -55,13 +55,13 @@ discard block |
||
| 55 | 55 | Dialog\Library\Butterup::class, // Butterup |
| 56 | 56 | Dialog\Library\IziToast::class, // IziToast |
| 57 | 57 | ]; |
| 58 | - foreach($aLibraries as $sClass) |
|
| 58 | + foreach ($aLibraries as $sClass) |
|
| 59 | 59 | { |
| 60 | 60 | try |
| 61 | 61 | { |
| 62 | 62 | $xDialog->registerLibrary($sClass, $sClass::NAME); |
| 63 | 63 | } |
| 64 | - catch(SetupException $_){} |
|
| 64 | + catch (SetupException $_) {} |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | return $xDialog; |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | function register(): void |
| 80 | 80 | { |
| 81 | 81 | // Do nothing if running in cli. |
| 82 | - if(php_sapi_name() !== 'cli') |
|
| 82 | + if (php_sapi_name() !== 'cli') |
|
| 83 | 83 | { |
| 84 | 84 | _register(); |
| 85 | 85 | }; |
@@ -60,8 +60,7 @@ |
||
| 60 | 60 | try |
| 61 | 61 | { |
| 62 | 62 | $xDialog->registerLibrary($sClass, $sClass::NAME); |
| 63 | - } |
|
| 64 | - catch(SetupException $_){} |
|
| 63 | + } catch(SetupException $_){} |
|
| 65 | 64 | } |
| 66 | 65 | |
| 67 | 66 | return $xDialog; |
@@ -142,15 +142,15 @@ discard block |
||
| 142 | 142 | 'defaults' => $this->xConfigManager->getAppOption('dialogs.default', []), |
| 143 | 143 | ]; |
| 144 | 144 | $aLibrariesOptions = []; |
| 145 | - foreach($this->getLibraries() as $xLibrary) |
|
| 145 | + foreach ($this->getLibraries() as $xLibrary) |
|
| 146 | 146 | { |
| 147 | 147 | $aLibOptions = $xLibrary->helper()->getJsOptions(); |
| 148 | - if(count($aLibOptions) > 0) |
|
| 148 | + if (count($aLibOptions) > 0) |
|
| 149 | 149 | { |
| 150 | 150 | $aLibrariesOptions[$xLibrary->getName()] = $aLibOptions; |
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | - if(count($aLibrariesOptions) > 0) |
|
| 153 | + if (count($aLibrariesOptions) > 0) |
|
| 154 | 154 | { |
| 155 | 155 | $aOptions['options'] = $aLibrariesOptions; |
| 156 | 156 | } |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | $xJsCode->sJsBefore = $this->getConfigScript(); |
| 168 | 168 | |
| 169 | 169 | $aCodes = []; |
| 170 | - foreach($this->getHelpers() as $xHelper) |
|
| 170 | + foreach ($this->getHelpers() as $xHelper) |
|
| 171 | 171 | { |
| 172 | 172 | $aCodes[] = $xHelper->getScript(); |
| 173 | 173 | $xJsCode->aFiles = array_merge($xJsCode->aFiles, $xHelper->getFiles()); |
@@ -55,8 +55,7 @@ |
||
| 55 | 55 | */ |
| 56 | 56 | public function helper(): LibraryHelper |
| 57 | 57 | { |
| 58 | - return $this->xHelper ?: |
|
| 59 | - $this->xHelper = dialog()->getLibraryHelper($this->getName()); |
|
| 58 | + return $this->xHelper ?: $this->xHelper = dialog()->getLibraryHelper($this->getName()); |
|
| 60 | 59 | } |
| 61 | 60 | |
| 62 | 61 | /** |
@@ -110,8 +110,7 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | private function getAssetUri(string $sOption, string $sFile): ?string |
| 112 | 112 | { |
| 113 | - return !$this->hasOption($sOption) ? "{$this->sUri}/$sFile" : |
|
| 114 | - (trim($this->getOption($sOption)) ?: null); |
|
| 113 | + return !$this->hasOption($sOption) ? "{$this->sUri}/$sFile" : (trim($this->getOption($sOption)) ?: null); |
|
| 115 | 114 | } |
| 116 | 115 | |
| 117 | 116 | /** |
@@ -194,7 +193,7 @@ discard block |
||
| 194 | 193 | */ |
| 195 | 194 | public function getFiles(): array |
| 196 | 195 | { |
| 197 | - if(!$this->getLibOption('js.app.export', false)) |
|
| 196 | + if (!$this->getLibOption('js.app.export', false)) |
|
| 198 | 197 | { |
| 199 | 198 | return []; |
| 200 | 199 | } |
@@ -36,44 +36,44 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | class DialogManager implements ConfigListenerInterface, LibraryRegistryInterface |
| 38 | 38 | { |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * @var array |
| 41 | 41 | */ |
| 42 | - protected $aLibraries = []; |
|
| 42 | +protected $aLibraries = []; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | +/** |
|
| 45 | 45 | * The ConfirmInterface class name |
| 46 | 46 | * |
| 47 | 47 | * @var string |
| 48 | 48 | */ |
| 49 | - private $sConfirmLibrary = ''; |
|
| 49 | +private $sConfirmLibrary = ''; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | +/** |
|
| 52 | 52 | * The AlertInterface class name |
| 53 | 53 | * |
| 54 | 54 | * @var string |
| 55 | 55 | */ |
| 56 | - private $sAlertLibrary = ''; |
|
| 56 | +private $sAlertLibrary = ''; |
|
| 57 | 57 | |
| 58 | - /** |
|
| 58 | +/** |
|
| 59 | 59 | * The ModalInterface class name |
| 60 | 60 | * |
| 61 | 61 | * @var string |
| 62 | 62 | */ |
| 63 | - private $sModalLibrary = ''; |
|
| 63 | +private $sModalLibrary = ''; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 65 | +/** |
|
| 66 | 66 | * The constructor |
| 67 | 67 | * |
| 68 | 68 | * @param Container $di |
| 69 | 69 | * @param ConfigManager $xConfigManager |
| 70 | 70 | * @param Translator $xTranslator |
| 71 | 71 | */ |
| 72 | - public function __construct(private Container $di, |
|
| 73 | - private ConfigManager $xConfigManager, private Translator $xTranslator) |
|
| 74 | - {} |
|
| 72 | +public function __construct(private Container $di, |
|
| 73 | +private ConfigManager $xConfigManager, private Translator $xTranslator) |
|
| 74 | +{} |
|
| 75 | 75 | |
| 76 | - /** |
|
| 76 | +/** |
|
| 77 | 77 | * Register a javascript dialog library adapter. |
| 78 | 78 | * |
| 79 | 79 | * @param string $sClass |
@@ -81,20 +81,20 @@ discard block |
||
| 81 | 81 | * |
| 82 | 82 | * @return void |
| 83 | 83 | */ |
| 84 | - private function _registerLibrary(string $sClass, string $sLibraryName): void |
|
| 85 | - { |
|
| 86 | - $this->di->set($sClass, function($di) use($sClass) { |
|
| 87 | - return $di->make($sClass); |
|
| 88 | - }); |
|
| 89 | - $this->di->set("dialog_library_helper_$sLibraryName", function($di) use($sClass) { |
|
| 90 | - return new LibraryHelper($di->g($sClass), $di->g(ConfigManager::class), |
|
| 91 | - $di->g(TemplateEngine::class)); |
|
| 92 | - }); |
|
| 93 | - // Set the alias, so the libraries can be found by their names. |
|
| 94 | - $this->di->alias("dialog_library_$sLibraryName", $sClass); |
|
| 95 | - } |
|
| 84 | +private function _registerLibrary(string $sClass, string $sLibraryName): void |
|
| 85 | +{ |
|
| 86 | +$this->di->set($sClass, function($di) use($sClass) { |
|
| 87 | +return $di->make($sClass); |
|
| 88 | +}); |
|
| 89 | +$this->di->set("dialog_library_helper_$sLibraryName", function($di) use($sClass) { |
|
| 90 | +return new LibraryHelper($di->g($sClass), $di->g(ConfigManager::class), |
|
| 91 | + $di->g(TemplateEngine::class)); |
|
| 92 | +}); |
|
| 93 | +// Set the alias, so the libraries can be found by their names. |
|
| 94 | +$this->di->alias("dialog_library_$sLibraryName", $sClass); |
|
| 95 | +} |
|
| 96 | 96 | |
| 97 | - /** |
|
| 97 | +/** |
|
| 98 | 98 | * Register a javascript dialog library adapter. |
| 99 | 99 | * |
| 100 | 100 | * @param string $sClassName |
@@ -103,53 +103,53 @@ discard block |
||
| 103 | 103 | * @return void |
| 104 | 104 | * @throws SetupException |
| 105 | 105 | */ |
| 106 | - public function registerLibrary(string $sClassName, string $sLibraryName): void |
|
| 107 | - { |
|
| 108 | - if(isset($this->aLibraries[$sLibraryName])) |
|
| 109 | - { |
|
| 110 | - return; |
|
| 111 | - } |
|
| 112 | - if(!($aInterfaces = class_implements($sClassName))) |
|
| 113 | - { |
|
| 114 | - // The class is invalid. |
|
| 115 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 116 | - throw new SetupException($sMessage); |
|
| 117 | - } |
|
| 106 | +public function registerLibrary(string $sClassName, string $sLibraryName): void |
|
| 107 | +{ |
|
| 108 | +if(isset($this->aLibraries[$sLibraryName])) |
|
| 109 | +{ |
|
| 110 | +return; |
|
| 111 | +} |
|
| 112 | +if(!($aInterfaces = class_implements($sClassName))) |
|
| 113 | +{ |
|
| 114 | +// The class is invalid. |
|
| 115 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 116 | +throw new SetupException($sMessage); |
|
| 117 | +} |
|
| 118 | 118 | |
| 119 | - $bIsConfirm = in_array(ConfirmInterface::class, $aInterfaces); |
|
| 120 | - $bIsAlert = in_array(AlertInterface::class, $aInterfaces); |
|
| 121 | - $bIsModal = in_array(ModalInterface::class, $aInterfaces); |
|
| 122 | - if(!$bIsConfirm && !$bIsAlert && !$bIsModal) |
|
| 123 | - { |
|
| 124 | - // The class is invalid. |
|
| 125 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 126 | - throw new SetupException($sMessage); |
|
| 127 | - } |
|
| 119 | +$bIsConfirm = in_array(ConfirmInterface::class, $aInterfaces); |
|
| 120 | +$bIsAlert = in_array(AlertInterface::class, $aInterfaces); |
|
| 121 | +$bIsModal = in_array(ModalInterface::class, $aInterfaces); |
|
| 122 | +if(!$bIsConfirm && !$bIsAlert && !$bIsModal) |
|
| 123 | +{ |
|
| 124 | +// The class is invalid. |
|
| 125 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 126 | +throw new SetupException($sMessage); |
|
| 127 | +} |
|
| 128 | 128 | |
| 129 | - // Save the library |
|
| 130 | - $this->aLibraries[$sLibraryName] = [ |
|
| 131 | - 'confirm' => $bIsConfirm, |
|
| 132 | - 'alert' => $bIsAlert, |
|
| 133 | - 'modal' => $bIsModal, |
|
| 134 | - 'used' => false, |
|
| 135 | - ]; |
|
| 136 | - // Register the library class in the container |
|
| 137 | - $this->_registerLibrary($sClassName, $sLibraryName); |
|
| 138 | - } |
|
| 129 | +// Save the library |
|
| 130 | +$this->aLibraries[$sLibraryName] = [ |
|
| 131 | +'confirm' => $bIsConfirm, |
|
| 132 | +'alert' => $bIsAlert, |
|
| 133 | +'modal' => $bIsModal, |
|
| 134 | +'used' => false, |
|
| 135 | +]; |
|
| 136 | +// Register the library class in the container |
|
| 137 | +$this->_registerLibrary($sClassName, $sLibraryName); |
|
| 138 | +} |
|
| 139 | 139 | |
| 140 | - /** |
|
| 140 | +/** |
|
| 141 | 141 | * Get the dialog library helper |
| 142 | 142 | * |
| 143 | 143 | * @param string $sLibraryName |
| 144 | 144 | * |
| 145 | 145 | * @return LibraryHelper |
| 146 | 146 | */ |
| 147 | - public function getLibraryHelper(string $sLibraryName): LibraryHelper |
|
| 148 | - { |
|
| 149 | - return $this->di->g("dialog_library_helper_$sLibraryName"); |
|
| 150 | - } |
|
| 147 | +public function getLibraryHelper(string $sLibraryName): LibraryHelper |
|
| 148 | +{ |
|
| 149 | +return $this->di->g("dialog_library_helper_$sLibraryName"); |
|
| 150 | +} |
|
| 151 | 151 | |
| 152 | - /** |
|
| 152 | +/** |
|
| 153 | 153 | * Set the ConfirmInterface library |
| 154 | 154 | * |
| 155 | 155 | * @param string $sLibraryName The ConfirmInterface library name |
@@ -157,29 +157,29 @@ discard block |
||
| 157 | 157 | * @return void |
| 158 | 158 | * @throws SetupException |
| 159 | 159 | */ |
| 160 | - public function setConfirmLibrary(string $sLibraryName) |
|
| 161 | - { |
|
| 162 | - if(!isset($this->aLibraries[$sLibraryName]) || !$this->aLibraries[$sLibraryName]['confirm']) |
|
| 163 | - { |
|
| 164 | - $sMessage = $this->xTranslator->trans('errors.dialog.library', |
|
| 165 | - ['type' => 'confirm', 'name' => $sLibraryName]); |
|
| 166 | - throw new SetupException($sMessage); |
|
| 167 | - } |
|
| 168 | - $this->sConfirmLibrary = $sLibraryName; |
|
| 169 | - } |
|
| 160 | +public function setConfirmLibrary(string $sLibraryName) |
|
| 161 | +{ |
|
| 162 | +if(!isset($this->aLibraries[$sLibraryName]) || !$this->aLibraries[$sLibraryName]['confirm']) |
|
| 163 | +{ |
|
| 164 | +$sMessage = $this->xTranslator->trans('errors.dialog.library', |
|
| 165 | + ['type' => 'confirm', 'name' => $sLibraryName]); |
|
| 166 | +throw new SetupException($sMessage); |
|
| 167 | +} |
|
| 168 | +$this->sConfirmLibrary = $sLibraryName; |
|
| 169 | +} |
|
| 170 | 170 | |
| 171 | - /** |
|
| 171 | +/** |
|
| 172 | 172 | * Get the ConfirmInterface library |
| 173 | 173 | * |
| 174 | 174 | * @return ConfirmInterface |
| 175 | 175 | */ |
| 176 | - public function getConfirmLibrary(): ConfirmInterface |
|
| 177 | - { |
|
| 178 | - $sKey = "dialog_library_{$this->sConfirmLibrary}"; |
|
| 179 | - return $this->di->h($sKey) ? $this->di->g($sKey) : $this->di->g(Alert::class); |
|
| 180 | - } |
|
| 176 | +public function getConfirmLibrary(): ConfirmInterface |
|
| 177 | +{ |
|
| 178 | +$sKey = "dialog_library_{$this->sConfirmLibrary}"; |
|
| 179 | +return $this->di->h($sKey) ? $this->di->g($sKey) : $this->di->g(Alert::class); |
|
| 180 | +} |
|
| 181 | 181 | |
| 182 | - /** |
|
| 182 | +/** |
|
| 183 | 183 | * Set AlertInterface library |
| 184 | 184 | * |
| 185 | 185 | * @param string $sLibraryName The AlertInterface library name |
@@ -187,29 +187,29 @@ discard block |
||
| 187 | 187 | * @return void |
| 188 | 188 | * @throws SetupException |
| 189 | 189 | */ |
| 190 | - public function setAlertLibrary(string $sLibraryName): void |
|
| 191 | - { |
|
| 192 | - if(!isset($this->aLibraries[$sLibraryName]) || !$this->aLibraries[$sLibraryName]['alert']) |
|
| 193 | - { |
|
| 194 | - $sMessage = $this->xTranslator->trans('errors.dialog.library', |
|
| 195 | - ['type' => 'alert', 'name' => $sLibraryName]); |
|
| 196 | - throw new SetupException($sMessage); |
|
| 197 | - } |
|
| 198 | - $this->sAlertLibrary = $sLibraryName; |
|
| 199 | - } |
|
| 190 | +public function setAlertLibrary(string $sLibraryName): void |
|
| 191 | +{ |
|
| 192 | +if(!isset($this->aLibraries[$sLibraryName]) || !$this->aLibraries[$sLibraryName]['alert']) |
|
| 193 | +{ |
|
| 194 | +$sMessage = $this->xTranslator->trans('errors.dialog.library', |
|
| 195 | + ['type' => 'alert', 'name' => $sLibraryName]); |
|
| 196 | +throw new SetupException($sMessage); |
|
| 197 | +} |
|
| 198 | +$this->sAlertLibrary = $sLibraryName; |
|
| 199 | +} |
|
| 200 | 200 | |
| 201 | - /** |
|
| 201 | +/** |
|
| 202 | 202 | * Get the AlertInterface library |
| 203 | 203 | * |
| 204 | 204 | * @return AlertInterface |
| 205 | 205 | */ |
| 206 | - public function getAlertLibrary(): AlertInterface |
|
| 207 | - { |
|
| 208 | - $sKey = "dialog_library_{$this->sAlertLibrary}"; |
|
| 209 | - return $this->di->h($sKey) ? $this->di->g($sKey) : $this->di->g(Alert::class); |
|
| 210 | - } |
|
| 206 | +public function getAlertLibrary(): AlertInterface |
|
| 207 | +{ |
|
| 208 | +$sKey = "dialog_library_{$this->sAlertLibrary}"; |
|
| 209 | +return $this->di->h($sKey) ? $this->di->g($sKey) : $this->di->g(Alert::class); |
|
| 210 | +} |
|
| 211 | 211 | |
| 212 | - /** |
|
| 212 | +/** |
|
| 213 | 213 | * Set the ModalInterface library |
| 214 | 214 | * |
| 215 | 215 | * @param string $sLibraryName The ModalInterface library name |
@@ -217,137 +217,137 @@ discard block |
||
| 217 | 217 | * @return void |
| 218 | 218 | * @throws SetupException |
| 219 | 219 | */ |
| 220 | - public function setModalLibrary(string $sLibraryName): void |
|
| 221 | - { |
|
| 222 | - if(!isset($this->aLibraries[$sLibraryName]) || !$this->aLibraries[$sLibraryName]['modal']) |
|
| 223 | - { |
|
| 224 | - $sMessage = $this->xTranslator->trans('errors.dialog.library', |
|
| 225 | - ['type' => 'modal', 'name' => $sLibraryName]); |
|
| 226 | - throw new SetupException($sMessage); |
|
| 227 | - } |
|
| 228 | - $this->sModalLibrary = $sLibraryName; |
|
| 229 | - } |
|
| 220 | +public function setModalLibrary(string $sLibraryName): void |
|
| 221 | +{ |
|
| 222 | +if(!isset($this->aLibraries[$sLibraryName]) || !$this->aLibraries[$sLibraryName]['modal']) |
|
| 223 | +{ |
|
| 224 | +$sMessage = $this->xTranslator->trans('errors.dialog.library', |
|
| 225 | + ['type' => 'modal', 'name' => $sLibraryName]); |
|
| 226 | +throw new SetupException($sMessage); |
|
| 227 | +} |
|
| 228 | +$this->sModalLibrary = $sLibraryName; |
|
| 229 | +} |
|
| 230 | 230 | |
| 231 | - /** |
|
| 231 | +/** |
|
| 232 | 232 | * Get the ModalInterface library |
| 233 | 233 | * |
| 234 | 234 | * @return ModalInterface|null |
| 235 | 235 | */ |
| 236 | - public function getModalLibrary(): ?ModalInterface |
|
| 237 | - { |
|
| 238 | - $sKey = "dialog_library_{$this->sModalLibrary}"; |
|
| 239 | - return $this->di->h($sKey) ? $this->di->g($sKey) : null; |
|
| 240 | - } |
|
| 236 | +public function getModalLibrary(): ?ModalInterface |
|
| 237 | +{ |
|
| 238 | +$sKey = "dialog_library_{$this->sModalLibrary}"; |
|
| 239 | +return $this->di->h($sKey) ? $this->di->g($sKey) : null; |
|
| 240 | +} |
|
| 241 | 241 | |
| 242 | - /** |
|
| 242 | +/** |
|
| 243 | 243 | * Register the javascript dialog libraries from config options. |
| 244 | 244 | * |
| 245 | 245 | * @return void |
| 246 | 246 | * @throws SetupException |
| 247 | 247 | */ |
| 248 | - protected function registerLibraries(): void |
|
| 249 | - { |
|
| 250 | - $aLibraries = $this->xConfigManager->getAppOption('dialogs.lib.ext', []); |
|
| 251 | - foreach($aLibraries as $sLibraryName => $sClassName) |
|
| 252 | - { |
|
| 253 | - $this->registerLibrary($sClassName, $sLibraryName); |
|
| 254 | - } |
|
| 255 | - } |
|
| 248 | +protected function registerLibraries(): void |
|
| 249 | +{ |
|
| 250 | +$aLibraries = $this->xConfigManager->getAppOption('dialogs.lib.ext', []); |
|
| 251 | +foreach($aLibraries as $sLibraryName => $sClassName) |
|
| 252 | +{ |
|
| 253 | +$this->registerLibrary($sClassName, $sLibraryName); |
|
| 254 | +} |
|
| 255 | +} |
|
| 256 | 256 | |
| 257 | - /** |
|
| 257 | +/** |
|
| 258 | 258 | * Set the default library for each dialog feature. |
| 259 | 259 | * |
| 260 | 260 | * @return void |
| 261 | 261 | * @throws SetupException |
| 262 | 262 | */ |
| 263 | - protected function setDefaultLibraries(): void |
|
| 264 | - { |
|
| 265 | - // Set the default modal library |
|
| 266 | - if(($sLibraryName = $this->xConfigManager->getAppOption('dialogs.default.modal', ''))) |
|
| 267 | - { |
|
| 268 | - $this->setModalLibrary($sLibraryName); |
|
| 269 | - $this->aLibraries[$sLibraryName]['used'] = true; |
|
| 270 | - } |
|
| 271 | - // Set the default alert library |
|
| 272 | - if(($sLibraryName = $this->xConfigManager->getAppOption('dialogs.default.alert', ''))) |
|
| 273 | - { |
|
| 274 | - $this->setAlertLibrary($sLibraryName); |
|
| 275 | - $this->aLibraries[$sLibraryName]['used'] = true; |
|
| 276 | - } |
|
| 277 | - // Set the default confirm library |
|
| 278 | - if(($sLibraryName = $this->xConfigManager->getAppOption('dialogs.default.confirm', ''))) |
|
| 279 | - { |
|
| 280 | - $this->setConfirmLibrary($sLibraryName); |
|
| 281 | - $this->aLibraries[$sLibraryName]['used'] = true; |
|
| 282 | - } |
|
| 283 | - } |
|
| 263 | +protected function setDefaultLibraries(): void |
|
| 264 | +{ |
|
| 265 | +// Set the default modal library |
|
| 266 | +if(($sLibraryName = $this->xConfigManager->getAppOption('dialogs.default.modal', ''))) |
|
| 267 | +{ |
|
| 268 | +$this->setModalLibrary($sLibraryName); |
|
| 269 | +$this->aLibraries[$sLibraryName]['used'] = true; |
|
| 270 | +} |
|
| 271 | +// Set the default alert library |
|
| 272 | +if(($sLibraryName = $this->xConfigManager->getAppOption('dialogs.default.alert', ''))) |
|
| 273 | +{ |
|
| 274 | +$this->setAlertLibrary($sLibraryName); |
|
| 275 | +$this->aLibraries[$sLibraryName]['used'] = true; |
|
| 276 | +} |
|
| 277 | +// Set the default confirm library |
|
| 278 | +if(($sLibraryName = $this->xConfigManager->getAppOption('dialogs.default.confirm', ''))) |
|
| 279 | +{ |
|
| 280 | +$this->setConfirmLibrary($sLibraryName); |
|
| 281 | +$this->aLibraries[$sLibraryName]['used'] = true; |
|
| 282 | +} |
|
| 283 | +} |
|
| 284 | 284 | |
| 285 | - /** |
|
| 285 | +/** |
|
| 286 | 286 | * Set the libraries in use. |
| 287 | 287 | * |
| 288 | 288 | * @return void |
| 289 | 289 | */ |
| 290 | - protected function setUsedLibraries(): void |
|
| 291 | - { |
|
| 292 | - // Set the other libraries in use |
|
| 293 | - $aLibraries = $this->xConfigManager->getAppOption('dialogs.lib.use', []); |
|
| 294 | - foreach($aLibraries as $sLibraryName) |
|
| 295 | - { |
|
| 296 | - if(isset($this->aLibraries[$sLibraryName])) // Make sure the library exists |
|
| 297 | - { |
|
| 298 | - $this->aLibraries[$sLibraryName]['used'] = true; |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - } |
|
| 290 | +protected function setUsedLibraries(): void |
|
| 291 | +{ |
|
| 292 | +// Set the other libraries in use |
|
| 293 | +$aLibraries = $this->xConfigManager->getAppOption('dialogs.lib.use', []); |
|
| 294 | +foreach($aLibraries as $sLibraryName) |
|
| 295 | +{ |
|
| 296 | +if(isset($this->aLibraries[$sLibraryName])) // Make sure the library exists |
|
| 297 | +{ |
|
| 298 | + $this->aLibraries[$sLibraryName]['used'] = true; |
|
| 299 | +} |
|
| 300 | +} |
|
| 301 | +} |
|
| 302 | 302 | |
| 303 | - /** |
|
| 303 | +/** |
|
| 304 | 304 | * Get the dialog libraries class instances |
| 305 | 305 | * |
| 306 | 306 | * @return LibraryInterface[] |
| 307 | 307 | */ |
| 308 | - public function getLibraries(): array |
|
| 309 | - { |
|
| 310 | - // Reset the default libraries any time the config is changed. |
|
| 311 | - $this->registerLibraries(); |
|
| 312 | - $this->setDefaultLibraries(); |
|
| 313 | - $this->setUsedLibraries(); |
|
| 308 | +public function getLibraries(): array |
|
| 309 | +{ |
|
| 310 | +// Reset the default libraries any time the config is changed. |
|
| 311 | +$this->registerLibraries(); |
|
| 312 | +$this->setDefaultLibraries(); |
|
| 313 | +$this->setUsedLibraries(); |
|
| 314 | 314 | |
| 315 | - // Only return the libraries that are used. |
|
| 316 | - $aLibraries = array_filter($this->aLibraries, function($aLibrary) { |
|
| 317 | - return $aLibrary['used']; |
|
| 318 | - }); |
|
| 319 | - return array_map(function($sLibraryName) { |
|
| 320 | - return $this->di->g("dialog_library_$sLibraryName"); |
|
| 321 | - }, array_keys($aLibraries)); |
|
| 322 | - } |
|
| 315 | +// Only return the libraries that are used. |
|
| 316 | +$aLibraries = array_filter($this->aLibraries, function($aLibrary) { |
|
| 317 | +return $aLibrary['used']; |
|
| 318 | +}); |
|
| 319 | +return array_map(function($sLibraryName) { |
|
| 320 | +return $this->di->g("dialog_library_$sLibraryName"); |
|
| 321 | +}, array_keys($aLibraries)); |
|
| 322 | +} |
|
| 323 | 323 | |
| 324 | - /** |
|
| 324 | +/** |
|
| 325 | 325 | * @inheritDoc |
| 326 | 326 | * @throws SetupException |
| 327 | 327 | */ |
| 328 | - public function onChange(Config $xConfig, string $sName): void |
|
| 329 | - { |
|
| 330 | - if($sName === '') |
|
| 331 | - { |
|
| 332 | - // Reset the default libraries any time the config is changed. |
|
| 333 | - $this->registerLibraries(); |
|
| 334 | - $this->setDefaultLibraries(); |
|
| 335 | - $this->setUsedLibraries(); |
|
| 336 | - return; |
|
| 337 | - } |
|
| 338 | - $sPrefix = substr($sName, 0, 15); |
|
| 339 | - switch($sPrefix) |
|
| 340 | - { |
|
| 341 | - case 'dialogs.default': |
|
| 342 | - $this->setDefaultLibraries(); |
|
| 343 | - return; |
|
| 344 | - case 'dialogs.lib.ext': |
|
| 345 | - $this->registerLibraries(); |
|
| 346 | - return; |
|
| 347 | - case 'dialogs.lib.use': |
|
| 348 | - $this->setUsedLibraries(); |
|
| 349 | - return; |
|
| 350 | - default: |
|
| 351 | - } |
|
| 328 | +public function onChange(Config $xConfig, string $sName): void |
|
| 329 | +{ |
|
| 330 | +if($sName === '') |
|
| 331 | +{ |
|
| 332 | +// Reset the default libraries any time the config is changed. |
|
| 333 | +$this->registerLibraries(); |
|
| 334 | +$this->setDefaultLibraries(); |
|
| 335 | +$this->setUsedLibraries(); |
|
| 336 | +return; |
|
| 337 | +} |
|
| 338 | +$sPrefix = substr($sName, 0, 15); |
|
| 339 | +switch($sPrefix) |
|
| 340 | +{ |
|
| 341 | +case 'dialogs.default': |
|
| 342 | +$this->setDefaultLibraries(); |
|
| 343 | +return; |
|
| 344 | +case 'dialogs.lib.ext': |
|
| 345 | +$this->registerLibraries(); |
|
| 346 | +return; |
|
| 347 | +case 'dialogs.lib.use': |
|
| 348 | +$this->setUsedLibraries(); |
|
| 349 | +return; |
|
| 350 | +default: |
|
| 351 | +} |
|
| 352 | 352 | } |
| 353 | 353 | } |
@@ -105,11 +105,11 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | public function registerLibrary(string $sClassName, string $sLibraryName): void |
| 107 | 107 | { |
| 108 | - if(isset($this->aLibraries[$sLibraryName])) |
|
| 108 | + if (isset($this->aLibraries[$sLibraryName])) |
|
| 109 | 109 | { |
| 110 | 110 | return; |
| 111 | 111 | } |
| 112 | - if(!($aInterfaces = class_implements($sClassName))) |
|
| 112 | + if (!($aInterfaces = class_implements($sClassName))) |
|
| 113 | 113 | { |
| 114 | 114 | // The class is invalid. |
| 115 | 115 | $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | $bIsConfirm = in_array(ConfirmInterface::class, $aInterfaces); |
| 120 | 120 | $bIsAlert = in_array(AlertInterface::class, $aInterfaces); |
| 121 | 121 | $bIsModal = in_array(ModalInterface::class, $aInterfaces); |
| 122 | - if(!$bIsConfirm && !$bIsAlert && !$bIsModal) |
|
| 122 | + if (!$bIsConfirm && !$bIsAlert && !$bIsModal) |
|
| 123 | 123 | { |
| 124 | 124 | // The class is invalid. |
| 125 | 125 | $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | public function setConfirmLibrary(string $sLibraryName) |
| 161 | 161 | { |
| 162 | - if(!isset($this->aLibraries[$sLibraryName]) || !$this->aLibraries[$sLibraryName]['confirm']) |
|
| 162 | + if (!isset($this->aLibraries[$sLibraryName]) || !$this->aLibraries[$sLibraryName]['confirm']) |
|
| 163 | 163 | { |
| 164 | 164 | $sMessage = $this->xTranslator->trans('errors.dialog.library', |
| 165 | 165 | ['type' => 'confirm', 'name' => $sLibraryName]); |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | */ |
| 190 | 190 | public function setAlertLibrary(string $sLibraryName): void |
| 191 | 191 | { |
| 192 | - if(!isset($this->aLibraries[$sLibraryName]) || !$this->aLibraries[$sLibraryName]['alert']) |
|
| 192 | + if (!isset($this->aLibraries[$sLibraryName]) || !$this->aLibraries[$sLibraryName]['alert']) |
|
| 193 | 193 | { |
| 194 | 194 | $sMessage = $this->xTranslator->trans('errors.dialog.library', |
| 195 | 195 | ['type' => 'alert', 'name' => $sLibraryName]); |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | */ |
| 220 | 220 | public function setModalLibrary(string $sLibraryName): void |
| 221 | 221 | { |
| 222 | - if(!isset($this->aLibraries[$sLibraryName]) || !$this->aLibraries[$sLibraryName]['modal']) |
|
| 222 | + if (!isset($this->aLibraries[$sLibraryName]) || !$this->aLibraries[$sLibraryName]['modal']) |
|
| 223 | 223 | { |
| 224 | 224 | $sMessage = $this->xTranslator->trans('errors.dialog.library', |
| 225 | 225 | ['type' => 'modal', 'name' => $sLibraryName]); |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | protected function registerLibraries(): void |
| 249 | 249 | { |
| 250 | 250 | $aLibraries = $this->xConfigManager->getAppOption('dialogs.lib.ext', []); |
| 251 | - foreach($aLibraries as $sLibraryName => $sClassName) |
|
| 251 | + foreach ($aLibraries as $sLibraryName => $sClassName) |
|
| 252 | 252 | { |
| 253 | 253 | $this->registerLibrary($sClassName, $sLibraryName); |
| 254 | 254 | } |
@@ -263,19 +263,19 @@ discard block |
||
| 263 | 263 | protected function setDefaultLibraries(): void |
| 264 | 264 | { |
| 265 | 265 | // Set the default modal library |
| 266 | - if(($sLibraryName = $this->xConfigManager->getAppOption('dialogs.default.modal', ''))) |
|
| 266 | + if (($sLibraryName = $this->xConfigManager->getAppOption('dialogs.default.modal', ''))) |
|
| 267 | 267 | { |
| 268 | 268 | $this->setModalLibrary($sLibraryName); |
| 269 | 269 | $this->aLibraries[$sLibraryName]['used'] = true; |
| 270 | 270 | } |
| 271 | 271 | // Set the default alert library |
| 272 | - if(($sLibraryName = $this->xConfigManager->getAppOption('dialogs.default.alert', ''))) |
|
| 272 | + if (($sLibraryName = $this->xConfigManager->getAppOption('dialogs.default.alert', ''))) |
|
| 273 | 273 | { |
| 274 | 274 | $this->setAlertLibrary($sLibraryName); |
| 275 | 275 | $this->aLibraries[$sLibraryName]['used'] = true; |
| 276 | 276 | } |
| 277 | 277 | // Set the default confirm library |
| 278 | - if(($sLibraryName = $this->xConfigManager->getAppOption('dialogs.default.confirm', ''))) |
|
| 278 | + if (($sLibraryName = $this->xConfigManager->getAppOption('dialogs.default.confirm', ''))) |
|
| 279 | 279 | { |
| 280 | 280 | $this->setConfirmLibrary($sLibraryName); |
| 281 | 281 | $this->aLibraries[$sLibraryName]['used'] = true; |
@@ -291,9 +291,9 @@ discard block |
||
| 291 | 291 | { |
| 292 | 292 | // Set the other libraries in use |
| 293 | 293 | $aLibraries = $this->xConfigManager->getAppOption('dialogs.lib.use', []); |
| 294 | - foreach($aLibraries as $sLibraryName) |
|
| 294 | + foreach ($aLibraries as $sLibraryName) |
|
| 295 | 295 | { |
| 296 | - if(isset($this->aLibraries[$sLibraryName])) // Make sure the library exists |
|
| 296 | + if (isset($this->aLibraries[$sLibraryName])) // Make sure the library exists |
|
| 297 | 297 | { |
| 298 | 298 | $this->aLibraries[$sLibraryName]['used'] = true; |
| 299 | 299 | } |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | */ |
| 328 | 328 | public function onChange(Config $xConfig, string $sName): void |
| 329 | 329 | { |
| 330 | - if($sName === '') |
|
| 330 | + if ($sName === '') |
|
| 331 | 331 | { |
| 332 | 332 | // Reset the default libraries any time the config is changed. |
| 333 | 333 | $this->registerLibraries(); |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | return; |
| 337 | 337 | } |
| 338 | 338 | $sPrefix = substr($sName, 0, 15); |
| 339 | - switch($sPrefix) |
|
| 339 | + switch ($sPrefix) |
|
| 340 | 340 | { |
| 341 | 341 | case 'dialogs.default': |
| 342 | 342 | $this->setDefaultLibraries(); |
@@ -293,10 +293,12 @@ |
||
| 293 | 293 | $aLibraries = $this->xConfigManager->getAppOption('dialogs.lib.use', []); |
| 294 | 294 | foreach($aLibraries as $sLibraryName) |
| 295 | 295 | { |
| 296 | - if(isset($this->aLibraries[$sLibraryName])) // Make sure the library exists |
|
| 296 | + if(isset($this->aLibraries[$sLibraryName])) { |
|
| 297 | + // Make sure the library exists |
|
| 297 | 298 | { |
| 298 | 299 | $this->aLibraries[$sLibraryName]['used'] = true; |
| 299 | 300 | } |
| 301 | + } |
|
| 300 | 302 | } |
| 301 | 303 | } |
| 302 | 304 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | public function point($iXaxis, $sLabel): static |
| 55 | 55 | { |
| 56 | 56 | $this->aPoints[] = $iXaxis; |
| 57 | - if(!$this->aLabels['data']) |
|
| 57 | + if (!$this->aLabels['data']) |
|
| 58 | 58 | { |
| 59 | 59 | $this->aLabels['data'] = []; |
| 60 | 60 | } |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function points($aPoints): int |
| 73 | 73 | { |
| 74 | - foreach($aPoints as $aPoint) |
|
| 74 | + foreach ($aPoints as $aPoint) |
|
| 75 | 75 | { |
| 76 | - if(count($aPoint) == 2) |
|
| 76 | + if (count($aPoint) == 2) |
|
| 77 | 77 | { |
| 78 | 78 | $this->point($aPoint[0], $aPoint[1]); |
| 79 | 79 | } |
@@ -96,11 +96,11 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | public function expr($iStart, $iEnd, $iStep, $sJsLabel): int |
| 98 | 98 | { |
| 99 | - for($x = $iStart; $x < $iEnd; $x += $iStep) |
|
| 99 | + for ($x = $iStart; $x < $iEnd; $x += $iStep) |
|
| 100 | 100 | { |
| 101 | 101 | $this->aPoints[] = $x; |
| 102 | 102 | } |
| 103 | - if(($sJsLabel)) |
|
| 103 | + if (($sJsLabel)) |
|
| 104 | 104 | { |
| 105 | 105 | $this->aLabels['func'] = $sJsLabel; |
| 106 | 106 | } |
@@ -61,14 +61,14 @@ discard block |
||
| 61 | 61 | public function point($iXaxis, $xValue, $sLabel = ''): static |
| 62 | 62 | { |
| 63 | 63 | $this->aPoints[] = $iXaxis; |
| 64 | - if(!$this->aValues['data']) |
|
| 64 | + if (!$this->aValues['data']) |
|
| 65 | 65 | { |
| 66 | 66 | $this->aValues['data'] = []; |
| 67 | 67 | } |
| 68 | 68 | $this->aValues['data'][$iXaxis] = $xValue; |
| 69 | - if(($sLabel)) |
|
| 69 | + if (($sLabel)) |
|
| 70 | 70 | { |
| 71 | - if(!$this->aLabels['data']) |
|
| 71 | + if (!$this->aLabels['data']) |
|
| 72 | 72 | { |
| 73 | 73 | $this->aLabels['data'] = []; |
| 74 | 74 | } |
@@ -86,13 +86,13 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public function points($aPoints): int |
| 88 | 88 | { |
| 89 | - foreach($aPoints as $aPoint) |
|
| 89 | + foreach ($aPoints as $aPoint) |
|
| 90 | 90 | { |
| 91 | - if(count($aPoint) === 2) |
|
| 91 | + if (count($aPoint) === 2) |
|
| 92 | 92 | { |
| 93 | 93 | $this->point($aPoint[0], $aPoint[1]); |
| 94 | 94 | } |
| 95 | - else if(count($aPoint) === 3) |
|
| 95 | + else if (count($aPoint) === 3) |
|
| 96 | 96 | { |
| 97 | 97 | $this->point($aPoint[0], $aPoint[1], $aPoint[2]); |
| 98 | 98 | } |
@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | public function expr($iStart, $iEnd, $iStep, $sJsValue, $sJsLabel = ''): int |
| 120 | 120 | { |
| 121 | - for($x = $iStart; $x < $iEnd; $x += $iStep) |
|
| 121 | + for ($x = $iStart; $x < $iEnd; $x += $iStep) |
|
| 122 | 122 | { |
| 123 | 123 | $this->aPoints[] = $x; |
| 124 | 124 | } |
| 125 | 125 | $this->aValues['func'] = $sJsValue; |
| 126 | - if(($sJsLabel)) |
|
| 126 | + if (($sJsLabel)) |
|
| 127 | 127 | { |
| 128 | 128 | $this->aLabels['func'] = $sJsLabel; |
| 129 | 129 | } |
@@ -91,8 +91,7 @@ |
||
| 91 | 91 | if(count($aPoint) === 2) |
| 92 | 92 | { |
| 93 | 93 | $this->point($aPoint[0], $aPoint[1]); |
| 94 | - } |
|
| 95 | - else if(count($aPoint) === 3) |
|
| 94 | + } else if(count($aPoint) === 3) |
|
| 96 | 95 | { |
| 97 | 96 | $this->point($aPoint[0], $aPoint[1], $aPoint[2]); |
| 98 | 97 | } |
@@ -75,8 +75,7 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public function getScript(): string |
| 77 | 77 | { |
| 78 | - return $this->xConfigManager->getOption('js.app.export', false) ? '' : |
|
| 79 | - $this->xTemplateEngine->render('jaxon::flot::flot.js'); |
|
| 78 | + return $this->xConfigManager->getOption('js.app.export', false) ? '' : $this->xTemplateEngine->render('jaxon::flot::flot.js'); |
|
| 80 | 79 | } |
| 81 | 80 | |
| 82 | 81 | /** |
@@ -84,7 +83,7 @@ discard block |
||
| 84 | 83 | */ |
| 85 | 84 | public function getJsCode(): ?JsCode |
| 86 | 85 | { |
| 87 | - if(!$this->xConfigManager->getOption('js.app.export', false)) |
|
| 86 | + if (!$this->xConfigManager->getOption('js.app.export', false)) |
|
| 88 | 87 | { |
| 89 | 88 | return null; |
| 90 | 89 | } |