@@ -21,31 +21,31 @@ |
||
| 21 | 21 | |
| 22 | 22 | class Bootbox extends AbstractLibrary implements ModalInterface, AlertInterface, ConfirmInterface |
| 23 | 23 | { |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @const The library name |
| 26 | 26 | */ |
| 27 | - public const NAME = 'bootbox'; |
|
| 27 | +public const NAME = 'bootbox'; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * The js files |
| 31 | 31 | * |
| 32 | 32 | * @var array |
| 33 | 33 | */ |
| 34 | - protected $aJsFiles = ['bootbox.min.js']; |
|
| 34 | +protected $aJsFiles = ['bootbox.min.js']; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 36 | +/** |
|
| 37 | 37 | * @inheritDoc |
| 38 | 38 | */ |
| 39 | - public function getName(): string |
|
| 40 | - { |
|
| 41 | - return self::NAME; |
|
| 42 | - } |
|
| 39 | +public function getName(): string |
|
| 40 | +{ |
|
| 41 | +return self::NAME; |
|
| 42 | +} |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | +/** |
|
| 45 | 45 | * @inheritDoc |
| 46 | 46 | */ |
| 47 | - public function getUri(): string |
|
| 48 | - { |
|
| 49 | - return 'https://cdn.jsdelivr.net/npm/[email protected]/dist'; |
|
| 50 | - } |
|
| 47 | +public function getUri(): string |
|
| 48 | +{ |
|
| 49 | +return 'https://cdn.jsdelivr.net/npm/[email protected]/dist'; |
|
| 50 | +} |
|
| 51 | 51 | } |
@@ -19,16 +19,16 @@ |
||
| 19 | 19 | |
| 20 | 20 | class Bootstrap5 extends AbstractLibrary implements ModalInterface |
| 21 | 21 | { |
| 22 | - /** |
|
| 22 | +/** |
|
| 23 | 23 | * @const The library name |
| 24 | 24 | */ |
| 25 | - public const NAME = 'bootstrap5'; |
|
| 25 | +public const NAME = 'bootstrap5'; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 27 | +/** |
|
| 28 | 28 | * @inheritDoc |
| 29 | 29 | */ |
| 30 | - public function getName(): string |
|
| 31 | - { |
|
| 32 | - return self::NAME; |
|
| 33 | - } |
|
| 30 | +public function getName(): string |
|
| 31 | +{ |
|
| 32 | +return self::NAME; |
|
| 33 | +} |
|
| 34 | 34 | } |
@@ -20,40 +20,40 @@ |
||
| 20 | 20 | use Jaxon\App\Dialog\Library\ModalInterface; |
| 21 | 21 | |
| 22 | 22 | class JQueryConfirm extends AbstractLibrary |
| 23 | - implements ModalInterface, AlertInterface, ConfirmInterface |
|
| 23 | +implements ModalInterface, AlertInterface, ConfirmInterface |
|
| 24 | 24 | { |
| 25 | - /** |
|
| 25 | +/** |
|
| 26 | 26 | * @const The library name |
| 27 | 27 | */ |
| 28 | - public const NAME = 'jconfirm'; |
|
| 28 | +public const NAME = 'jconfirm'; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * The css files |
| 32 | 32 | * |
| 33 | 33 | * @var array |
| 34 | 34 | */ |
| 35 | - protected $aCssFiles = ['jquery-confirm.min.css']; |
|
| 35 | +protected $aCssFiles = ['jquery-confirm.min.css']; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 37 | +/** |
|
| 38 | 38 | * The js files |
| 39 | 39 | * |
| 40 | 40 | * @var array |
| 41 | 41 | */ |
| 42 | - protected $aJsFiles = ['jquery-confirm.min.js']; |
|
| 42 | +protected $aJsFiles = ['jquery-confirm.min.js']; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | +/** |
|
| 45 | 45 | * @inheritDoc |
| 46 | 46 | */ |
| 47 | - public function getName(): string |
|
| 48 | - { |
|
| 49 | - return self::NAME; |
|
| 50 | - } |
|
| 47 | +public function getName(): string |
|
| 48 | +{ |
|
| 49 | +return self::NAME; |
|
| 50 | +} |
|
| 51 | 51 | |
| 52 | - /** |
|
| 52 | +/** |
|
| 53 | 53 | * @inheritDoc |
| 54 | 54 | */ |
| 55 | - public function getUri(): string |
|
| 56 | - { |
|
| 57 | - return 'https://cdn.jsdelivr.net/npm/[email protected]/dist'; |
|
| 58 | - } |
|
| 55 | +public function getUri(): string |
|
| 56 | +{ |
|
| 57 | +return 'https://cdn.jsdelivr.net/npm/[email protected]/dist'; |
|
| 58 | +} |
|
| 59 | 59 | } |
@@ -20,40 +20,40 @@ |
||
| 20 | 20 | use Jaxon\App\Dialog\Library\ModalInterface; |
| 21 | 21 | |
| 22 | 22 | class Bootstrap3 extends AbstractLibrary |
| 23 | - implements ModalInterface, AlertInterface, ConfirmInterface |
|
| 23 | +implements ModalInterface, AlertInterface, ConfirmInterface |
|
| 24 | 24 | { |
| 25 | - /** |
|
| 25 | +/** |
|
| 26 | 26 | * @const The library name |
| 27 | 27 | */ |
| 28 | - public const NAME = 'bootstrap3'; |
|
| 28 | +public const NAME = 'bootstrap3'; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * The css files |
| 32 | 32 | * |
| 33 | 33 | * @var array |
| 34 | 34 | */ |
| 35 | - protected $aCssFiles = ['css/bootstrap-dialog.min.css']; |
|
| 35 | +protected $aCssFiles = ['css/bootstrap-dialog.min.css']; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 37 | +/** |
|
| 38 | 38 | * The js files |
| 39 | 39 | * |
| 40 | 40 | * @var array |
| 41 | 41 | */ |
| 42 | - protected $aJsFiles = ['js/bootstrap-dialog.min.js']; |
|
| 42 | +protected $aJsFiles = ['js/bootstrap-dialog.min.js']; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | +/** |
|
| 45 | 45 | * @inheritDoc |
| 46 | 46 | */ |
| 47 | - public function getName(): string |
|
| 48 | - { |
|
| 49 | - return self::NAME; |
|
| 50 | - } |
|
| 47 | +public function getName(): string |
|
| 48 | +{ |
|
| 49 | +return self::NAME; |
|
| 50 | +} |
|
| 51 | 51 | |
| 52 | - /** |
|
| 52 | +/** |
|
| 53 | 53 | * @inheritDoc |
| 54 | 54 | */ |
| 55 | - public function getUri(): string |
|
| 56 | - { |
|
| 57 | - return 'https://cdn.jsdelivr.net/npm/[email protected]/dist'; |
|
| 58 | - } |
|
| 55 | +public function getUri(): string |
|
| 56 | +{ |
|
| 57 | +return 'https://cdn.jsdelivr.net/npm/[email protected]/dist'; |
|
| 58 | +} |
|
| 59 | 59 | } |
@@ -16,56 +16,56 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | class LibraryHelper |
| 18 | 18 | { |
| 19 | - use ConfigTrait; |
|
| 19 | +use ConfigTrait; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 21 | +/** |
|
| 22 | 22 | * Default library URL |
| 23 | 23 | * |
| 24 | 24 | * @var string |
| 25 | 25 | */ |
| 26 | - const JS_LIB_URL = 'https://cdn.jsdelivr.net/gh/jaxon-php/jaxon-dialogs@main/js'; |
|
| 26 | +const JS_LIB_URL = 'https://cdn.jsdelivr.net/gh/jaxon-php/jaxon-dialogs@main/js'; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 28 | +/** |
|
| 29 | 29 | * The name of the library |
| 30 | 30 | * |
| 31 | 31 | * @var string |
| 32 | 32 | */ |
| 33 | - protected $sName = ''; |
|
| 33 | +protected $sName = ''; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 35 | +/** |
|
| 36 | 36 | * The URI where to get the library files from |
| 37 | 37 | * |
| 38 | 38 | * @var string |
| 39 | 39 | */ |
| 40 | - protected $sUri = ''; |
|
| 40 | +protected $sUri = ''; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 42 | +/** |
|
| 43 | 43 | * The constructor |
| 44 | 44 | * |
| 45 | 45 | * @param LibraryInterface $xDialogLibrary |
| 46 | 46 | * @param ConfigManager $xConfigManager |
| 47 | 47 | * @param TemplateEngine $xTemplateEngine |
| 48 | 48 | */ |
| 49 | - public function __construct(LibraryInterface $xDialogLibrary, |
|
| 50 | - private ConfigManager $xConfigManager, private TemplateEngine $xTemplateEngine) |
|
| 51 | - { |
|
| 52 | - // Set the library name |
|
| 53 | - $this->sName = $xDialogLibrary->getName(); |
|
| 54 | - // Set the default URI. |
|
| 55 | - $sDefaultUri = $this->getAppOption('dialogs.lib.uri', $xDialogLibrary->getUri()); |
|
| 56 | - // Set the library URI. |
|
| 57 | - $this->sUri = rtrim($this->getOption('uri', $sDefaultUri), '/'); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 49 | +public function __construct(LibraryInterface $xDialogLibrary, |
|
| 50 | +private ConfigManager $xConfigManager, private TemplateEngine $xTemplateEngine) |
|
| 51 | +{ |
|
| 52 | +// Set the library name |
|
| 53 | +$this->sName = $xDialogLibrary->getName(); |
|
| 54 | +// Set the default URI. |
|
| 55 | +$sDefaultUri = $this->getAppOption('dialogs.lib.uri', $xDialogLibrary->getUri()); |
|
| 56 | +// Set the library URI. |
|
| 57 | +$this->sUri = rtrim($this->getOption('uri', $sDefaultUri), '/'); |
|
| 58 | +} |
|
| 59 | + |
|
| 60 | +/** |
|
| 61 | 61 | * @return ConfigManager |
| 62 | 62 | */ |
| 63 | - protected function config(): ConfigManager |
|
| 64 | - { |
|
| 65 | - return $this->xConfigManager; |
|
| 66 | - } |
|
| 63 | +protected function config(): ConfigManager |
|
| 64 | +{ |
|
| 65 | +return $this->xConfigManager; |
|
| 66 | +} |
|
| 67 | 67 | |
| 68 | - /** |
|
| 68 | +/** |
|
| 69 | 69 | * Get the value of a config option |
| 70 | 70 | * |
| 71 | 71 | * @param string $sOptionName The option name |
@@ -73,134 +73,134 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @return mixed |
| 75 | 75 | */ |
| 76 | - public function getOption(string $sOptionName, $xDefault = null) |
|
| 77 | - { |
|
| 78 | - $sOptionName = "dialogs.{$this->sName}.$sOptionName"; |
|
| 79 | - return $this->getAppOption($sOptionName, $xDefault); |
|
| 80 | - } |
|
| 76 | +public function getOption(string $sOptionName, $xDefault = null) |
|
| 77 | +{ |
|
| 78 | +$sOptionName = "dialogs.{$this->sName}.$sOptionName"; |
|
| 79 | +return $this->getAppOption($sOptionName, $xDefault); |
|
| 80 | +} |
|
| 81 | 81 | |
| 82 | - /** |
|
| 82 | +/** |
|
| 83 | 83 | * Check the presence of a config option |
| 84 | 84 | * |
| 85 | 85 | * @param string $sOptionName The option name |
| 86 | 86 | * |
| 87 | 87 | * @return bool |
| 88 | 88 | */ |
| 89 | - public function hasOption(string $sOptionName): bool |
|
| 90 | - { |
|
| 91 | - return $this->hasAppOption("dialogs.{$this->sName}.$sOptionName"); |
|
| 92 | - } |
|
| 89 | +public function hasOption(string $sOptionName): bool |
|
| 90 | +{ |
|
| 91 | +return $this->hasAppOption("dialogs.{$this->sName}.$sOptionName"); |
|
| 92 | +} |
|
| 93 | 93 | |
| 94 | - /** |
|
| 94 | +/** |
|
| 95 | 95 | * Get the options of the js library |
| 96 | 96 | * |
| 97 | 97 | * @return array |
| 98 | 98 | */ |
| 99 | - public function getJsOptions(): array |
|
| 100 | - { |
|
| 101 | - $xOptions = $this->getAppOption("dialogs.{$this->sName}.options", []); |
|
| 102 | - return is_array($xOptions) ? $xOptions : []; |
|
| 103 | - } |
|
| 99 | +public function getJsOptions(): array |
|
| 100 | +{ |
|
| 101 | +$xOptions = $this->getAppOption("dialogs.{$this->sName}.options", []); |
|
| 102 | +return is_array($xOptions) ? $xOptions : []; |
|
| 103 | +} |
|
| 104 | 104 | |
| 105 | - /** |
|
| 105 | +/** |
|
| 106 | 106 | * @param string $sOption The assets option name |
| 107 | 107 | * @param string $sFile The javascript file name |
| 108 | 108 | * |
| 109 | 109 | * @return string|null |
| 110 | 110 | */ |
| 111 | - private function getAssetUri(string $sOption, string $sFile): ?string |
|
| 112 | - { |
|
| 113 | - return !$this->hasOption($sOption) ? "{$this->sUri}/$sFile" : |
|
| 114 | - (trim($this->getOption($sOption)) ?: null); |
|
| 115 | - } |
|
| 111 | +private function getAssetUri(string $sOption, string $sFile): ?string |
|
| 112 | +{ |
|
| 113 | +return !$this->hasOption($sOption) ? "{$this->sUri}/$sFile" : |
|
| 114 | +(trim($this->getOption($sOption)) ?: null); |
|
| 115 | +} |
|
| 116 | 116 | |
| 117 | - /** |
|
| 117 | +/** |
|
| 118 | 118 | * @param string $sOption The assets option name |
| 119 | 119 | * @param array $aFiles The asset files |
| 120 | 120 | * |
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | - private function getUris(string $sOption, array $aFiles): array |
|
| 124 | - { |
|
| 125 | - $aFiles = array_map(fn($sFile) => |
|
| 126 | - $this->getAssetUri($sOption, $sFile), $aFiles); |
|
| 127 | - return array_filter($aFiles, fn($sFile) => $sFile !== null); |
|
| 128 | - } |
|
| 123 | +private function getUris(string $sOption, array $aFiles): array |
|
| 124 | +{ |
|
| 125 | +$aFiles = array_map(fn($sFile) => |
|
| 126 | +$this->getAssetUri($sOption, $sFile), $aFiles); |
|
| 127 | +return array_filter($aFiles, fn($sFile) => $sFile !== null); |
|
| 128 | +} |
|
| 129 | 129 | |
| 130 | - /** |
|
| 130 | +/** |
|
| 131 | 131 | * @param string $sUri |
| 132 | 132 | * |
| 133 | 133 | * @return string |
| 134 | 134 | */ |
| 135 | - private function getJsTag(string $sUri): string |
|
| 136 | - { |
|
| 137 | - return '<script type="text/javascript" src="' . $sUri . '"></script>'; |
|
| 138 | - } |
|
| 135 | +private function getJsTag(string $sUri): string |
|
| 136 | +{ |
|
| 137 | +return '<script type="text/javascript" src="' . $sUri . '"></script>'; |
|
| 138 | +} |
|
| 139 | 139 | |
| 140 | - /** |
|
| 140 | +/** |
|
| 141 | 141 | * Get the javascript HTML header code |
| 142 | 142 | * |
| 143 | 143 | * @param array $aFiles The js files |
| 144 | 144 | * |
| 145 | 145 | * @return string |
| 146 | 146 | */ |
| 147 | - public function getJs(array $aFiles): string |
|
| 148 | - { |
|
| 149 | - $aFiles = $this->getUris('assets.js', $aFiles); |
|
| 150 | - $aFiles = array_map(fn($sUri) => $this->getJsTag($sUri), $aFiles); |
|
| 151 | - return implode("\n", $aFiles); |
|
| 152 | - } |
|
| 147 | +public function getJs(array $aFiles): string |
|
| 148 | +{ |
|
| 149 | +$aFiles = $this->getUris('assets.js', $aFiles); |
|
| 150 | +$aFiles = array_map(fn($sUri) => $this->getJsTag($sUri), $aFiles); |
|
| 151 | +return implode("\n", $aFiles); |
|
| 152 | +} |
|
| 153 | 153 | |
| 154 | - /** |
|
| 154 | +/** |
|
| 155 | 155 | * @param string $sUri |
| 156 | 156 | * |
| 157 | 157 | * @return string |
| 158 | 158 | */ |
| 159 | - private function getCssTag(string $sUri): string |
|
| 160 | - { |
|
| 161 | - return '<link rel="stylesheet" href="' . $sUri . '" />'; |
|
| 162 | - } |
|
| 159 | +private function getCssTag(string $sUri): string |
|
| 160 | +{ |
|
| 161 | +return '<link rel="stylesheet" href="' . $sUri . '" />'; |
|
| 162 | +} |
|
| 163 | 163 | |
| 164 | - /** |
|
| 164 | +/** |
|
| 165 | 165 | * Get the CSS HTML header code |
| 166 | 166 | * |
| 167 | 167 | * @param array $aFiles The CSS files |
| 168 | 168 | * |
| 169 | 169 | * @return string |
| 170 | 170 | */ |
| 171 | - public function getCss(array $aFiles): string |
|
| 172 | - { |
|
| 173 | - $aFiles = $this->getUris('assets.css', $aFiles); |
|
| 174 | - $aFiles = array_map(fn($sUri) => $this->getCssTag($sUri), $aFiles); |
|
| 175 | - return implode("\n", $aFiles); |
|
| 176 | - } |
|
| 171 | +public function getCss(array $aFiles): string |
|
| 172 | +{ |
|
| 173 | +$aFiles = $this->getUris('assets.css', $aFiles); |
|
| 174 | +$aFiles = array_map(fn($sUri) => $this->getCssTag($sUri), $aFiles); |
|
| 175 | +return implode("\n", $aFiles); |
|
| 176 | +} |
|
| 177 | 177 | |
| 178 | - /** |
|
| 178 | +/** |
|
| 179 | 179 | * Get the library script code |
| 180 | 180 | * |
| 181 | 181 | * @return string |
| 182 | 182 | */ |
| 183 | 183 | |
| 184 | - public function getScript(): string |
|
| 185 | - { |
|
| 186 | - return !$this->getLibOption('js.app.export', false) ? |
|
| 187 | - $this->xTemplateEngine->render("jaxon::dialogs::{$this->sName}.js") : ''; |
|
| 188 | - } |
|
| 184 | +public function getScript(): string |
|
| 185 | +{ |
|
| 186 | +return !$this->getLibOption('js.app.export', false) ? |
|
| 187 | +$this->xTemplateEngine->render("jaxon::dialogs::{$this->sName}.js") : ''; |
|
| 188 | +} |
|
| 189 | 189 | |
| 190 | - /** |
|
| 190 | +/** |
|
| 191 | 191 | * Get the javascript HTML header code |
| 192 | 192 | * |
| 193 | 193 | * @return array |
| 194 | 194 | */ |
| 195 | - public function getFiles(): array |
|
| 196 | - { |
|
| 197 | - if(!$this->getLibOption('js.app.export', false)) |
|
| 198 | - { |
|
| 199 | - return []; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - $sJsFileName = !$this->getLibOption('js.app.minify', false) ? |
|
| 203 | - "{$this->sName}.js" : "{$this->sName}.min.js"; |
|
| 204 | - return [self::JS_LIB_URL . "/$sJsFileName"]; |
|
| 205 | - } |
|
| 195 | +public function getFiles(): array |
|
| 196 | +{ |
|
| 197 | +if(!$this->getLibOption('js.app.export', false)) |
|
| 198 | +{ |
|
| 199 | +return []; |
|
| 200 | +} |
|
| 201 | + |
|
| 202 | +$sJsFileName = !$this->getLibOption('js.app.minify', false) ? |
|
| 203 | +"{$this->sName}.js" : "{$this->sName}.min.js"; |
|
| 204 | +return [self::JS_LIB_URL . "/$sJsFileName"]; |
|
| 205 | +} |
|
| 206 | 206 | } |
@@ -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 | } |