@@ -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 | } |
@@ -175,62 +175,62 @@ |
||
| 175 | 175 | 0 => true, |
| 176 | 176 | 1 => isset($this->properties['attr']) || isset($this->properties['class']), |
| 177 | 177 | 2 => isset($this->properties['attr']) && isset($this->properties['class']), |
| 178 | - default => false, |
|
| 179 | - }; |
|
| 180 | - } |
|
| 178 | +default => false, |
|
| 179 | +}; |
|
| 180 | +} |
|
| 181 | 181 | |
| 182 | - /** |
|
| 182 | +/** |
|
| 183 | 183 | * @return void |
| 184 | 184 | * @throws AnnotationException |
| 185 | 185 | */ |
| 186 | - private function parseProperties() |
|
| 187 | - { |
|
| 188 | - if(!$this->checkPropertiesNames()) |
|
| 189 | - { |
|
| 190 | - throw new AnnotationException('The @di annotation accepts only "attr" or "class" as properties'); |
|
| 191 | - } |
|
| 186 | +private function parseProperties() |
|
| 187 | +{ |
|
| 188 | +if(!$this->checkPropertiesNames()) |
|
| 189 | +{ |
|
| 190 | +throw new AnnotationException('The @di annotation accepts only "attr" or "class" as properties'); |
|
| 191 | +} |
|
| 192 | 192 | |
| 193 | - if(isset($this->properties['attr'])) |
|
| 194 | - { |
|
| 195 | - if(self::$xReader->annotationIsOnProperty()) |
|
| 196 | - { |
|
| 197 | - throw new AnnotationException('The @di annotation does not allow the "attr" property on class attributes'); |
|
| 198 | - } |
|
| 199 | - if(!is_string($this->properties['attr'])) |
|
| 200 | - { |
|
| 201 | - throw new AnnotationException('The @di annotation requires a property "attr" of type string'); |
|
| 202 | - } |
|
| 203 | - $this->sAttr = $this->properties['attr']; |
|
| 204 | - } |
|
| 205 | - if(isset($this->properties['class'])) |
|
| 206 | - { |
|
| 207 | - if(!is_string($this->properties['class'])) |
|
| 208 | - { |
|
| 209 | - throw new AnnotationException('The @di annotation requires a property "class" of type string'); |
|
| 210 | - } |
|
| 211 | - $this->sClass = $this->getFullClassName($this->properties['class']); |
|
| 212 | - } |
|
| 213 | - } |
|
| 193 | +if(isset($this->properties['attr'])) |
|
| 194 | +{ |
|
| 195 | +if(self::$xReader->annotationIsOnProperty()) |
|
| 196 | +{ |
|
| 197 | + throw new AnnotationException('The @di annotation does not allow the "attr" property on class attributes'); |
|
| 198 | +} |
|
| 199 | +if(!is_string($this->properties['attr'])) |
|
| 200 | +{ |
|
| 201 | + throw new AnnotationException('The @di annotation requires a property "attr" of type string'); |
|
| 202 | +} |
|
| 203 | +$this->sAttr = $this->properties['attr']; |
|
| 204 | +} |
|
| 205 | +if(isset($this->properties['class'])) |
|
| 206 | +{ |
|
| 207 | +if(!is_string($this->properties['class'])) |
|
| 208 | +{ |
|
| 209 | + throw new AnnotationException('The @di annotation requires a property "class" of type string'); |
|
| 210 | +} |
|
| 211 | +$this->sClass = $this->getFullClassName($this->properties['class']); |
|
| 212 | +} |
|
| 213 | +} |
|
| 214 | 214 | |
| 215 | - /** |
|
| 215 | +/** |
|
| 216 | 216 | * @inheritDoc |
| 217 | 217 | */ |
| 218 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 219 | - { |
|
| 220 | - isset($this->properties['__value__']) ? $this->parseValue() : $this->parseProperties(); |
|
| 218 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 219 | +{ |
|
| 220 | +isset($this->properties['__value__']) ? $this->parseValue() : $this->parseProperties(); |
|
| 221 | 221 | |
| 222 | - // The type in the @di annotations can be set from the values in the @var annotations |
|
| 223 | - $aPropTypes = self::$xReader->getPropTypes(); |
|
| 224 | - if($this->sClass === '') |
|
| 225 | - { |
|
| 226 | - if(!isset($aPropTypes[$this->sAttr])) |
|
| 227 | - { |
|
| 228 | - throw new AnnotationException('No class defined for @di on attribute "' . |
|
| 229 | - $this->sAttr . '".'); |
|
| 230 | - } |
|
| 231 | - $this->sClass = ltrim($aPropTypes[$this->sAttr], '\\'); |
|
| 232 | - } |
|
| 222 | +// The type in the @di annotations can be set from the values in the @var annotations |
|
| 223 | +$aPropTypes = self::$xReader->getPropTypes(); |
|
| 224 | +if($this->sClass === '') |
|
| 225 | +{ |
|
| 226 | +if(!isset($aPropTypes[$this->sAttr])) |
|
| 227 | +{ |
|
| 228 | + throw new AnnotationException('No class defined for @di on attribute "' . |
|
| 229 | + $this->sAttr . '".'); |
|
| 230 | +} |
|
| 231 | +$this->sClass = ltrim($aPropTypes[$this->sAttr], '\\'); |
|
| 232 | +} |
|
| 233 | 233 | |
| 234 | - $xMetadata->container($sMethod)->addValue($this->sAttr, $this->sClass); |
|
| 235 | - } |
|
| 234 | +$xMetadata->container($sMethod)->addValue($this->sAttr, $this->sClass); |
|
| 235 | +} |
|
| 236 | 236 | } |
@@ -23,19 +23,19 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class AfterAnnotation extends HookAnnotation |
| 25 | 25 | { |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * @inheritDoc |
| 28 | 28 | */ |
| 29 | - protected static function getType(): string |
|
| 30 | - { |
|
| 31 | - return 'after'; |
|
| 32 | - } |
|
| 29 | +protected static function getType(): string |
|
| 30 | +{ |
|
| 31 | +return 'after'; |
|
| 32 | +} |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @inheritDoc |
| 36 | 36 | */ |
| 37 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 38 | - { |
|
| 39 | - $xMetadata->after($sMethod)->addCall($this->sMethod, $this->aParams); |
|
| 40 | - } |
|
| 37 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 38 | +{ |
|
| 39 | +$xMetadata->after($sMethod)->addCall($this->sMethod, $this->aParams); |
|
| 40 | +} |
|
| 41 | 41 | } |
@@ -28,40 +28,40 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class CallbackAnnotation extends AbstractAnnotation |
| 30 | 30 | { |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * The javascript object name |
| 33 | 33 | * |
| 34 | 34 | * @var string |
| 35 | 35 | */ |
| 36 | - protected $sJsObject; |
|
| 36 | +protected $sJsObject; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * @inheritDoc |
| 40 | 40 | */ |
| 41 | - public static function parseAnnotation($value) |
|
| 42 | - { |
|
| 43 | - $aParams = preg_split('/[\s]+/', $value, 2); |
|
| 44 | - return count($aParams) === 1 ? ['name' => $aParams[0]] : ['name' => $aParams[0], 'extra' => $aParams[1]]; |
|
| 45 | - } |
|
| 41 | +public static function parseAnnotation($value) |
|
| 42 | +{ |
|
| 43 | +$aParams = preg_split('/[\s]+/', $value, 2); |
|
| 44 | +return count($aParams) === 1 ? ['name' => $aParams[0]] : ['name' => $aParams[0], 'extra' => $aParams[1]]; |
|
| 45 | +} |
|
| 46 | 46 | |
| 47 | - /** |
|
| 47 | +/** |
|
| 48 | 48 | * @inheritDoc |
| 49 | 49 | * @throws AnnotationException |
| 50 | 50 | */ |
| 51 | - public function initAnnotation(array $properties) |
|
| 52 | - { |
|
| 53 | - if(count($properties) !== 1 || !isset($properties['name']) || !is_string($properties['name'])) |
|
| 54 | - { |
|
| 55 | - throw new AnnotationException('the @callback annotation requires a single string as property'); |
|
| 56 | - } |
|
| 57 | - $this->sJsObject = $properties['name']; |
|
| 58 | - } |
|
| 51 | +public function initAnnotation(array $properties) |
|
| 52 | +{ |
|
| 53 | +if(count($properties) !== 1 || !isset($properties['name']) || !is_string($properties['name'])) |
|
| 54 | +{ |
|
| 55 | +throw new AnnotationException('the @callback annotation requires a single string as property'); |
|
| 56 | +} |
|
| 57 | +$this->sJsObject = $properties['name']; |
|
| 58 | +} |
|
| 59 | 59 | |
| 60 | - /** |
|
| 60 | +/** |
|
| 61 | 61 | * @inheritDoc |
| 62 | 62 | */ |
| 63 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 64 | - { |
|
| 65 | - $xMetadata->callback($sMethod)->addValue($this->sJsObject); |
|
| 66 | - } |
|
| 63 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 64 | +{ |
|
| 65 | +$xMetadata->callback($sMethod)->addValue($this->sJsObject); |
|
| 66 | +} |
|
| 67 | 67 | } |
@@ -23,19 +23,19 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class BeforeAnnotation extends HookAnnotation |
| 25 | 25 | { |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * @inheritDoc |
| 28 | 28 | */ |
| 29 | - protected static function getType(): string |
|
| 30 | - { |
|
| 31 | - return 'before'; |
|
| 32 | - } |
|
| 29 | +protected static function getType(): string |
|
| 30 | +{ |
|
| 31 | +return 'before'; |
|
| 32 | +} |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @inheritDoc |
| 36 | 36 | */ |
| 37 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 38 | - { |
|
| 39 | - $xMetadata->before($sMethod)->addCall($this->sMethod, $this->aParams); |
|
| 40 | - } |
|
| 37 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 38 | +{ |
|
| 39 | +$xMetadata->before($sMethod)->addCall($this->sMethod, $this->aParams); |
|
| 40 | +} |
|
| 41 | 41 | } |
@@ -27,38 +27,38 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class ExcludeAnnotation extends AbstractAnnotation |
| 29 | 29 | { |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * @var bool |
| 32 | 32 | */ |
| 33 | - protected $bValue; |
|
| 33 | +protected $bValue; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 35 | +/** |
|
| 36 | 36 | * @inheritDoc |
| 37 | 37 | */ |
| 38 | - public static function parseAnnotation($value) |
|
| 39 | - { |
|
| 40 | - return [$value === 'true' ? true : ($value === 'false' ? false : $value)]; |
|
| 41 | - } |
|
| 38 | +public static function parseAnnotation($value) |
|
| 39 | +{ |
|
| 40 | +return [$value === 'true' ? true : ($value === 'false' ? false : $value)]; |
|
| 41 | +} |
|
| 42 | 42 | |
| 43 | - /** |
|
| 43 | +/** |
|
| 44 | 44 | * @inheritDoc |
| 45 | 45 | * @throws AnnotationException |
| 46 | 46 | */ |
| 47 | - public function initAnnotation(array $properties) |
|
| 48 | - { |
|
| 49 | - if(count($properties) !== 0 && (count($properties) !== 1 |
|
| 50 | - || !isset($properties[0]) || !is_bool($properties[0]))) |
|
| 51 | - { |
|
| 52 | - throw new AnnotationException('the @exclude annotation requires a single boolean or no property'); |
|
| 53 | - } |
|
| 54 | - $this->bValue = $properties[0] ?? true; |
|
| 55 | - } |
|
| 47 | +public function initAnnotation(array $properties) |
|
| 48 | +{ |
|
| 49 | +if(count($properties) !== 0 && (count($properties) !== 1 |
|
| 50 | +|| !isset($properties[0]) || !is_bool($properties[0]))) |
|
| 51 | +{ |
|
| 52 | +throw new AnnotationException('the @exclude annotation requires a single boolean or no property'); |
|
| 53 | +} |
|
| 54 | +$this->bValue = $properties[0] ?? true; |
|
| 55 | +} |
|
| 56 | 56 | |
| 57 | - /** |
|
| 57 | +/** |
|
| 58 | 58 | * @inheritDoc |
| 59 | 59 | */ |
| 60 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 61 | - { |
|
| 62 | - $xMetadata->exclude($sMethod)->setValue($this->bValue); |
|
| 63 | - } |
|
| 60 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 61 | +{ |
|
| 62 | +$xMetadata->exclude($sMethod)->setValue($this->bValue); |
|
| 63 | +} |
|
| 64 | 64 | } |
@@ -28,42 +28,42 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class UploadAnnotation extends AbstractAnnotation |
| 30 | 30 | { |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * The name of the upload field |
| 33 | 33 | * |
| 34 | 34 | * @var string |
| 35 | 35 | */ |
| 36 | - protected $sField = ''; |
|
| 36 | +protected $sField = ''; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * @inheritDoc |
| 40 | 40 | */ |
| 41 | - public static function parseAnnotation($value) |
|
| 42 | - { |
|
| 43 | - $aParams = preg_split('/[\s]+/', $value, 2); |
|
| 44 | - return count($aParams) === 1 ? ['field' => $aParams[0]] : |
|
| 45 | - ['field' => $aParams[0], 'extra' => $aParams[1]]; |
|
| 46 | - } |
|
| 41 | +public static function parseAnnotation($value) |
|
| 42 | +{ |
|
| 43 | +$aParams = preg_split('/[\s]+/', $value, 2); |
|
| 44 | +return count($aParams) === 1 ? ['field' => $aParams[0]] : |
|
| 45 | +['field' => $aParams[0], 'extra' => $aParams[1]]; |
|
| 46 | +} |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * @inheritDoc |
| 50 | 50 | * @throws AnnotationException |
| 51 | 51 | */ |
| 52 | - public function initAnnotation(array $properties) |
|
| 53 | - { |
|
| 54 | - if(count($properties) != 1 || !isset($properties['field']) || |
|
| 55 | - !is_string($properties['field'])) |
|
| 56 | - { |
|
| 57 | - throw new AnnotationException('The @upload annotation requires a property "field" of type string'); |
|
| 58 | - } |
|
| 59 | - $this->sField = $properties['field']; |
|
| 60 | - } |
|
| 52 | +public function initAnnotation(array $properties) |
|
| 53 | +{ |
|
| 54 | +if(count($properties) != 1 || !isset($properties['field']) || |
|
| 55 | +!is_string($properties['field'])) |
|
| 56 | +{ |
|
| 57 | +throw new AnnotationException('The @upload annotation requires a property "field" of type string'); |
|
| 58 | +} |
|
| 59 | +$this->sField = $properties['field']; |
|
| 60 | +} |
|
| 61 | 61 | |
| 62 | - /** |
|
| 62 | +/** |
|
| 63 | 63 | * @inheritDoc |
| 64 | 64 | */ |
| 65 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 66 | - { |
|
| 67 | - $xMetadata->upload($sMethod)->setValue($this->sField); |
|
| 68 | - } |
|
| 65 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 66 | +{ |
|
| 67 | +$xMetadata->upload($sMethod)->setValue($this->sField); |
|
| 68 | +} |
|
| 69 | 69 | } |
@@ -27,64 +27,64 @@ |
||
| 27 | 27 | |
| 28 | 28 | abstract class HookAnnotation extends AbstractAnnotation |
| 29 | 29 | { |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * @var string |
| 32 | 32 | */ |
| 33 | - protected $sMethod = ''; |
|
| 33 | +protected $sMethod = ''; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 35 | +/** |
|
| 36 | 36 | * @var array |
| 37 | 37 | */ |
| 38 | - protected $aParams = []; |
|
| 38 | +protected $aParams = []; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * |
| 42 | 42 | */ |
| 43 | - abstract protected static function getType(): string; |
|
| 43 | +abstract protected static function getType(): string; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 45 | +/** |
|
| 46 | 46 | * @inheritDoc |
| 47 | 47 | */ |
| 48 | - public static function parseAnnotation($value) |
|
| 49 | - { |
|
| 50 | - $aParams = preg_split('/[\s]+/', $value, 2); |
|
| 51 | - if(count($aParams) === 1) |
|
| 52 | - { |
|
| 53 | - return ['call' => rtrim($aParams[0])]; |
|
| 54 | - } |
|
| 55 | - // The second parameter must be an array of callback parameter in json format. |
|
| 56 | - return ['call' => rtrim($aParams[0]), 'with' => json_decode($aParams[1], false)]; |
|
| 57 | - } |
|
| 48 | +public static function parseAnnotation($value) |
|
| 49 | +{ |
|
| 50 | +$aParams = preg_split('/[\s]+/', $value, 2); |
|
| 51 | +if(count($aParams) === 1) |
|
| 52 | +{ |
|
| 53 | +return ['call' => rtrim($aParams[0])]; |
|
| 54 | +} |
|
| 55 | +// The second parameter must be an array of callback parameter in json format. |
|
| 56 | +return ['call' => rtrim($aParams[0]), 'with' => json_decode($aParams[1], false)]; |
|
| 57 | +} |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * @inheritDoc |
| 61 | 61 | * @throws AnnotationException |
| 62 | 62 | */ |
| 63 | - public function initAnnotation(array $properties) |
|
| 64 | - { |
|
| 65 | - if(!isset($properties['call']) || !is_string($properties['call'])) |
|
| 66 | - { |
|
| 67 | - throw new AnnotationException('The @' . $this->getType() . |
|
| 68 | - ' annotation requires a property "call" of type string'); |
|
| 69 | - } |
|
| 70 | - foreach(array_keys($properties) as $propName) |
|
| 71 | - { |
|
| 72 | - if($propName !== 'call' && $propName !== 'with') |
|
| 73 | - { |
|
| 74 | - throw new AnnotationException('Unknown property "' . $propName . |
|
| 75 | - '" in the @' . $this->getType() . ' annotation'); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - // Cannot use isset here, because it will return false in case $properties['with'] === null |
|
| 79 | - if(array_key_exists('with', $properties)) |
|
| 80 | - { |
|
| 81 | - if(!is_array($properties['with'])) |
|
| 82 | - { |
|
| 83 | - throw new AnnotationException('The "with" property of the @' . |
|
| 84 | - $this->getType() . ' annotation must be of type array'); |
|
| 85 | - } |
|
| 86 | - $this->aParams = $properties['with']; |
|
| 87 | - } |
|
| 88 | - $this->sMethod = $properties['call']; |
|
| 89 | - } |
|
| 63 | +public function initAnnotation(array $properties) |
|
| 64 | +{ |
|
| 65 | +if(!isset($properties['call']) || !is_string($properties['call'])) |
|
| 66 | +{ |
|
| 67 | +throw new AnnotationException('The @' . $this->getType() . |
|
| 68 | + ' annotation requires a property "call" of type string'); |
|
| 69 | +} |
|
| 70 | +foreach(array_keys($properties) as $propName) |
|
| 71 | +{ |
|
| 72 | +if($propName !== 'call' && $propName !== 'with') |
|
| 73 | +{ |
|
| 74 | + throw new AnnotationException('Unknown property "' . $propName . |
|
| 75 | + '" in the @' . $this->getType() . ' annotation'); |
|
| 76 | +} |
|
| 77 | +} |
|
| 78 | +// Cannot use isset here, because it will return false in case $properties['with'] === null |
|
| 79 | +if(array_key_exists('with', $properties)) |
|
| 80 | +{ |
|
| 81 | +if(!is_array($properties['with'])) |
|
| 82 | +{ |
|
| 83 | + throw new AnnotationException('The "with" property of the @' . |
|
| 84 | + $this->getType() . ' annotation must be of type array'); |
|
| 85 | +} |
|
| 86 | +$this->aParams = $properties['with']; |
|
| 87 | +} |
|
| 88 | +$this->sMethod = $properties['call']; |
|
| 89 | +} |
|
| 90 | 90 | } |
@@ -28,40 +28,40 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class DataBagAnnotation extends AbstractAnnotation |
| 30 | 30 | { |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * The data bag name |
| 33 | 33 | * |
| 34 | 34 | * @var string |
| 35 | 35 | */ |
| 36 | - protected $sName = ''; |
|
| 36 | +protected $sName = ''; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * @inheritDoc |
| 40 | 40 | */ |
| 41 | - public static function parseAnnotation($value) |
|
| 42 | - { |
|
| 43 | - $aParams = preg_split('/[\s]+/', $value, 2); |
|
| 44 | - return count($aParams) === 1 ? ['name' => $aParams[0]] : ['name' => $aParams[0], 'extra' => $aParams[1]]; |
|
| 45 | - } |
|
| 41 | +public static function parseAnnotation($value) |
|
| 42 | +{ |
|
| 43 | +$aParams = preg_split('/[\s]+/', $value, 2); |
|
| 44 | +return count($aParams) === 1 ? ['name' => $aParams[0]] : ['name' => $aParams[0], 'extra' => $aParams[1]]; |
|
| 45 | +} |
|
| 46 | 46 | |
| 47 | - /** |
|
| 47 | +/** |
|
| 48 | 48 | * @inheritDoc |
| 49 | 49 | * @throws AnnotationException |
| 50 | 50 | */ |
| 51 | - public function initAnnotation(array $properties) |
|
| 52 | - { |
|
| 53 | - if(count($properties) !== 1 || !isset($properties['name']) || !is_string($properties['name'])) |
|
| 54 | - { |
|
| 55 | - throw new AnnotationException('The @databag annotation requires a property "name" of type string'); |
|
| 56 | - } |
|
| 57 | - $this->sName = $properties['name']; |
|
| 58 | - } |
|
| 51 | +public function initAnnotation(array $properties) |
|
| 52 | +{ |
|
| 53 | +if(count($properties) !== 1 || !isset($properties['name']) || !is_string($properties['name'])) |
|
| 54 | +{ |
|
| 55 | +throw new AnnotationException('The @databag annotation requires a property "name" of type string'); |
|
| 56 | +} |
|
| 57 | +$this->sName = $properties['name']; |
|
| 58 | +} |
|
| 59 | 59 | |
| 60 | - /** |
|
| 60 | +/** |
|
| 61 | 61 | * @inheritDoc |
| 62 | 62 | */ |
| 63 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 64 | - { |
|
| 65 | - $xMetadata->databag($sMethod)->addValue($this->sName); |
|
| 66 | - } |
|
| 63 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 64 | +{ |
|
| 65 | +$xMetadata->databag($sMethod)->addValue($this->sName); |
|
| 66 | +} |
|
| 67 | 67 | } |