@@ -31,75 +31,75 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | class CodeGenerator |
| 33 | 33 | { |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @var AssetManager |
| 36 | 36 | */ |
| 37 | - private $xAssetManager; |
|
| 37 | +private $xAssetManager; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * The classes that generate code |
| 41 | 41 | * |
| 42 | 42 | * @var array<string> |
| 43 | 43 | */ |
| 44 | - protected $aCodeGenerators = []; |
|
| 44 | +protected $aCodeGenerators = []; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 46 | +/** |
|
| 47 | 47 | * @var string |
| 48 | 48 | */ |
| 49 | - protected $sJsOptions; |
|
| 49 | +protected $sJsOptions; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | +/** |
|
| 52 | 52 | * @var array |
| 53 | 53 | */ |
| 54 | - protected $aCss = []; |
|
| 54 | +protected $aCss = []; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 56 | +/** |
|
| 57 | 57 | * @var array |
| 58 | 58 | */ |
| 59 | - protected $aJs = []; |
|
| 59 | +protected $aJs = []; |
|
| 60 | 60 | |
| 61 | - /** |
|
| 61 | +/** |
|
| 62 | 62 | * @var array |
| 63 | 63 | */ |
| 64 | - protected $aCodeJs = []; |
|
| 64 | +protected $aCodeJs = []; |
|
| 65 | 65 | |
| 66 | - /** |
|
| 66 | +/** |
|
| 67 | 67 | * @var array |
| 68 | 68 | */ |
| 69 | - protected $aCodeJsBefore = []; |
|
| 69 | +protected $aCodeJsBefore = []; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 71 | +/** |
|
| 72 | 72 | * @var array |
| 73 | 73 | */ |
| 74 | - protected $aCodeJsAfter = []; |
|
| 74 | +protected $aCodeJsAfter = []; |
|
| 75 | 75 | |
| 76 | - /** |
|
| 76 | +/** |
|
| 77 | 77 | * @var array |
| 78 | 78 | */ |
| 79 | - protected $aCodeJsFiles = []; |
|
| 79 | +protected $aCodeJsFiles = []; |
|
| 80 | 80 | |
| 81 | - /** |
|
| 81 | +/** |
|
| 82 | 82 | * @var bool |
| 83 | 83 | */ |
| 84 | - protected $bGenerated = false; |
|
| 84 | +protected $bGenerated = false; |
|
| 85 | 85 | |
| 86 | - /** |
|
| 86 | +/** |
|
| 87 | 87 | * The constructor |
| 88 | 88 | * |
| 89 | 89 | * @param string $sVersion |
| 90 | 90 | * @param Container $di |
| 91 | 91 | * @param TemplateEngine $xTemplateEngine |
| 92 | 92 | */ |
| 93 | - public function __construct(private string $sVersion, private Container $di, |
|
| 94 | - private TemplateEngine $xTemplateEngine) |
|
| 95 | - { |
|
| 96 | - // The Jaxon library config is on top. |
|
| 97 | - $this->addCodeGenerator(ConfigScriptGenerator::class, 0); |
|
| 98 | - // The ready script comes after. |
|
| 99 | - $this->addCodeGenerator(ReadyScriptGenerator::class, 200); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 93 | +public function __construct(private string $sVersion, private Container $di, |
|
| 94 | +private TemplateEngine $xTemplateEngine) |
|
| 95 | +{ |
|
| 96 | +// The Jaxon library config is on top. |
|
| 97 | +$this->addCodeGenerator(ConfigScriptGenerator::class, 0); |
|
| 98 | +// The ready script comes after. |
|
| 99 | +$this->addCodeGenerator(ReadyScriptGenerator::class, 200); |
|
| 100 | +} |
|
| 101 | + |
|
| 102 | +/** |
|
| 103 | 103 | * Add a code generator to the list |
| 104 | 104 | * |
| 105 | 105 | * @param string $sClassName The code generator class |
@@ -107,39 +107,39 @@ discard block |
||
| 107 | 107 | * |
| 108 | 108 | * @return void |
| 109 | 109 | */ |
| 110 | - public function addCodeGenerator(string $sClassName, int $nPriority): void |
|
| 111 | - { |
|
| 112 | - while(isset($this->aCodeGenerators[$nPriority])) |
|
| 113 | - { |
|
| 114 | - $nPriority++; |
|
| 115 | - } |
|
| 116 | - $this->aCodeGenerators[$nPriority] = $sClassName; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 110 | +public function addCodeGenerator(string $sClassName, int $nPriority): void |
|
| 111 | +{ |
|
| 112 | +while(isset($this->aCodeGenerators[$nPriority])) |
|
| 113 | +{ |
|
| 114 | +$nPriority++; |
|
| 115 | +} |
|
| 116 | +$this->aCodeGenerators[$nPriority] = $sClassName; |
|
| 117 | +} |
|
| 118 | + |
|
| 119 | +/** |
|
| 120 | 120 | * @param string $sClassName |
| 121 | 121 | * |
| 122 | 122 | * @return CodeGeneratorInterface |
| 123 | 123 | */ |
| 124 | - private function getCodeGenerator(string $sClassName): CodeGeneratorInterface |
|
| 125 | - { |
|
| 126 | - return $this->di->g($sClassName); |
|
| 127 | - } |
|
| 124 | +private function getCodeGenerator(string $sClassName): CodeGeneratorInterface |
|
| 125 | +{ |
|
| 126 | +return $this->di->g($sClassName); |
|
| 127 | +} |
|
| 128 | 128 | |
| 129 | - /** |
|
| 129 | +/** |
|
| 130 | 130 | * Generate a hash for all the javascript code generated by the library |
| 131 | 131 | * |
| 132 | 132 | * @return string |
| 133 | 133 | */ |
| 134 | - public function getHash(): string |
|
| 135 | - { |
|
| 136 | - $aHashes = array_map(fn($sClassName) => |
|
| 137 | - $this->getCodeGenerator($sClassName)->getHash(), $this->aCodeGenerators); |
|
| 138 | - $aHashes[] = $this->sVersion; |
|
| 139 | - return md5(implode('', $aHashes)); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 134 | +public function getHash(): string |
|
| 135 | +{ |
|
| 136 | +$aHashes = array_map(fn($sClassName) => |
|
| 137 | +$this->getCodeGenerator($sClassName)->getHash(), $this->aCodeGenerators); |
|
| 138 | +$aHashes[] = $this->sVersion; |
|
| 139 | +return md5(implode('', $aHashes)); |
|
| 140 | +} |
|
| 141 | + |
|
| 142 | +/** |
|
| 143 | 143 | * Render a template in the 'plugins' subdir |
| 144 | 144 | * |
| 145 | 145 | * @param string $sTemplate The template filename |
@@ -147,185 +147,185 @@ discard block |
||
| 147 | 147 | * |
| 148 | 148 | * @return string |
| 149 | 149 | */ |
| 150 | - private function render(string $sTemplate, array $aVars = []): string |
|
| 151 | - { |
|
| 152 | - $aVars['sJsOptions'] = $this->sJsOptions; |
|
| 153 | - return $this->xTemplateEngine->render("jaxon::plugins/$sTemplate", $aVars); |
|
| 154 | - } |
|
| 150 | +private function render(string $sTemplate, array $aVars = []): string |
|
| 151 | +{ |
|
| 152 | +$aVars['sJsOptions'] = $this->sJsOptions; |
|
| 153 | +return $this->xTemplateEngine->render("jaxon::plugins/$sTemplate", $aVars); |
|
| 154 | +} |
|
| 155 | 155 | |
| 156 | - /** |
|
| 156 | +/** |
|
| 157 | 157 | * Generate the Jaxon CSS and js codes for a given plugin |
| 158 | 158 | * |
| 159 | 159 | * @param CodeGeneratorInterface $xGenerator |
| 160 | 160 | * |
| 161 | 161 | * @return void |
| 162 | 162 | */ |
| 163 | - private function generatePluginCodes(CodeGeneratorInterface $xGenerator): void |
|
| 164 | - { |
|
| 165 | - if(!is_subclass_of($xGenerator, AbstractPlugin::class) || |
|
| 166 | - $this->xAssetManager->shallIncludeAssets($xGenerator)) |
|
| 167 | - { |
|
| 168 | - // HTML tags for CSS |
|
| 169 | - if(($sCss = trim($xGenerator->getCss(), " \n")) !== '') |
|
| 170 | - { |
|
| 171 | - $this->aCss[] = $sCss; |
|
| 172 | - } |
|
| 173 | - // HTML tags for js |
|
| 174 | - if(($sJs = trim($xGenerator->getJs(), " \n")) !== '') |
|
| 175 | - { |
|
| 176 | - $this->aJs[] = $sJs; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // Additional js codes |
|
| 181 | - if(($xJsCode = $xGenerator->getJsCode()) !== null) |
|
| 182 | - { |
|
| 183 | - if(($sJs = trim($xJsCode->sJs, " \n")) !== '') |
|
| 184 | - { |
|
| 185 | - $this->aCodeJs[] = $sJs; |
|
| 186 | - } |
|
| 187 | - if(($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '') |
|
| 188 | - { |
|
| 189 | - $this->aCodeJsBefore[] = $sJsBefore; |
|
| 190 | - } |
|
| 191 | - if(($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '') |
|
| 192 | - { |
|
| 193 | - $this->aCodeJsAfter[] = $sJsAfter; |
|
| 194 | - } |
|
| 195 | - $this->aCodeJsFiles = array_merge($this->aCodeJsFiles, $xJsCode->aFiles); |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 163 | +private function generatePluginCodes(CodeGeneratorInterface $xGenerator): void |
|
| 164 | +{ |
|
| 165 | +if(!is_subclass_of($xGenerator, AbstractPlugin::class) || |
|
| 166 | +$this->xAssetManager->shallIncludeAssets($xGenerator)) |
|
| 167 | +{ |
|
| 168 | +// HTML tags for CSS |
|
| 169 | +if(($sCss = trim($xGenerator->getCss(), " \n")) !== '') |
|
| 170 | +{ |
|
| 171 | + $this->aCss[] = $sCss; |
|
| 172 | +} |
|
| 173 | +// HTML tags for js |
|
| 174 | +if(($sJs = trim($xGenerator->getJs(), " \n")) !== '') |
|
| 175 | +{ |
|
| 176 | + $this->aJs[] = $sJs; |
|
| 177 | +} |
|
| 178 | +} |
|
| 179 | + |
|
| 180 | +// Additional js codes |
|
| 181 | +if(($xJsCode = $xGenerator->getJsCode()) !== null) |
|
| 182 | +{ |
|
| 183 | +if(($sJs = trim($xJsCode->sJs, " \n")) !== '') |
|
| 184 | +{ |
|
| 185 | + $this->aCodeJs[] = $sJs; |
|
| 186 | +} |
|
| 187 | +if(($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '') |
|
| 188 | +{ |
|
| 189 | + $this->aCodeJsBefore[] = $sJsBefore; |
|
| 190 | +} |
|
| 191 | +if(($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '') |
|
| 192 | +{ |
|
| 193 | + $this->aCodeJsAfter[] = $sJsAfter; |
|
| 194 | +} |
|
| 195 | +$this->aCodeJsFiles = array_merge($this->aCodeJsFiles, $xJsCode->aFiles); |
|
| 196 | +} |
|
| 197 | +} |
|
| 198 | + |
|
| 199 | +/** |
|
| 200 | 200 | * Generate the Jaxon CSS ans js codes |
| 201 | 201 | * |
| 202 | 202 | * @return void |
| 203 | 203 | * @throws UriException |
| 204 | 204 | */ |
| 205 | - private function generateCodes(): void |
|
| 206 | - { |
|
| 207 | - if($this->bGenerated) |
|
| 208 | - { |
|
| 209 | - return; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // We need the library to have been bootstrapped. |
|
| 213 | - $this->di->getBootstrap()->onBoot(); |
|
| 214 | - |
|
| 215 | - // Sort the code generators by ascending priority |
|
| 216 | - ksort($this->aCodeGenerators); |
|
| 217 | - |
|
| 218 | - // Cannot be injected because of dependency loop. |
|
| 219 | - $this->xAssetManager = $this->di->getAssetManager(); |
|
| 220 | - |
|
| 221 | - $this->sJsOptions = $this->xAssetManager->getJsOptions(); |
|
| 222 | - foreach($this->aCodeGenerators as $sClassName) |
|
| 223 | - { |
|
| 224 | - $this->generatePluginCodes($this->getCodeGenerator($sClassName)); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - // Load the Jaxon lib js files, after the other libs js files. |
|
| 228 | - $this->aJs[] = trim($this->render('includes.js', [ |
|
| 229 | - 'aUrls' => $this->xAssetManager->getJsLibFiles(), |
|
| 230 | - ])); |
|
| 231 | - |
|
| 232 | - // The codes are already generated. |
|
| 233 | - $this->bGenerated = true; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 205 | +private function generateCodes(): void |
|
| 206 | +{ |
|
| 207 | +if($this->bGenerated) |
|
| 208 | +{ |
|
| 209 | +return; |
|
| 210 | +} |
|
| 211 | + |
|
| 212 | +// We need the library to have been bootstrapped. |
|
| 213 | +$this->di->getBootstrap()->onBoot(); |
|
| 214 | + |
|
| 215 | +// Sort the code generators by ascending priority |
|
| 216 | +ksort($this->aCodeGenerators); |
|
| 217 | + |
|
| 218 | +// Cannot be injected because of dependency loop. |
|
| 219 | +$this->xAssetManager = $this->di->getAssetManager(); |
|
| 220 | + |
|
| 221 | +$this->sJsOptions = $this->xAssetManager->getJsOptions(); |
|
| 222 | +foreach($this->aCodeGenerators as $sClassName) |
|
| 223 | +{ |
|
| 224 | +$this->generatePluginCodes($this->getCodeGenerator($sClassName)); |
|
| 225 | +} |
|
| 226 | + |
|
| 227 | +// Load the Jaxon lib js files, after the other libs js files. |
|
| 228 | +$this->aJs[] = trim($this->render('includes.js', [ |
|
| 229 | +'aUrls' => $this->xAssetManager->getJsLibFiles(), |
|
| 230 | +])); |
|
| 231 | + |
|
| 232 | +// The codes are already generated. |
|
| 233 | +$this->bGenerated = true; |
|
| 234 | +} |
|
| 235 | + |
|
| 236 | +/** |
|
| 237 | 237 | * Get the HTML tags to include Jaxon CSS code and files into the page |
| 238 | 238 | * |
| 239 | 239 | * @return string |
| 240 | 240 | * @throws UriException |
| 241 | 241 | */ |
| 242 | - public function getCss(): string |
|
| 243 | - { |
|
| 244 | - $this->generateCodes(); |
|
| 245 | - return implode("\n\n", $this->aCss); |
|
| 246 | - } |
|
| 242 | +public function getCss(): string |
|
| 243 | +{ |
|
| 244 | +$this->generateCodes(); |
|
| 245 | +return implode("\n\n", $this->aCss); |
|
| 246 | +} |
|
| 247 | 247 | |
| 248 | - /** |
|
| 248 | +/** |
|
| 249 | 249 | * Get the HTML tags to include Jaxon javascript files into the page |
| 250 | 250 | * |
| 251 | 251 | * @return string |
| 252 | 252 | * @throws UriException |
| 253 | 253 | */ |
| 254 | - public function getJs(): string |
|
| 255 | - { |
|
| 256 | - $this->generateCodes(); |
|
| 257 | - return implode("\n\n", $this->aJs); |
|
| 258 | - } |
|
| 254 | +public function getJs(): string |
|
| 255 | +{ |
|
| 256 | +$this->generateCodes(); |
|
| 257 | +return implode("\n\n", $this->aJs); |
|
| 258 | +} |
|
| 259 | 259 | |
| 260 | - /** |
|
| 260 | +/** |
|
| 261 | 261 | * Get the Javascript code |
| 262 | 262 | * |
| 263 | 263 | * @return string |
| 264 | 264 | */ |
| 265 | - public function getJsScript(): string |
|
| 266 | - { |
|
| 267 | - $aJsScripts = []; |
|
| 268 | - foreach($this->aCodeGenerators as $sClassName) |
|
| 269 | - { |
|
| 270 | - $xGenerator = $this->getCodeGenerator($sClassName); |
|
| 271 | - // Javascript code |
|
| 272 | - if(($sJsScript = trim($xGenerator->getScript(), " \n")) !== '') |
|
| 273 | - { |
|
| 274 | - $aJsScripts[] = $sJsScript; |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - return implode("\n\n", $aJsScripts); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 265 | +public function getJsScript(): string |
|
| 266 | +{ |
|
| 267 | +$aJsScripts = []; |
|
| 268 | +foreach($this->aCodeGenerators as $sClassName) |
|
| 269 | +{ |
|
| 270 | +$xGenerator = $this->getCodeGenerator($sClassName); |
|
| 271 | +// Javascript code |
|
| 272 | +if(($sJsScript = trim($xGenerator->getScript(), " \n")) !== '') |
|
| 273 | +{ |
|
| 274 | + $aJsScripts[] = $sJsScript; |
|
| 275 | +} |
|
| 276 | +} |
|
| 277 | +return implode("\n\n", $aJsScripts); |
|
| 278 | +} |
|
| 279 | + |
|
| 280 | +/** |
|
| 281 | 281 | * @param bool $bIncludeJs Also get the JS files |
| 282 | 282 | * @param bool $bIncludeCss Also get the CSS files |
| 283 | 283 | * |
| 284 | 284 | * @return array<string> |
| 285 | 285 | */ |
| 286 | - private function renderCodes(bool $bIncludeJs, bool $bIncludeCss): array |
|
| 287 | - { |
|
| 288 | - $aCodes = []; |
|
| 289 | - if($bIncludeCss) |
|
| 290 | - { |
|
| 291 | - $aCodes[] = $this->getCss(); |
|
| 292 | - } |
|
| 293 | - if($bIncludeJs) |
|
| 294 | - { |
|
| 295 | - $aCodes[] = $this->getJs(); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - $sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' : |
|
| 299 | - $this->xAssetManager->createJsFiles($this); |
|
| 300 | - // Wrap the js code into the corresponding HTML tag. |
|
| 301 | - $aCodes[] = $sUrl !== '' ? |
|
| 302 | - $this->render('include.js', ['sUrl' => $sUrl]) : |
|
| 303 | - $this->render('wrapper.js', ['sScript' => $this->getJsScript()]); |
|
| 304 | - |
|
| 305 | - // Wrap the js codes into HTML tags. |
|
| 306 | - if(count($this->aCodeJsBefore) > 0) |
|
| 307 | - { |
|
| 308 | - $sScript = implode("\n\n", $this->aCodeJsBefore); |
|
| 309 | - $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
|
| 310 | - } |
|
| 311 | - if(count($this->aCodeJs) > 0) |
|
| 312 | - { |
|
| 313 | - $sScript = implode("\n\n", $this->aCodeJs); |
|
| 314 | - $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
|
| 315 | - } |
|
| 316 | - if(count($this->aCodeJsFiles) > 0) |
|
| 317 | - { |
|
| 318 | - $aCodes[] = $this->render('includes.js', ['aUrls' => $this->aCodeJsFiles]); |
|
| 319 | - } |
|
| 320 | - if(count($this->aCodeJsAfter) > 0) |
|
| 321 | - { |
|
| 322 | - $sScript = implode("\n\n", $this->aCodeJsAfter); |
|
| 323 | - $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
|
| 324 | - } |
|
| 325 | - return $aCodes; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 286 | +private function renderCodes(bool $bIncludeJs, bool $bIncludeCss): array |
|
| 287 | +{ |
|
| 288 | +$aCodes = []; |
|
| 289 | +if($bIncludeCss) |
|
| 290 | +{ |
|
| 291 | +$aCodes[] = $this->getCss(); |
|
| 292 | +} |
|
| 293 | +if($bIncludeJs) |
|
| 294 | +{ |
|
| 295 | +$aCodes[] = $this->getJs(); |
|
| 296 | +} |
|
| 297 | + |
|
| 298 | +$sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' : |
|
| 299 | +$this->xAssetManager->createJsFiles($this); |
|
| 300 | +// Wrap the js code into the corresponding HTML tag. |
|
| 301 | +$aCodes[] = $sUrl !== '' ? |
|
| 302 | +$this->render('include.js', ['sUrl' => $sUrl]) : |
|
| 303 | +$this->render('wrapper.js', ['sScript' => $this->getJsScript()]); |
|
| 304 | + |
|
| 305 | +// Wrap the js codes into HTML tags. |
|
| 306 | +if(count($this->aCodeJsBefore) > 0) |
|
| 307 | +{ |
|
| 308 | +$sScript = implode("\n\n", $this->aCodeJsBefore); |
|
| 309 | +$aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
|
| 310 | +} |
|
| 311 | +if(count($this->aCodeJs) > 0) |
|
| 312 | +{ |
|
| 313 | +$sScript = implode("\n\n", $this->aCodeJs); |
|
| 314 | +$aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
|
| 315 | +} |
|
| 316 | +if(count($this->aCodeJsFiles) > 0) |
|
| 317 | +{ |
|
| 318 | +$aCodes[] = $this->render('includes.js', ['aUrls' => $this->aCodeJsFiles]); |
|
| 319 | +} |
|
| 320 | +if(count($this->aCodeJsAfter) > 0) |
|
| 321 | +{ |
|
| 322 | +$sScript = implode("\n\n", $this->aCodeJsAfter); |
|
| 323 | +$aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
|
| 324 | +} |
|
| 325 | +return $aCodes; |
|
| 326 | +} |
|
| 327 | + |
|
| 328 | +/** |
|
| 329 | 329 | * Get the javascript code to be sent to the browser |
| 330 | 330 | * |
| 331 | 331 | * @param bool $bIncludeJs Also get the JS files |
@@ -334,10 +334,10 @@ discard block |
||
| 334 | 334 | * @return string |
| 335 | 335 | * @throws UriException |
| 336 | 336 | */ |
| 337 | - public function getScript(bool $bIncludeJs, bool $bIncludeCss): string |
|
| 338 | - { |
|
| 339 | - $this->generateCodes(); |
|
| 340 | - $aCodes = $this->renderCodes($bIncludeJs, $bIncludeCss); |
|
| 341 | - return implode("\n\n", $aCodes); |
|
| 342 | - } |
|
| 337 | +public function getScript(bool $bIncludeJs, bool $bIncludeCss): string |
|
| 338 | +{ |
|
| 339 | +$this->generateCodes(); |
|
| 340 | +$aCodes = $this->renderCodes($bIncludeJs, $bIncludeCss); |
|
| 341 | +return implode("\n\n", $aCodes); |
|
| 342 | +} |
|
| 343 | 343 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function addCodeGenerator(string $sClassName, int $nPriority): void |
| 111 | 111 | { |
| 112 | - while(isset($this->aCodeGenerators[$nPriority])) |
|
| 112 | + while (isset($this->aCodeGenerators[$nPriority])) |
|
| 113 | 113 | { |
| 114 | 114 | $nPriority++; |
| 115 | 115 | } |
@@ -162,33 +162,33 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | private function generatePluginCodes(CodeGeneratorInterface $xGenerator): void |
| 164 | 164 | { |
| 165 | - if(!is_subclass_of($xGenerator, AbstractPlugin::class) || |
|
| 165 | + if (!is_subclass_of($xGenerator, AbstractPlugin::class) || |
|
| 166 | 166 | $this->xAssetManager->shallIncludeAssets($xGenerator)) |
| 167 | 167 | { |
| 168 | 168 | // HTML tags for CSS |
| 169 | - if(($sCss = trim($xGenerator->getCss(), " \n")) !== '') |
|
| 169 | + if (($sCss = trim($xGenerator->getCss(), " \n")) !== '') |
|
| 170 | 170 | { |
| 171 | 171 | $this->aCss[] = $sCss; |
| 172 | 172 | } |
| 173 | 173 | // HTML tags for js |
| 174 | - if(($sJs = trim($xGenerator->getJs(), " \n")) !== '') |
|
| 174 | + if (($sJs = trim($xGenerator->getJs(), " \n")) !== '') |
|
| 175 | 175 | { |
| 176 | 176 | $this->aJs[] = $sJs; |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | // Additional js codes |
| 181 | - if(($xJsCode = $xGenerator->getJsCode()) !== null) |
|
| 181 | + if (($xJsCode = $xGenerator->getJsCode()) !== null) |
|
| 182 | 182 | { |
| 183 | - if(($sJs = trim($xJsCode->sJs, " \n")) !== '') |
|
| 183 | + if (($sJs = trim($xJsCode->sJs, " \n")) !== '') |
|
| 184 | 184 | { |
| 185 | 185 | $this->aCodeJs[] = $sJs; |
| 186 | 186 | } |
| 187 | - if(($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '') |
|
| 187 | + if (($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '') |
|
| 188 | 188 | { |
| 189 | 189 | $this->aCodeJsBefore[] = $sJsBefore; |
| 190 | 190 | } |
| 191 | - if(($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '') |
|
| 191 | + if (($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '') |
|
| 192 | 192 | { |
| 193 | 193 | $this->aCodeJsAfter[] = $sJsAfter; |
| 194 | 194 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | private function generateCodes(): void |
| 206 | 206 | { |
| 207 | - if($this->bGenerated) |
|
| 207 | + if ($this->bGenerated) |
|
| 208 | 208 | { |
| 209 | 209 | return; |
| 210 | 210 | } |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | $this->xAssetManager = $this->di->getAssetManager(); |
| 220 | 220 | |
| 221 | 221 | $this->sJsOptions = $this->xAssetManager->getJsOptions(); |
| 222 | - foreach($this->aCodeGenerators as $sClassName) |
|
| 222 | + foreach ($this->aCodeGenerators as $sClassName) |
|
| 223 | 223 | { |
| 224 | 224 | $this->generatePluginCodes($this->getCodeGenerator($sClassName)); |
| 225 | 225 | } |
@@ -265,11 +265,11 @@ discard block |
||
| 265 | 265 | public function getJsScript(): string |
| 266 | 266 | { |
| 267 | 267 | $aJsScripts = []; |
| 268 | - foreach($this->aCodeGenerators as $sClassName) |
|
| 268 | + foreach ($this->aCodeGenerators as $sClassName) |
|
| 269 | 269 | { |
| 270 | 270 | $xGenerator = $this->getCodeGenerator($sClassName); |
| 271 | 271 | // Javascript code |
| 272 | - if(($sJsScript = trim($xGenerator->getScript(), " \n")) !== '') |
|
| 272 | + if (($sJsScript = trim($xGenerator->getScript(), " \n")) !== '') |
|
| 273 | 273 | { |
| 274 | 274 | $aJsScripts[] = $sJsScript; |
| 275 | 275 | } |
@@ -286,38 +286,36 @@ discard block |
||
| 286 | 286 | private function renderCodes(bool $bIncludeJs, bool $bIncludeCss): array |
| 287 | 287 | { |
| 288 | 288 | $aCodes = []; |
| 289 | - if($bIncludeCss) |
|
| 289 | + if ($bIncludeCss) |
|
| 290 | 290 | { |
| 291 | 291 | $aCodes[] = $this->getCss(); |
| 292 | 292 | } |
| 293 | - if($bIncludeJs) |
|
| 293 | + if ($bIncludeJs) |
|
| 294 | 294 | { |
| 295 | 295 | $aCodes[] = $this->getJs(); |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - $sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' : |
|
| 299 | - $this->xAssetManager->createJsFiles($this); |
|
| 298 | + $sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' : $this->xAssetManager->createJsFiles($this); |
|
| 300 | 299 | // Wrap the js code into the corresponding HTML tag. |
| 301 | 300 | $aCodes[] = $sUrl !== '' ? |
| 302 | - $this->render('include.js', ['sUrl' => $sUrl]) : |
|
| 303 | - $this->render('wrapper.js', ['sScript' => $this->getJsScript()]); |
|
| 301 | + $this->render('include.js', ['sUrl' => $sUrl]) : $this->render('wrapper.js', ['sScript' => $this->getJsScript()]); |
|
| 304 | 302 | |
| 305 | 303 | // Wrap the js codes into HTML tags. |
| 306 | - if(count($this->aCodeJsBefore) > 0) |
|
| 304 | + if (count($this->aCodeJsBefore) > 0) |
|
| 307 | 305 | { |
| 308 | 306 | $sScript = implode("\n\n", $this->aCodeJsBefore); |
| 309 | 307 | $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
| 310 | 308 | } |
| 311 | - if(count($this->aCodeJs) > 0) |
|
| 309 | + if (count($this->aCodeJs) > 0) |
|
| 312 | 310 | { |
| 313 | 311 | $sScript = implode("\n\n", $this->aCodeJs); |
| 314 | 312 | $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
| 315 | 313 | } |
| 316 | - if(count($this->aCodeJsFiles) > 0) |
|
| 314 | + if (count($this->aCodeJsFiles) > 0) |
|
| 317 | 315 | { |
| 318 | 316 | $aCodes[] = $this->render('includes.js', ['aUrls' => $this->aCodeJsFiles]); |
| 319 | 317 | } |
| 320 | - if(count($this->aCodeJsAfter) > 0) |
|
| 318 | + if (count($this->aCodeJsAfter) > 0) |
|
| 321 | 319 | { |
| 322 | 320 | $sScript = implode("\n\n", $this->aCodeJsAfter); |
| 323 | 321 | $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
@@ -10,24 +10,24 @@ |
||
| 10 | 10 | jxn.config.defaultMethod = '<?php echo $this->sDefaultMethod ?>'; |
| 11 | 11 | jxn.config.responseType = '<?php echo $this->sResponseType ?>'; |
| 12 | 12 | |
| 13 | -<?php if($this->nResponseQueueSize > 0): ?> |
|
| 13 | +<?php if ($this->nResponseQueueSize > 0): ?> |
|
| 14 | 14 | jxn.config.responseQueueSize = <?php echo $this->nResponseQueueSize ?>; |
| 15 | 15 | <?php endif ?> |
| 16 | 16 | |
| 17 | -<?php if($this->bLoggingEnabled): ?> |
|
| 17 | +<?php if ($this->bLoggingEnabled): ?> |
|
| 18 | 18 | jxn.debug.logger = '<?php echo Jaxon\rq(Jaxon\App\Component\Logger::class)->_class() ?>'; |
| 19 | 19 | <?php endif ?> |
| 20 | 20 | |
| 21 | -<?php if($this->bDebug): ?> |
|
| 21 | +<?php if ($this->bDebug): ?> |
|
| 22 | 22 | jxn.debug.active = true; |
| 23 | -<?php if($this->sDebugOutputID): ?> |
|
| 23 | +<?php if ($this->sDebugOutputID): ?> |
|
| 24 | 24 | jxn.debug.outputID = '<?php echo $this->sDebugOutputID ?>'; |
| 25 | 25 | <?php endif ?> |
| 26 | -<?php if($this->bVerboseDebug): ?> |
|
| 26 | +<?php if ($this->bVerboseDebug): ?> |
|
| 27 | 27 | jxn.debug.verbose.active = true; |
| 28 | 28 | <?php endif ?> |
| 29 | 29 | <?php endif ?> |
| 30 | 30 | |
| 31 | -<?php if($this->sCsrfMetaName): ?> |
|
| 31 | +<?php if ($this->sCsrfMetaName): ?> |
|
| 32 | 32 | jxn.setCsrf('<?php echo $this->sCsrfMetaName ?>'); |
| 33 | 33 | <?php endif ?> |
@@ -7,15 +7,15 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | class Logger |
| 9 | 9 | { |
| 10 | - use LoggerTrait; |
|
| 10 | +use LoggerTrait; |
|
| 11 | 11 | |
| 12 | - /** |
|
| 12 | +/** |
|
| 13 | 13 | * @param LoggerInterface $logger |
| 14 | 14 | */ |
| 15 | - public function __construct(private LoggerInterface $logger) |
|
| 16 | - {} |
|
| 15 | +public function __construct(private LoggerInterface $logger) |
|
| 16 | +{} |
|
| 17 | 17 | |
| 18 | - /** |
|
| 18 | +/** |
|
| 19 | 19 | * Logs with an arbitrary level. |
| 20 | 20 | * |
| 21 | 21 | * @param mixed $level |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @return void |
| 26 | 26 | */ |
| 27 | - public function log($level, string|\Stringable $message, array $context = []): void |
|
| 28 | - { |
|
| 29 | - $this->logger->log($level, $message, $context); |
|
| 30 | - } |
|
| 27 | +public function log($level, string|\Stringable $message, array $context = []): void |
|
| 28 | +{ |
|
| 29 | +$this->logger->log($level, $message, $context); |
|
| 30 | +} |
|
| 31 | 31 | } |