@@ -91,15 +91,15 @@ |
||
| 91 | 91 | return $this->xManager->getErrorMessage(); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Add a response command to the array of commands |
|
| 96 | - * |
|
| 97 | - * @param string $sName The command name |
|
| 98 | - * @param array|JsonSerializable $aArgs The command arguments |
|
| 99 | - * @param bool $bRemoveEmpty |
|
| 100 | - * |
|
| 101 | - * @return Command |
|
| 102 | - */ |
|
| 94 | + /** |
|
| 95 | + * Add a response command to the array of commands |
|
| 96 | + * |
|
| 97 | + * @param string $sName The command name |
|
| 98 | + * @param array|JsonSerializable $aArgs The command arguments |
|
| 99 | + * @param bool $bRemoveEmpty |
|
| 100 | + * |
|
| 101 | + * @return Command |
|
| 102 | + */ |
|
| 103 | 103 | public function addCommand(string $sName, array|JsonSerializable $aArgs = [], |
| 104 | 104 | bool $bRemoveEmpty = false): Command |
| 105 | 105 | { |
@@ -218,8 +218,7 @@ |
||
| 218 | 218 | { |
| 219 | 219 | // A string is supposed to be the path to a config file. |
| 220 | 220 | $aLibOptions = $this->xConfigManager->read($aLibOptions); |
| 221 | - } |
|
| 222 | - elseif(!is_array($aLibOptions)) |
|
| 221 | + } elseif(!is_array($aLibOptions)) |
|
| 223 | 222 | { |
| 224 | 223 | // Otherwise, anything else than an array is not accepted. |
| 225 | 224 | $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
@@ -62,25 +62,25 @@ discard block |
||
| 62 | 62 | private function updateContainer(Config $xConfig): void |
| 63 | 63 | { |
| 64 | 64 | $aOptions = $xConfig->getOption('container.set', []); |
| 65 | - foreach($aOptions as $xKey => $xValue) |
|
| 65 | + foreach ($aOptions as $xKey => $xValue) |
|
| 66 | 66 | { |
| 67 | 67 | // The key is the class name. It must be a string. |
| 68 | 68 | $this->di->set((string)$xKey, $xValue); |
| 69 | 69 | } |
| 70 | 70 | $aOptions = $xConfig->getOption('container.val', []); |
| 71 | - foreach($aOptions as $xKey => $xValue) |
|
| 71 | + foreach ($aOptions as $xKey => $xValue) |
|
| 72 | 72 | { |
| 73 | 73 | // The key is the class name. It must be a string. |
| 74 | 74 | $this->di->val((string)$xKey, $xValue); |
| 75 | 75 | } |
| 76 | 76 | $aOptions = $xConfig->getOption('container.auto', []); |
| 77 | - foreach($aOptions as $xValue) |
|
| 77 | + foreach ($aOptions as $xValue) |
|
| 78 | 78 | { |
| 79 | 79 | // The key is the class name. It must be a string. |
| 80 | 80 | $this->di->auto((string)$xValue); |
| 81 | 81 | } |
| 82 | 82 | $aOptions = $xConfig->getOption('container.alias', []); |
| 83 | - foreach($aOptions as $xKey => $xValue) |
|
| 83 | + foreach ($aOptions as $xKey => $xValue) |
|
| 84 | 84 | { |
| 85 | 85 | // The key is the class name. It must be a string. |
| 86 | 86 | $this->di->alias((string)$xKey, (string)$xValue); |
@@ -98,16 +98,16 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | private function registerCallables(array $aOptions, string $sCallableType): void |
| 100 | 100 | { |
| 101 | - foreach($aOptions as $xKey => $xValue) |
|
| 101 | + foreach ($aOptions as $xKey => $xValue) |
|
| 102 | 102 | { |
| 103 | - if(is_integer($xKey) && is_string($xValue)) |
|
| 103 | + if (is_integer($xKey) && is_string($xValue)) |
|
| 104 | 104 | { |
| 105 | 105 | // Register a function without options |
| 106 | 106 | $this->xPluginManager->registerCallable($sCallableType, $xValue); |
| 107 | 107 | continue; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if(is_string($xKey) && (is_array($xValue) || is_string($xValue))) |
|
| 110 | + if (is_string($xKey) && (is_array($xValue) || is_string($xValue))) |
|
| 111 | 111 | { |
| 112 | 112 | // Register a function with options |
| 113 | 113 | $this->xPluginManager->registerCallable($sCallableType, $xKey, $xValue); |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | private function registerExceptionHandlers(Config $xConfig): void |
| 126 | 126 | { |
| 127 | - foreach($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler) |
|
| 127 | + foreach ($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler) |
|
| 128 | 128 | { |
| 129 | 129 | $this->xCallbackManager->error($xExHandler, is_string($sExClass) ? $sExClass : ''); |
| 130 | 130 | } |
@@ -147,20 +147,20 @@ discard block |
||
| 147 | 147 | // key of the array item, a string as the value of an entry without a key, |
| 148 | 148 | // or set with the key $sOptionKey in an array entry without a key. |
| 149 | 149 | $aCallables = []; |
| 150 | - foreach($xConfig->getOption($sOptionName, []) as $xKey => $xValue) |
|
| 150 | + foreach ($xConfig->getOption($sOptionName, []) as $xKey => $xValue) |
|
| 151 | 151 | { |
| 152 | - if(is_string($xKey)) |
|
| 152 | + if (is_string($xKey)) |
|
| 153 | 153 | { |
| 154 | 154 | $aCallables[$xKey] = $xValue; |
| 155 | 155 | continue; |
| 156 | 156 | } |
| 157 | - if(is_string($xValue)) |
|
| 157 | + if (is_string($xValue)) |
|
| 158 | 158 | { |
| 159 | 159 | $aCallables[] = $xValue; |
| 160 | 160 | continue; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if(is_array($xValue) && isset($xValue[$sOptionKey])) |
|
| 163 | + if (is_array($xValue) && isset($xValue[$sOptionKey])) |
|
| 164 | 164 | { |
| 165 | 165 | $aCallables[$xValue[$sOptionKey]] = $xValue; |
| 166 | 166 | } |
@@ -215,12 +215,12 @@ discard block |
||
| 215 | 215 | { |
| 216 | 216 | // $this->aPackages contains packages config file paths. |
| 217 | 217 | $aLibOptions = $sClassName::config(); |
| 218 | - if(is_string($aLibOptions)) |
|
| 218 | + if (is_string($aLibOptions)) |
|
| 219 | 219 | { |
| 220 | 220 | // A string is supposed to be the path to a config file. |
| 221 | 221 | $aLibOptions = $this->xConfigManager->read($aLibOptions); |
| 222 | 222 | } |
| 223 | - elseif(!is_array($aLibOptions)) |
|
| 223 | + elseif (!is_array($aLibOptions)) |
|
| 224 | 224 | { |
| 225 | 225 | // Otherwise, anything else than an array is not accepted. |
| 226 | 226 | $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | public function registerPackage(string $sClassName, array $aUserOptions = []): void |
| 244 | 244 | { |
| 245 | 245 | $sClassName = trim($sClassName, '\\ '); |
| 246 | - if(!is_subclass_of($sClassName, AbstractPackage::class)) |
|
| 246 | + if (!is_subclass_of($sClassName, AbstractPackage::class)) |
|
| 247 | 247 | { |
| 248 | 248 | $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
| 249 | 249 | throw new SetupException($sMessage); |
@@ -287,9 +287,9 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | // Register packages |
| 289 | 289 | $aPackageConfig = $xAppConfig->getOption('packages', []); |
| 290 | - foreach($aPackageConfig as $xKey => $xValue) |
|
| 290 | + foreach ($aPackageConfig as $xKey => $xValue) |
|
| 291 | 291 | { |
| 292 | - if(is_integer($xKey) && is_string($xValue)) |
|
| 292 | + if (is_integer($xKey) && is_string($xValue)) |
|
| 293 | 293 | { |
| 294 | 294 | // Register a package without options |
| 295 | 295 | $sClassName = $xValue; |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | continue; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - if(is_string($xKey) && is_array($xValue)) |
|
| 300 | + if (is_string($xKey) && is_array($xValue)) |
|
| 301 | 301 | { |
| 302 | 302 | // Register a package with options |
| 303 | 303 | $sClassName = $xKey; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | private function _registerPlugin(string $sClassName, string $sPluginName, array $aInterfaces): int |
| 101 | 101 | { |
| 102 | 102 | // Any plugin must implement the PluginInterface interface. |
| 103 | - if(!in_array(PluginInterface::class, $aInterfaces)) |
|
| 103 | + if (!in_array(PluginInterface::class, $aInterfaces)) |
|
| 104 | 104 | { |
| 105 | 105 | $sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
| 106 | 106 | 'name' => $sClassName, |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // Response plugin. |
| 112 | - if(in_array(ResponsePluginInterface::class, $aInterfaces)) |
|
| 112 | + if (in_array(ResponsePluginInterface::class, $aInterfaces)) |
|
| 113 | 113 | { |
| 114 | 114 | $this->aResponsePlugins[$sPluginName] = $sClassName; |
| 115 | 115 | return 1; |
@@ -117,12 +117,12 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | // Request plugin. |
| 119 | 119 | $nCount = 0; |
| 120 | - if(in_array(CallableRegistryInterface::class, $aInterfaces)) |
|
| 120 | + if (in_array(CallableRegistryInterface::class, $aInterfaces)) |
|
| 121 | 121 | { |
| 122 | 122 | $this->aRegistryPlugins[$sPluginName] = $sClassName; |
| 123 | 123 | $nCount++; |
| 124 | 124 | } |
| 125 | - if(in_array(RequestHandlerInterface::class, $aInterfaces)) |
|
| 125 | + if (in_array(RequestHandlerInterface::class, $aInterfaces)) |
|
| 126 | 126 | { |
| 127 | 127 | $this->aRequestHandlers[$sPluginName] = $sClassName; |
| 128 | 128 | $nCount++; |
@@ -151,13 +151,13 @@ discard block |
||
| 151 | 151 | $nCount = $this->_registerPlugin($sClassName, $sPluginName, $aInterfaces); |
| 152 | 152 | |
| 153 | 153 | // Any plugin can implement the CodeGeneratorInterface interface. |
| 154 | - if(in_array(CodeGeneratorInterface::class, $aInterfaces)) |
|
| 154 | + if (in_array(CodeGeneratorInterface::class, $aInterfaces)) |
|
| 155 | 155 | { |
| 156 | 156 | $this->xCodeGenerator->addCodeGenerator($sClassName, $nPriority); |
| 157 | 157 | $nCount++; |
| 158 | 158 | } |
| 159 | 159 | // The class is not a valid plugin. |
| 160 | - if($nCount === 0) |
|
| 160 | + if ($nCount === 0) |
|
| 161 | 161 | { |
| 162 | 162 | $sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
| 163 | 163 | 'name' => $sClassName, |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | // Register the plugin in the DI container, if necessary |
| 169 | - if(!$this->di->has($sClassName)) |
|
| 169 | + if (!$this->di->has($sClassName)) |
|
| 170 | 170 | { |
| 171 | 171 | $this->di->auto($sClassName); |
| 172 | 172 | } |
@@ -182,8 +182,7 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | public function getResponsePlugin(string $sName): ?ResponsePluginInterface |
| 184 | 184 | { |
| 185 | - return $this->di->h($sName) ? $this->di->g($sName) : |
|
| 186 | - (!isset($this->aResponsePlugins[$sName]) ? null : |
|
| 185 | + return $this->di->h($sName) ? $this->di->g($sName) : (!isset($this->aResponsePlugins[$sName]) ? null : |
|
| 187 | 186 | $this->di->g($this->aResponsePlugins[$sName])); |
| 188 | 187 | } |
| 189 | 188 | |
@@ -201,7 +200,7 @@ discard block |
||
| 201 | 200 | */ |
| 202 | 201 | public function registerCallable(string $sType, string $sCallable, $xOptions = []): void |
| 203 | 202 | { |
| 204 | - if(isset($this->aRegistryPlugins[$sType]) && |
|
| 203 | + if (isset($this->aRegistryPlugins[$sType]) && |
|
| 205 | 204 | ($xPlugin = $this->di->g($this->aRegistryPlugins[$sType]))) |
| 206 | 205 | { |
| 207 | 206 | $xPlugin->register($sType, $sCallable, $xPlugin->checkOptions($sCallable, $xOptions)); |
@@ -63,7 +63,7 @@ |
||
| 63 | 63 | public function ajaxResponse(): ResponseInterface |
| 64 | 64 | { |
| 65 | 65 | $xPsrResponse = $this->xPsr17Factory->createResponse(200); |
| 66 | - if($this->xRequest->getMethod() === 'GET') |
|
| 66 | + if ($this->xRequest->getMethod() === 'GET') |
|
| 67 | 67 | { |
| 68 | 68 | $xPsrResponse = $xPsrResponse |
| 69 | 69 | ->withHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT') |
@@ -23,56 +23,56 @@ |
||
| 23 | 23 | |
| 24 | 24 | class PsrPlugin extends AbstractResponsePlugin |
| 25 | 25 | { |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * @const The plugin name |
| 28 | 28 | */ |
| 29 | - public const NAME = 'psr'; |
|
| 29 | +public const NAME = 'psr'; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * The class constructor |
| 33 | 33 | * |
| 34 | 34 | * @param Psr17Factory $xPsr17Factory |
| 35 | 35 | * @param RequestInterface $xRequest |
| 36 | 36 | */ |
| 37 | - public function __construct(private Psr17Factory $xPsr17Factory, |
|
| 38 | - private RequestInterface $xRequest) |
|
| 39 | - {} |
|
| 37 | +public function __construct(private Psr17Factory $xPsr17Factory, |
|
| 38 | +private RequestInterface $xRequest) |
|
| 39 | +{} |
|
| 40 | 40 | |
| 41 | - /** |
|
| 41 | +/** |
|
| 42 | 42 | * @inheritDoc |
| 43 | 43 | */ |
| 44 | - public function getName(): string |
|
| 45 | - { |
|
| 46 | - return self::NAME; |
|
| 47 | - } |
|
| 44 | +public function getName(): string |
|
| 45 | +{ |
|
| 46 | +return self::NAME; |
|
| 47 | +} |
|
| 48 | 48 | |
| 49 | - /** |
|
| 49 | +/** |
|
| 50 | 50 | * @inheritDoc |
| 51 | 51 | */ |
| 52 | - public function getHash(): string |
|
| 53 | - { |
|
| 54 | - // Use the version number as hash |
|
| 55 | - return '5.0.0'; |
|
| 56 | - } |
|
| 52 | +public function getHash(): string |
|
| 53 | +{ |
|
| 54 | +// Use the version number as hash |
|
| 55 | +return '5.0.0'; |
|
| 56 | +} |
|
| 57 | 57 | |
| 58 | - /** |
|
| 58 | +/** |
|
| 59 | 59 | * Convert an ajax response to a PSR7 response object |
| 60 | 60 | * |
| 61 | 61 | * @return ResponseInterface |
| 62 | 62 | */ |
| 63 | - public function ajaxResponse(): ResponseInterface |
|
| 64 | - { |
|
| 65 | - $xPsrResponse = $this->xPsr17Factory->createResponse(200); |
|
| 66 | - if($this->xRequest->getMethod() === 'GET') |
|
| 67 | - { |
|
| 68 | - $xPsrResponse = $xPsrResponse |
|
| 69 | - ->withHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT') |
|
| 70 | - ->withHeader('Last-Modified', gmdate("D, d M Y H:i:s") . ' GMT') |
|
| 71 | - ->withHeader('Cache-Control', 'no-cache, must-revalidate') |
|
| 72 | - ->withHeader('Pragma', 'no-cache'); |
|
| 73 | - } |
|
| 74 | - return $xPsrResponse |
|
| 75 | - ->withHeader('content-type', $this->response()->getContentType()) |
|
| 76 | - ->withBody(Stream::create($this->response()->getOutput())); |
|
| 77 | - } |
|
| 63 | +public function ajaxResponse(): ResponseInterface |
|
| 64 | +{ |
|
| 65 | +$xPsrResponse = $this->xPsr17Factory->createResponse(200); |
|
| 66 | +if($this->xRequest->getMethod() === 'GET') |
|
| 67 | +{ |
|
| 68 | +$xPsrResponse = $xPsrResponse |
|
| 69 | + ->withHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT') |
|
| 70 | + ->withHeader('Last-Modified', gmdate("D, d M Y H:i:s") . ' GMT') |
|
| 71 | + ->withHeader('Cache-Control', 'no-cache, must-revalidate') |
|
| 72 | + ->withHeader('Pragma', 'no-cache'); |
|
| 73 | +} |
|
| 74 | +return $xPsrResponse |
|
| 75 | +->withHeader('content-type', $this->response()->getContentType()) |
|
| 76 | +->withBody(Stream::create($this->response()->getOutput())); |
|
| 77 | +} |
|
| 78 | 78 | } |
@@ -52,8 +52,7 @@ |
||
| 52 | 52 | public function getScript(): string |
| 53 | 53 | { |
| 54 | 54 | // It is important to call $this->xParameterReader->uri() only if necessary. |
| 55 | - $sUri = $this->xConfigManager->getOption('core.request.uri') ?: |
|
| 56 | - $this->xParameterReader->uri(); |
|
| 55 | + $sUri = $this->xConfigManager->getOption('core.request.uri') ?: $this->xParameterReader->uri(); |
|
| 57 | 56 | $aOptions = [ |
| 58 | 57 | 'sResponseType' => 'JSON', |
| 59 | 58 | 'sVersion' => $this->option('core.version'), |
@@ -22,53 +22,53 @@ |
||
| 22 | 22 | |
| 23 | 23 | class ConfigScriptGenerator extends AbstractCodeGenerator |
| 24 | 24 | { |
| 25 | - /** |
|
| 25 | +/** |
|
| 26 | 26 | * The constructor |
| 27 | 27 | * |
| 28 | 28 | * @param ParameterReader $xParameterReader |
| 29 | 29 | * @param TemplateEngine $xTemplateEngine |
| 30 | 30 | * @param ConfigManager $xConfigManager |
| 31 | 31 | */ |
| 32 | - public function __construct(private ParameterReader $xParameterReader, |
|
| 33 | - private TemplateEngine $xTemplateEngine, private ConfigManager $xConfigManager) |
|
| 34 | - {} |
|
| 32 | +public function __construct(private ParameterReader $xParameterReader, |
|
| 33 | +private TemplateEngine $xTemplateEngine, private ConfigManager $xConfigManager) |
|
| 34 | +{} |
|
| 35 | 35 | |
| 36 | - /** |
|
| 36 | +/** |
|
| 37 | 37 | * Get the value of a config option |
| 38 | 38 | * |
| 39 | 39 | * @param string $sName The option name |
| 40 | 40 | * |
| 41 | 41 | * @return mixed |
| 42 | 42 | */ |
| 43 | - private function option(string $sName): mixed |
|
| 44 | - { |
|
| 45 | - return $this->xConfigManager->getOption($sName); |
|
| 46 | - } |
|
| 43 | +private function option(string $sName): mixed |
|
| 44 | +{ |
|
| 45 | +return $this->xConfigManager->getOption($sName); |
|
| 46 | +} |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * @inheritDoc |
| 50 | 50 | * @throws UriException |
| 51 | 51 | */ |
| 52 | - public function getScript(): string |
|
| 53 | - { |
|
| 54 | - // It is important to call $this->xParameterReader->uri() only if necessary. |
|
| 55 | - $sUri = $this->xConfigManager->getOption('core.request.uri') ?: |
|
| 56 | - $this->xParameterReader->uri(); |
|
| 57 | - $aOptions = [ |
|
| 58 | - 'sResponseType' => 'JSON', |
|
| 59 | - 'sVersion' => $this->option('core.version'), |
|
| 60 | - 'sLanguage' => $this->option('core.language'), |
|
| 61 | - 'sRequestURI' => $sUri, |
|
| 62 | - 'sDefaultMode' => $this->option('core.request.mode'), |
|
| 63 | - 'sDefaultMethod' => $this->option('core.request.method'), |
|
| 64 | - 'sCsrfMetaName' => $this->option('core.request.csrf_meta'), |
|
| 65 | - 'bDebug' => $this->option('core.debug.on'), |
|
| 66 | - 'bVerboseDebug' => $this->option('core.debug.verbose'), |
|
| 67 | - 'sDebugOutputID' => $this->option('core.debug.output_id'), |
|
| 68 | - 'nResponseQueueSize' => $this->option('js.lib.queue_size'), |
|
| 69 | - 'sStatusMessages' => $this->option('js.lib.show_status') ? 'true' : 'false', |
|
| 70 | - 'sWaitCursor' => $this->option('js.lib.show_cursor') ? 'true' : 'false', |
|
| 71 | - ]; |
|
| 72 | - return $this->xTemplateEngine->render('jaxon::plugins/config.js', $aOptions); |
|
| 73 | - } |
|
| 52 | +public function getScript(): string |
|
| 53 | +{ |
|
| 54 | +// It is important to call $this->xParameterReader->uri() only if necessary. |
|
| 55 | +$sUri = $this->xConfigManager->getOption('core.request.uri') ?: |
|
| 56 | +$this->xParameterReader->uri(); |
|
| 57 | +$aOptions = [ |
|
| 58 | +'sResponseType' => 'JSON', |
|
| 59 | +'sVersion' => $this->option('core.version'), |
|
| 60 | +'sLanguage' => $this->option('core.language'), |
|
| 61 | +'sRequestURI' => $sUri, |
|
| 62 | +'sDefaultMode' => $this->option('core.request.mode'), |
|
| 63 | +'sDefaultMethod' => $this->option('core.request.method'), |
|
| 64 | +'sCsrfMetaName' => $this->option('core.request.csrf_meta'), |
|
| 65 | +'bDebug' => $this->option('core.debug.on'), |
|
| 66 | +'bVerboseDebug' => $this->option('core.debug.verbose'), |
|
| 67 | +'sDebugOutputID' => $this->option('core.debug.output_id'), |
|
| 68 | +'nResponseQueueSize' => $this->option('js.lib.queue_size'), |
|
| 69 | +'sStatusMessages' => $this->option('js.lib.show_status') ? 'true' : 'false', |
|
| 70 | +'sWaitCursor' => $this->option('js.lib.show_cursor') ? 'true' : 'false', |
|
| 71 | +]; |
|
| 72 | +return $this->xTemplateEngine->render('jaxon::plugins/config.js', $aOptions); |
|
| 73 | +} |
|
| 74 | 74 | } |
@@ -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 | } |
@@ -163,33 +163,33 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | private function generatePluginCodes(CodeGeneratorInterface $xGenerator): void |
| 165 | 165 | { |
| 166 | - if(!is_subclass_of($xGenerator, AbstractPlugin::class) || |
|
| 166 | + if (!is_subclass_of($xGenerator, AbstractPlugin::class) || |
|
| 167 | 167 | $this->xAssetManager->shallIncludeAssets($xGenerator)) |
| 168 | 168 | { |
| 169 | 169 | // HTML tags for CSS |
| 170 | - if(($sCss = trim($xGenerator->getCss(), " \n")) !== '') |
|
| 170 | + if (($sCss = trim($xGenerator->getCss(), " \n")) !== '') |
|
| 171 | 171 | { |
| 172 | 172 | $this->aCss[] = $sCss; |
| 173 | 173 | } |
| 174 | 174 | // HTML tags for js |
| 175 | - if(($sJs = trim($xGenerator->getJs(), " \n")) !== '') |
|
| 175 | + if (($sJs = trim($xGenerator->getJs(), " \n")) !== '') |
|
| 176 | 176 | { |
| 177 | 177 | $this->aJs[] = $sJs; |
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | // Additional js codes |
| 182 | - if(($xJsCode = $xGenerator->getJsCode()) !== null) |
|
| 182 | + if (($xJsCode = $xGenerator->getJsCode()) !== null) |
|
| 183 | 183 | { |
| 184 | - if(($sJs = trim($xJsCode->sJs, " \n")) !== '') |
|
| 184 | + if (($sJs = trim($xJsCode->sJs, " \n")) !== '') |
|
| 185 | 185 | { |
| 186 | 186 | $this->aCodeJs[] = $sJs; |
| 187 | 187 | } |
| 188 | - if(($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '') |
|
| 188 | + if (($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '') |
|
| 189 | 189 | { |
| 190 | 190 | $this->aCodeJsBefore[] = $sJsBefore; |
| 191 | 191 | } |
| 192 | - if(($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '') |
|
| 192 | + if (($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '') |
|
| 193 | 193 | { |
| 194 | 194 | $this->aCodeJsAfter[] = $sJsAfter; |
| 195 | 195 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | private function generateCodes(): void |
| 207 | 207 | { |
| 208 | - if($this->bGenerated) |
|
| 208 | + if ($this->bGenerated) |
|
| 209 | 209 | { |
| 210 | 210 | return; |
| 211 | 211 | } |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | // Sort the code generators by ascending priority |
| 217 | 217 | ksort($this->aCodeGenerators); |
| 218 | 218 | |
| 219 | - foreach($this->aCodeGenerators as $sClassName) |
|
| 219 | + foreach ($this->aCodeGenerators as $sClassName) |
|
| 220 | 220 | { |
| 221 | 221 | $this->generatePluginCodes($this->getCodeGenerator($sClassName)); |
| 222 | 222 | } |
@@ -261,11 +261,11 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | public function getJsScript(): string |
| 263 | 263 | { |
| 264 | - foreach($this->aCodeGenerators as $sClassName) |
|
| 264 | + foreach ($this->aCodeGenerators as $sClassName) |
|
| 265 | 265 | { |
| 266 | 266 | $xGenerator = $this->getCodeGenerator($sClassName); |
| 267 | 267 | // Javascript code |
| 268 | - if(($sJsScript = trim($xGenerator->getScript(), " \n")) !== '') |
|
| 268 | + if (($sJsScript = trim($xGenerator->getScript(), " \n")) !== '') |
|
| 269 | 269 | { |
| 270 | 270 | $aJsScript[] = $sJsScript; |
| 271 | 271 | } |
@@ -282,38 +282,36 @@ discard block |
||
| 282 | 282 | private function renderCodes(bool $bIncludeJs, bool $bIncludeCss): array |
| 283 | 283 | { |
| 284 | 284 | $aCodes = []; |
| 285 | - if($bIncludeCss) |
|
| 285 | + if ($bIncludeCss) |
|
| 286 | 286 | { |
| 287 | 287 | $aCodes[] = $this->getCss(); |
| 288 | 288 | } |
| 289 | - if($bIncludeJs) |
|
| 289 | + if ($bIncludeJs) |
|
| 290 | 290 | { |
| 291 | 291 | $aCodes[] = $this->getJs(); |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - $sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' : |
|
| 295 | - $this->xAssetManager->createJsFiles($this); |
|
| 294 | + $sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' : $this->xAssetManager->createJsFiles($this); |
|
| 296 | 295 | // Wrap the js code into the corresponding HTML tag. |
| 297 | 296 | $aCodes[] = $sUrl !== '' ? |
| 298 | - $this->render('include.js', ['sUrl' => $sUrl]) : |
|
| 299 | - $this->render('wrapper.js', ['sScript' => $this->getJsScript()]); |
|
| 297 | + $this->render('include.js', ['sUrl' => $sUrl]) : $this->render('wrapper.js', ['sScript' => $this->getJsScript()]); |
|
| 300 | 298 | |
| 301 | 299 | // Wrap the js codes into HTML tags. |
| 302 | - if(count($this->aCodeJsBefore) > 0) |
|
| 300 | + if (count($this->aCodeJsBefore) > 0) |
|
| 303 | 301 | { |
| 304 | 302 | $sScript = implode("\n\n", $this->aCodeJsBefore); |
| 305 | 303 | $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
| 306 | 304 | } |
| 307 | - if(count($this->aCodeJs) > 0) |
|
| 305 | + if (count($this->aCodeJs) > 0) |
|
| 308 | 306 | { |
| 309 | 307 | $sScript = implode("\n\n", $this->aCodeJs); |
| 310 | 308 | $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
| 311 | 309 | } |
| 312 | - if(count($this->aCodeJsFiles) > 0) |
|
| 310 | + if (count($this->aCodeJsFiles) > 0) |
|
| 313 | 311 | { |
| 314 | 312 | $aCodes[] = $this->render('includes.js', ['aUrls' => $this->aCodeJsFiles]); |
| 315 | 313 | } |
| 316 | - if(count($this->aCodeJsAfter) > 0) |
|
| 314 | + if (count($this->aCodeJsAfter) > 0) |
|
| 317 | 315 | { |
| 318 | 316 | $sScript = implode("\n\n", $this->aCodeJsAfter); |
| 319 | 317 | $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
@@ -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 string |
| 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,40 +107,40 @@ 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(function($sClassName) { |
|
| 137 | - return $this->getCodeGenerator($sClassName)->getHash(); |
|
| 138 | - }, $this->aCodeGenerators); |
|
| 139 | - $aHashes[] = $this->sVersion; |
|
| 140 | - return md5(implode('', $aHashes)); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 134 | +public function getHash(): string |
|
| 135 | +{ |
|
| 136 | +$aHashes = array_map(function($sClassName) { |
|
| 137 | +return $this->getCodeGenerator($sClassName)->getHash(); |
|
| 138 | +}, $this->aCodeGenerators); |
|
| 139 | +$aHashes[] = $this->sVersion; |
|
| 140 | +return md5(implode('', $aHashes)); |
|
| 141 | +} |
|
| 142 | + |
|
| 143 | +/** |
|
| 144 | 144 | * Render a template in the 'plugins' subdir |
| 145 | 145 | * |
| 146 | 146 | * @param string $sTemplate The template filename |
@@ -148,180 +148,180 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @return string |
| 150 | 150 | */ |
| 151 | - private function render(string $sTemplate, array $aVars = []): string |
|
| 152 | - { |
|
| 153 | - $aVars['sJsOptions'] = $this->sJsOptions; |
|
| 154 | - return $this->xTemplateEngine->render("jaxon::plugins/$sTemplate", $aVars); |
|
| 155 | - } |
|
| 151 | +private function render(string $sTemplate, array $aVars = []): string |
|
| 152 | +{ |
|
| 153 | +$aVars['sJsOptions'] = $this->sJsOptions; |
|
| 154 | +return $this->xTemplateEngine->render("jaxon::plugins/$sTemplate", $aVars); |
|
| 155 | +} |
|
| 156 | 156 | |
| 157 | - /** |
|
| 157 | +/** |
|
| 158 | 158 | * Generate the Jaxon CSS and js codes for a given plugin |
| 159 | 159 | * |
| 160 | 160 | * @param CodeGeneratorInterface $xGenerator |
| 161 | 161 | * |
| 162 | 162 | * @return void |
| 163 | 163 | */ |
| 164 | - private function generatePluginCodes(CodeGeneratorInterface $xGenerator): void |
|
| 165 | - { |
|
| 166 | - if(!is_subclass_of($xGenerator, AbstractPlugin::class) || |
|
| 167 | - $this->xAssetManager->shallIncludeAssets($xGenerator)) |
|
| 168 | - { |
|
| 169 | - // HTML tags for CSS |
|
| 170 | - if(($sCss = trim($xGenerator->getCss(), " \n")) !== '') |
|
| 171 | - { |
|
| 172 | - $this->aCss[] = $sCss; |
|
| 173 | - } |
|
| 174 | - // HTML tags for js |
|
| 175 | - if(($sJs = trim($xGenerator->getJs(), " \n")) !== '') |
|
| 176 | - { |
|
| 177 | - $this->aJs[] = $sJs; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // Additional js codes |
|
| 182 | - if(($xJsCode = $xGenerator->getJsCode()) !== null) |
|
| 183 | - { |
|
| 184 | - if(($sJs = trim($xJsCode->sJs, " \n")) !== '') |
|
| 185 | - { |
|
| 186 | - $this->aCodeJs[] = $sJs; |
|
| 187 | - } |
|
| 188 | - if(($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '') |
|
| 189 | - { |
|
| 190 | - $this->aCodeJsBefore[] = $sJsBefore; |
|
| 191 | - } |
|
| 192 | - if(($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '') |
|
| 193 | - { |
|
| 194 | - $this->aCodeJsAfter[] = $sJsAfter; |
|
| 195 | - } |
|
| 196 | - $this->aCodeJsFiles = array_merge($this->aCodeJsFiles, $xJsCode->aFiles); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 164 | +private function generatePluginCodes(CodeGeneratorInterface $xGenerator): void |
|
| 165 | +{ |
|
| 166 | +if(!is_subclass_of($xGenerator, AbstractPlugin::class) || |
|
| 167 | +$this->xAssetManager->shallIncludeAssets($xGenerator)) |
|
| 168 | +{ |
|
| 169 | +// HTML tags for CSS |
|
| 170 | +if(($sCss = trim($xGenerator->getCss(), " \n")) !== '') |
|
| 171 | +{ |
|
| 172 | + $this->aCss[] = $sCss; |
|
| 173 | +} |
|
| 174 | +// HTML tags for js |
|
| 175 | +if(($sJs = trim($xGenerator->getJs(), " \n")) !== '') |
|
| 176 | +{ |
|
| 177 | + $this->aJs[] = $sJs; |
|
| 178 | +} |
|
| 179 | +} |
|
| 180 | + |
|
| 181 | +// Additional js codes |
|
| 182 | +if(($xJsCode = $xGenerator->getJsCode()) !== null) |
|
| 183 | +{ |
|
| 184 | +if(($sJs = trim($xJsCode->sJs, " \n")) !== '') |
|
| 185 | +{ |
|
| 186 | + $this->aCodeJs[] = $sJs; |
|
| 187 | +} |
|
| 188 | +if(($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '') |
|
| 189 | +{ |
|
| 190 | + $this->aCodeJsBefore[] = $sJsBefore; |
|
| 191 | +} |
|
| 192 | +if(($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '') |
|
| 193 | +{ |
|
| 194 | + $this->aCodeJsAfter[] = $sJsAfter; |
|
| 195 | +} |
|
| 196 | +$this->aCodeJsFiles = array_merge($this->aCodeJsFiles, $xJsCode->aFiles); |
|
| 197 | +} |
|
| 198 | +} |
|
| 199 | + |
|
| 200 | +/** |
|
| 201 | 201 | * Generate the Jaxon CSS ans js codes |
| 202 | 202 | * |
| 203 | 203 | * @return void |
| 204 | 204 | * @throws UriException |
| 205 | 205 | */ |
| 206 | - private function generateCodes(): void |
|
| 207 | - { |
|
| 208 | - if($this->bGenerated) |
|
| 209 | - { |
|
| 210 | - return; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $this->xAssetManager = $this->di->getAssetManager(); |
|
| 214 | - $this->sJsOptions = $this->xAssetManager->getJsOptions(); |
|
| 215 | - |
|
| 216 | - // Sort the code generators by ascending priority |
|
| 217 | - ksort($this->aCodeGenerators); |
|
| 218 | - |
|
| 219 | - foreach($this->aCodeGenerators as $sClassName) |
|
| 220 | - { |
|
| 221 | - $this->generatePluginCodes($this->getCodeGenerator($sClassName)); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - // Load the Jaxon lib js files, after the other libs js files. |
|
| 225 | - $this->aJs[] = trim($this->render('includes.js', [ |
|
| 226 | - 'aUrls' => $this->xAssetManager->getJsLibFiles(), |
|
| 227 | - ])); |
|
| 228 | - |
|
| 229 | - // The codes are already generated. |
|
| 230 | - $this->bGenerated = true; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 206 | +private function generateCodes(): void |
|
| 207 | +{ |
|
| 208 | +if($this->bGenerated) |
|
| 209 | +{ |
|
| 210 | +return; |
|
| 211 | +} |
|
| 212 | + |
|
| 213 | +$this->xAssetManager = $this->di->getAssetManager(); |
|
| 214 | +$this->sJsOptions = $this->xAssetManager->getJsOptions(); |
|
| 215 | + |
|
| 216 | +// Sort the code generators by ascending priority |
|
| 217 | +ksort($this->aCodeGenerators); |
|
| 218 | + |
|
| 219 | +foreach($this->aCodeGenerators as $sClassName) |
|
| 220 | +{ |
|
| 221 | +$this->generatePluginCodes($this->getCodeGenerator($sClassName)); |
|
| 222 | +} |
|
| 223 | + |
|
| 224 | +// Load the Jaxon lib js files, after the other libs js files. |
|
| 225 | +$this->aJs[] = trim($this->render('includes.js', [ |
|
| 226 | +'aUrls' => $this->xAssetManager->getJsLibFiles(), |
|
| 227 | +])); |
|
| 228 | + |
|
| 229 | +// The codes are already generated. |
|
| 230 | +$this->bGenerated = true; |
|
| 231 | +} |
|
| 232 | + |
|
| 233 | +/** |
|
| 234 | 234 | * Get the HTML tags to include Jaxon CSS code and files into the page |
| 235 | 235 | * |
| 236 | 236 | * @return string |
| 237 | 237 | * @throws UriException |
| 238 | 238 | */ |
| 239 | - public function getCss(): string |
|
| 240 | - { |
|
| 241 | - $this->generateCodes(); |
|
| 242 | - return implode("\n\n", $this->aCss); |
|
| 243 | - } |
|
| 239 | +public function getCss(): string |
|
| 240 | +{ |
|
| 241 | +$this->generateCodes(); |
|
| 242 | +return implode("\n\n", $this->aCss); |
|
| 243 | +} |
|
| 244 | 244 | |
| 245 | - /** |
|
| 245 | +/** |
|
| 246 | 246 | * Get the HTML tags to include Jaxon javascript files into the page |
| 247 | 247 | * |
| 248 | 248 | * @return string |
| 249 | 249 | * @throws UriException |
| 250 | 250 | */ |
| 251 | - public function getJs(): string |
|
| 252 | - { |
|
| 253 | - $this->generateCodes(); |
|
| 254 | - return implode("\n\n", $this->aJs); |
|
| 255 | - } |
|
| 251 | +public function getJs(): string |
|
| 252 | +{ |
|
| 253 | +$this->generateCodes(); |
|
| 254 | +return implode("\n\n", $this->aJs); |
|
| 255 | +} |
|
| 256 | 256 | |
| 257 | - /** |
|
| 257 | +/** |
|
| 258 | 258 | * Get the Javascript code |
| 259 | 259 | * |
| 260 | 260 | * @return string |
| 261 | 261 | */ |
| 262 | - public function getJsScript(): string |
|
| 263 | - { |
|
| 264 | - foreach($this->aCodeGenerators as $sClassName) |
|
| 265 | - { |
|
| 266 | - $xGenerator = $this->getCodeGenerator($sClassName); |
|
| 267 | - // Javascript code |
|
| 268 | - if(($sJsScript = trim($xGenerator->getScript(), " \n")) !== '') |
|
| 269 | - { |
|
| 270 | - $aJsScript[] = $sJsScript; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - return implode("\n\n", $aJsScript); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 262 | +public function getJsScript(): string |
|
| 263 | +{ |
|
| 264 | +foreach($this->aCodeGenerators as $sClassName) |
|
| 265 | +{ |
|
| 266 | +$xGenerator = $this->getCodeGenerator($sClassName); |
|
| 267 | +// Javascript code |
|
| 268 | +if(($sJsScript = trim($xGenerator->getScript(), " \n")) !== '') |
|
| 269 | +{ |
|
| 270 | + $aJsScript[] = $sJsScript; |
|
| 271 | +} |
|
| 272 | +} |
|
| 273 | +return implode("\n\n", $aJsScript); |
|
| 274 | +} |
|
| 275 | + |
|
| 276 | +/** |
|
| 277 | 277 | * @param bool $bIncludeJs Also get the JS files |
| 278 | 278 | * @param bool $bIncludeCss Also get the CSS files |
| 279 | 279 | * |
| 280 | 280 | * @return array<string> |
| 281 | 281 | */ |
| 282 | - private function renderCodes(bool $bIncludeJs, bool $bIncludeCss): array |
|
| 283 | - { |
|
| 284 | - $aCodes = []; |
|
| 285 | - if($bIncludeCss) |
|
| 286 | - { |
|
| 287 | - $aCodes[] = $this->getCss(); |
|
| 288 | - } |
|
| 289 | - if($bIncludeJs) |
|
| 290 | - { |
|
| 291 | - $aCodes[] = $this->getJs(); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - $sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' : |
|
| 295 | - $this->xAssetManager->createJsFiles($this); |
|
| 296 | - // Wrap the js code into the corresponding HTML tag. |
|
| 297 | - $aCodes[] = $sUrl !== '' ? |
|
| 298 | - $this->render('include.js', ['sUrl' => $sUrl]) : |
|
| 299 | - $this->render('wrapper.js', ['sScript' => $this->getJsScript()]); |
|
| 300 | - |
|
| 301 | - // Wrap the js codes into HTML tags. |
|
| 302 | - if(count($this->aCodeJsBefore) > 0) |
|
| 303 | - { |
|
| 304 | - $sScript = implode("\n\n", $this->aCodeJsBefore); |
|
| 305 | - $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
|
| 306 | - } |
|
| 307 | - if(count($this->aCodeJs) > 0) |
|
| 308 | - { |
|
| 309 | - $sScript = implode("\n\n", $this->aCodeJs); |
|
| 310 | - $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
|
| 311 | - } |
|
| 312 | - if(count($this->aCodeJsFiles) > 0) |
|
| 313 | - { |
|
| 314 | - $aCodes[] = $this->render('includes.js', ['aUrls' => $this->aCodeJsFiles]); |
|
| 315 | - } |
|
| 316 | - if(count($this->aCodeJsAfter) > 0) |
|
| 317 | - { |
|
| 318 | - $sScript = implode("\n\n", $this->aCodeJsAfter); |
|
| 319 | - $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
|
| 320 | - } |
|
| 321 | - return $aCodes; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 282 | +private function renderCodes(bool $bIncludeJs, bool $bIncludeCss): array |
|
| 283 | +{ |
|
| 284 | +$aCodes = []; |
|
| 285 | +if($bIncludeCss) |
|
| 286 | +{ |
|
| 287 | +$aCodes[] = $this->getCss(); |
|
| 288 | +} |
|
| 289 | +if($bIncludeJs) |
|
| 290 | +{ |
|
| 291 | +$aCodes[] = $this->getJs(); |
|
| 292 | +} |
|
| 293 | + |
|
| 294 | +$sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' : |
|
| 295 | +$this->xAssetManager->createJsFiles($this); |
|
| 296 | +// Wrap the js code into the corresponding HTML tag. |
|
| 297 | +$aCodes[] = $sUrl !== '' ? |
|
| 298 | +$this->render('include.js', ['sUrl' => $sUrl]) : |
|
| 299 | +$this->render('wrapper.js', ['sScript' => $this->getJsScript()]); |
|
| 300 | + |
|
| 301 | +// Wrap the js codes into HTML tags. |
|
| 302 | +if(count($this->aCodeJsBefore) > 0) |
|
| 303 | +{ |
|
| 304 | +$sScript = implode("\n\n", $this->aCodeJsBefore); |
|
| 305 | +$aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
|
| 306 | +} |
|
| 307 | +if(count($this->aCodeJs) > 0) |
|
| 308 | +{ |
|
| 309 | +$sScript = implode("\n\n", $this->aCodeJs); |
|
| 310 | +$aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
|
| 311 | +} |
|
| 312 | +if(count($this->aCodeJsFiles) > 0) |
|
| 313 | +{ |
|
| 314 | +$aCodes[] = $this->render('includes.js', ['aUrls' => $this->aCodeJsFiles]); |
|
| 315 | +} |
|
| 316 | +if(count($this->aCodeJsAfter) > 0) |
|
| 317 | +{ |
|
| 318 | +$sScript = implode("\n\n", $this->aCodeJsAfter); |
|
| 319 | +$aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
|
| 320 | +} |
|
| 321 | +return $aCodes; |
|
| 322 | +} |
|
| 323 | + |
|
| 324 | +/** |
|
| 325 | 325 | * Get the javascript code to be sent to the browser |
| 326 | 326 | * |
| 327 | 327 | * @param bool $bIncludeJs Also get the JS files |
@@ -330,10 +330,10 @@ discard block |
||
| 330 | 330 | * @return string |
| 331 | 331 | * @throws UriException |
| 332 | 332 | */ |
| 333 | - public function getScript(bool $bIncludeJs, bool $bIncludeCss): string |
|
| 334 | - { |
|
| 335 | - $this->generateCodes(); |
|
| 336 | - $aCodes = $this->renderCodes($bIncludeJs, $bIncludeCss); |
|
| 337 | - return implode("\n\n", $aCodes); |
|
| 338 | - } |
|
| 333 | +public function getScript(bool $bIncludeJs, bool $bIncludeCss): string |
|
| 334 | +{ |
|
| 335 | +$this->generateCodes(); |
|
| 336 | +$aCodes = $this->renderCodes($bIncludeJs, $bIncludeCss); |
|
| 337 | +return implode("\n\n", $aCodes); |
|
| 338 | +} |
|
| 339 | 339 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | public function shallIncludeAssets(AbstractPlugin $xPlugin): bool |
| 74 | 74 | { |
| 75 | 75 | $sPluginOptionName = 'assets.include.' . $xPlugin->getName(); |
| 76 | - if($this->hasLibOption($sPluginOptionName)) |
|
| 76 | + if ($this->hasLibOption($sPluginOptionName)) |
|
| 77 | 77 | { |
| 78 | 78 | return $this->getLibOption($sPluginOptionName); |
| 79 | 79 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $this->getLibOption('js.lib.jq', "$sJsLibUri/libs/chibi/chibi$sJsExtension"), |
| 98 | 98 | "$sJsLibUri/jaxon.core$sJsExtension", |
| 99 | 99 | ]; |
| 100 | - if($this->getLibOption('core.debug.on')) |
|
| 100 | + if ($this->getLibOption('core.debug.on')) |
|
| 101 | 101 | { |
| 102 | 102 | $sLanguage = $this->getLibOption('core.language'); |
| 103 | 103 | $aJsFiles[] = "$sJsLibUri/jaxon.debug$sJsExtension"; |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | // Check config options |
| 118 | 118 | // - The js.app.export option must be set to true |
| 119 | 119 | // - The js.app.uri and js.app.dir options must be set to non null values |
| 120 | - if(!$this->getLibOption('js.app.export', false) || |
|
| 120 | + if (!$this->getLibOption('js.app.export', false) || |
|
| 121 | 121 | !$this->getLibOption('js.app.uri') || !$this->getLibOption('js.app.dir')) |
| 122 | 122 | { |
| 123 | 123 | return false; |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | $sJsFileName = $this->getLibOption('js.app.file') ?: $xCodeGenerator->getHash(); |
| 139 | 139 | $sJsDirectory = rtrim($this->getLibOption('js.app.dir'), '\/') . DIRECTORY_SEPARATOR; |
| 140 | 140 | // - The js.app.dir must be writable |
| 141 | - if(!$sJsFileName || !is_dir($sJsDirectory) || !is_writable($sJsDirectory)) |
|
| 141 | + if (!$sJsFileName || !is_dir($sJsDirectory) || !is_writable($sJsDirectory)) |
|
| 142 | 142 | { |
| 143 | 143 | return ''; |
| 144 | 144 | } |
@@ -147,16 +147,16 @@ discard block |
||
| 147 | 147 | $sJsMinFilePath = $sJsDirectory . $sJsFileName . '.min.js'; |
| 148 | 148 | $sJsFileUri = rtrim($this->getLibOption('js.app.uri'), '/') . "/$sJsFileName"; |
| 149 | 149 | |
| 150 | - if(!is_file($sJsFilePath) && |
|
| 150 | + if (!is_file($sJsFilePath) && |
|
| 151 | 151 | !@file_put_contents($sJsFilePath, $xCodeGenerator->getJsScript())) |
| 152 | 152 | { |
| 153 | 153 | return ''; |
| 154 | 154 | } |
| 155 | - if(!$this->getLibOption('js.app.minify', false)) |
|
| 155 | + if (!$this->getLibOption('js.app.minify', false)) |
|
| 156 | 156 | { |
| 157 | 157 | return $sJsFileUri . '.js'; |
| 158 | 158 | } |
| 159 | - if(!is_file($sJsMinFilePath) && |
|
| 159 | + if (!is_file($sJsMinFilePath) && |
|
| 160 | 160 | !$this->xMinifier->minify($sJsFilePath, $sJsMinFilePath)) |
| 161 | 161 | { |
| 162 | 162 | // If the file cannot be minified, return the plain js file. |
@@ -26,142 +26,142 @@ |
||
| 26 | 26 | |
| 27 | 27 | class AssetManager |
| 28 | 28 | { |
| 29 | - use ConfigTrait; |
|
| 29 | +use ConfigTrait; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * Default library URL |
| 33 | 33 | * |
| 34 | 34 | * @var string |
| 35 | 35 | */ |
| 36 | - const JS_LIB_URL = 'https://cdn.jsdelivr.net/gh/jaxon-php/[email protected]/dist'; |
|
| 36 | +const JS_LIB_URL = 'https://cdn.jsdelivr.net/gh/jaxon-php/[email protected]/dist'; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * The constructor |
| 40 | 40 | * |
| 41 | 41 | * @param ConfigManager $xConfigManager |
| 42 | 42 | * @param MinifierInterface $xMinifier |
| 43 | 43 | */ |
| 44 | - public function __construct(private ConfigManager $xConfigManager, |
|
| 45 | - private MinifierInterface $xMinifier) |
|
| 46 | - {} |
|
| 44 | +public function __construct(private ConfigManager $xConfigManager, |
|
| 45 | +private MinifierInterface $xMinifier) |
|
| 46 | +{} |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * @return ConfigManager |
| 50 | 50 | */ |
| 51 | - protected function config(): ConfigManager |
|
| 52 | - { |
|
| 53 | - return $this->xConfigManager; |
|
| 54 | - } |
|
| 51 | +protected function config(): ConfigManager |
|
| 52 | +{ |
|
| 53 | +return $this->xConfigManager; |
|
| 54 | +} |
|
| 55 | 55 | |
| 56 | - /** |
|
| 56 | +/** |
|
| 57 | 57 | * Get app js options |
| 58 | 58 | * |
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | - public function getJsOptions(): string |
|
| 62 | - { |
|
| 63 | - return $this->getLibOption('js.app.options', ''); |
|
| 64 | - } |
|
| 61 | +public function getJsOptions(): string |
|
| 62 | +{ |
|
| 63 | +return $this->getLibOption('js.app.options', ''); |
|
| 64 | +} |
|
| 65 | 65 | |
| 66 | - /** |
|
| 66 | +/** |
|
| 67 | 67 | * Check if the assets of this plugin shall be included in Jaxon generated code. |
| 68 | 68 | * |
| 69 | 69 | * @param AbstractPlugin $xPlugin |
| 70 | 70 | * |
| 71 | 71 | * @return bool |
| 72 | 72 | */ |
| 73 | - public function shallIncludeAssets(AbstractPlugin $xPlugin): bool |
|
| 74 | - { |
|
| 75 | - $sPluginOptionName = 'assets.include.' . $xPlugin->getName(); |
|
| 76 | - if($this->hasLibOption($sPluginOptionName)) |
|
| 77 | - { |
|
| 78 | - return $this->getLibOption($sPluginOptionName); |
|
| 79 | - } |
|
| 80 | - return $this->getLibOption('assets.include.all', true); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 73 | +public function shallIncludeAssets(AbstractPlugin $xPlugin): bool |
|
| 74 | +{ |
|
| 75 | +$sPluginOptionName = 'assets.include.' . $xPlugin->getName(); |
|
| 76 | +if($this->hasLibOption($sPluginOptionName)) |
|
| 77 | +{ |
|
| 78 | +return $this->getLibOption($sPluginOptionName); |
|
| 79 | +} |
|
| 80 | +return $this->getLibOption('assets.include.all', true); |
|
| 81 | +} |
|
| 82 | + |
|
| 83 | +/** |
|
| 84 | 84 | * Get the HTML tags to include Jaxon javascript files into the page |
| 85 | 85 | * |
| 86 | 86 | * @return array |
| 87 | 87 | */ |
| 88 | - public function getJsLibFiles(): array |
|
| 89 | - { |
|
| 90 | - $sJsExtension = $this->getLibOption('js.app.minify') ? '.min.js' : '.js'; |
|
| 91 | - // The URI for the javascript library files |
|
| 92 | - $sJsLibUri = $this->getLibOption('js.lib.uri', self::JS_LIB_URL); |
|
| 93 | - $sJsLibUri = rtrim($sJsLibUri, '/'); |
|
| 94 | - |
|
| 95 | - // Add component files to the javascript file array; |
|
| 96 | - $aJsFiles = [ |
|
| 97 | - $this->getLibOption('js.lib.jq', "$sJsLibUri/libs/chibi/chibi$sJsExtension"), |
|
| 98 | - "$sJsLibUri/jaxon.core$sJsExtension", |
|
| 99 | - ]; |
|
| 100 | - if($this->getLibOption('core.debug.on')) |
|
| 101 | - { |
|
| 102 | - $sLanguage = $this->getLibOption('core.language'); |
|
| 103 | - $aJsFiles[] = "$sJsLibUri/jaxon.debug$sJsExtension"; |
|
| 104 | - $aJsFiles[] = "$sJsLibUri/lang/jaxon.$sLanguage$sJsExtension"; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return $aJsFiles; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 88 | +public function getJsLibFiles(): array |
|
| 89 | +{ |
|
| 90 | +$sJsExtension = $this->getLibOption('js.app.minify') ? '.min.js' : '.js'; |
|
| 91 | +// The URI for the javascript library files |
|
| 92 | +$sJsLibUri = $this->getLibOption('js.lib.uri', self::JS_LIB_URL); |
|
| 93 | +$sJsLibUri = rtrim($sJsLibUri, '/'); |
|
| 94 | + |
|
| 95 | +// Add component files to the javascript file array; |
|
| 96 | +$aJsFiles = [ |
|
| 97 | +$this->getLibOption('js.lib.jq', "$sJsLibUri/libs/chibi/chibi$sJsExtension"), |
|
| 98 | +"$sJsLibUri/jaxon.core$sJsExtension", |
|
| 99 | +]; |
|
| 100 | +if($this->getLibOption('core.debug.on')) |
|
| 101 | +{ |
|
| 102 | +$sLanguage = $this->getLibOption('core.language'); |
|
| 103 | +$aJsFiles[] = "$sJsLibUri/jaxon.debug$sJsExtension"; |
|
| 104 | +$aJsFiles[] = "$sJsLibUri/lang/jaxon.$sLanguage$sJsExtension"; |
|
| 105 | +} |
|
| 106 | + |
|
| 107 | +return $aJsFiles; |
|
| 108 | +} |
|
| 109 | + |
|
| 110 | +/** |
|
| 111 | 111 | * Get the javascript file name |
| 112 | 112 | * |
| 113 | 113 | * @return bool |
| 114 | 114 | */ |
| 115 | - public function shallCreateJsFiles(): bool |
|
| 116 | - { |
|
| 117 | - // Check config options |
|
| 118 | - // - The js.app.export option must be set to true |
|
| 119 | - // - The js.app.uri and js.app.dir options must be set to non null values |
|
| 120 | - if(!$this->getLibOption('js.app.export', false) || |
|
| 121 | - !$this->getLibOption('js.app.uri') || !$this->getLibOption('js.app.dir')) |
|
| 122 | - { |
|
| 123 | - return false; |
|
| 124 | - } |
|
| 125 | - return true; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 115 | +public function shallCreateJsFiles(): bool |
|
| 116 | +{ |
|
| 117 | +// Check config options |
|
| 118 | +// - The js.app.export option must be set to true |
|
| 119 | +// - The js.app.uri and js.app.dir options must be set to non null values |
|
| 120 | +if(!$this->getLibOption('js.app.export', false) || |
|
| 121 | +!$this->getLibOption('js.app.uri') || !$this->getLibOption('js.app.dir')) |
|
| 122 | +{ |
|
| 123 | +return false; |
|
| 124 | +} |
|
| 125 | +return true; |
|
| 126 | +} |
|
| 127 | + |
|
| 128 | +/** |
|
| 129 | 129 | * Write javascript files and return the corresponding URI |
| 130 | 130 | * |
| 131 | 131 | * @param CodeGenerator $codeGenerator |
| 132 | 132 | * |
| 133 | 133 | * @return string |
| 134 | 134 | */ |
| 135 | - public function createJsFiles(CodeGenerator $xCodeGenerator): string |
|
| 136 | - { |
|
| 137 | - // Check dir access |
|
| 138 | - $sJsFileName = $this->getLibOption('js.app.file') ?: $xCodeGenerator->getHash(); |
|
| 139 | - $sJsDirectory = rtrim($this->getLibOption('js.app.dir'), '\/') . DIRECTORY_SEPARATOR; |
|
| 140 | - // - The js.app.dir must be writable |
|
| 141 | - if(!$sJsFileName || !is_dir($sJsDirectory) || !is_writable($sJsDirectory)) |
|
| 142 | - { |
|
| 143 | - return ''; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $sJsFilePath = $sJsDirectory . $sJsFileName . '.js'; |
|
| 147 | - $sJsMinFilePath = $sJsDirectory . $sJsFileName . '.min.js'; |
|
| 148 | - $sJsFileUri = rtrim($this->getLibOption('js.app.uri'), '/') . "/$sJsFileName"; |
|
| 149 | - |
|
| 150 | - if(!is_file($sJsFilePath) && |
|
| 151 | - !@file_put_contents($sJsFilePath, $xCodeGenerator->getJsScript())) |
|
| 152 | - { |
|
| 153 | - return ''; |
|
| 154 | - } |
|
| 155 | - if(!$this->getLibOption('js.app.minify', false)) |
|
| 156 | - { |
|
| 157 | - return $sJsFileUri . '.js'; |
|
| 158 | - } |
|
| 159 | - if(!is_file($sJsMinFilePath) && |
|
| 160 | - !$this->xMinifier->minify($sJsFilePath, $sJsMinFilePath)) |
|
| 161 | - { |
|
| 162 | - // If the file cannot be minified, return the plain js file. |
|
| 163 | - return $sJsFileUri . '.js'; |
|
| 164 | - } |
|
| 165 | - return $sJsFileUri . '.min.js'; |
|
| 166 | - } |
|
| 135 | +public function createJsFiles(CodeGenerator $xCodeGenerator): string |
|
| 136 | +{ |
|
| 137 | +// Check dir access |
|
| 138 | +$sJsFileName = $this->getLibOption('js.app.file') ?: $xCodeGenerator->getHash(); |
|
| 139 | +$sJsDirectory = rtrim($this->getLibOption('js.app.dir'), '\/') . DIRECTORY_SEPARATOR; |
|
| 140 | +// - The js.app.dir must be writable |
|
| 141 | +if(!$sJsFileName || !is_dir($sJsDirectory) || !is_writable($sJsDirectory)) |
|
| 142 | +{ |
|
| 143 | +return ''; |
|
| 144 | +} |
|
| 145 | + |
|
| 146 | +$sJsFilePath = $sJsDirectory . $sJsFileName . '.js'; |
|
| 147 | +$sJsMinFilePath = $sJsDirectory . $sJsFileName . '.min.js'; |
|
| 148 | +$sJsFileUri = rtrim($this->getLibOption('js.app.uri'), '/') . "/$sJsFileName"; |
|
| 149 | + |
|
| 150 | +if(!is_file($sJsFilePath) && |
|
| 151 | +!@file_put_contents($sJsFilePath, $xCodeGenerator->getJsScript())) |
|
| 152 | +{ |
|
| 153 | +return ''; |
|
| 154 | +} |
|
| 155 | +if(!$this->getLibOption('js.app.minify', false)) |
|
| 156 | +{ |
|
| 157 | +return $sJsFileUri . '.js'; |
|
| 158 | +} |
|
| 159 | +if(!is_file($sJsMinFilePath) && |
|
| 160 | +!$this->xMinifier->minify($sJsFilePath, $sJsMinFilePath)) |
|
| 161 | +{ |
|
| 162 | +// If the file cannot be minified, return the plain js file. |
|
| 163 | +return $sJsFileUri . '.js'; |
|
| 164 | +} |
|
| 165 | +return $sJsFileUri . '.min.js'; |
|
| 166 | +} |
|
| 167 | 167 | } |
@@ -226,8 +226,7 @@ |
||
| 226 | 226 | if(is_array($xMethodToCall)) |
| 227 | 227 | { |
| 228 | 228 | $aHookMethods[$sCalledMethod] = array_merge($aHookMethods[$sCalledMethod], $xMethodToCall); |
| 229 | - } |
|
| 230 | - elseif(is_string($xMethodToCall)) |
|
| 229 | + } elseif(is_string($xMethodToCall)) |
|
| 231 | 230 | { |
| 232 | 231 | $aHookMethods[$sCalledMethod][] = $xMethodToCall; |
| 233 | 232 | } |
@@ -107,33 +107,33 @@ discard block |
||
| 107 | 107 | { |
| 108 | 108 | $this->bExcluded = ($xMetadata?->isExcluded() ?? false) || |
| 109 | 109 | (bool)($aOptions['excluded'] ?? false); |
| 110 | - if($this->bExcluded) |
|
| 110 | + if ($this->bExcluded) |
|
| 111 | 111 | { |
| 112 | 112 | return; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | $sSeparator = $aOptions['separator']; |
| 116 | - if($sSeparator === '_' || $sSeparator === '.') |
|
| 116 | + if ($sSeparator === '_' || $sSeparator === '.') |
|
| 117 | 117 | { |
| 118 | 118 | $this->sSeparator = $sSeparator; |
| 119 | 119 | } |
| 120 | 120 | $this->addProtectedMethods($aOptions['protected']); |
| 121 | 121 | |
| 122 | - foreach($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 122 | + foreach ($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 123 | 123 | { |
| 124 | 124 | // Names are in a comma-separated list. |
| 125 | 125 | $aFunctionNames = explode(',', $sNames); |
| 126 | - foreach($aFunctionNames as $sFunctionName) |
|
| 126 | + foreach ($aFunctionNames as $sFunctionName) |
|
| 127 | 127 | { |
| 128 | 128 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if($xMetadata !== null) |
|
| 132 | + if ($xMetadata !== null) |
|
| 133 | 133 | { |
| 134 | 134 | $this->aExportMethods = $xMetadata->getExportMethods(); |
| 135 | 135 | $this->addProtectedMethods($xMetadata->getProtectedMethods()); |
| 136 | - foreach($xMetadata->getProperties() as $sFunctionName => $aFunctionOptions) |
|
| 136 | + foreach ($xMetadata->getProperties() as $sFunctionName => $aFunctionOptions) |
|
| 137 | 137 | { |
| 138 | 138 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
| 139 | 139 | } |
@@ -150,8 +150,7 @@ discard block |
||
| 150 | 150 | private function addProtectedMethods(array|string $xMethods): void |
| 151 | 151 | { |
| 152 | 152 | $this->aProtectedMethods = array_merge($this->aProtectedMethods, |
| 153 | - !is_array($xMethods) ? [trim((string)$xMethods)] : |
|
| 154 | - array_map(fn($sMethod) => trim((string)$sMethod), $xMethods)); |
|
| 153 | + !is_array($xMethods) ? [trim((string)$xMethods)] : array_map(fn($sMethod) => trim((string)$sMethod), $xMethods)); |
|
| 155 | 154 | } |
| 156 | 155 | |
| 157 | 156 | /** |
@@ -161,7 +160,7 @@ discard block |
||
| 161 | 160 | */ |
| 162 | 161 | private function filterPublicMethods(array $aMethods): array |
| 163 | 162 | { |
| 164 | - if($this->bExcluded || in_array('*', $this->aProtectedMethods)) |
|
| 163 | + if ($this->bExcluded || in_array('*', $this->aProtectedMethods)) |
|
| 165 | 164 | { |
| 166 | 165 | return []; |
| 167 | 166 | } |
@@ -169,13 +168,13 @@ discard block |
||
| 169 | 168 | $aBaseMethods = $aMethods[1]; |
| 170 | 169 | $aMethods = $aMethods[0]; |
| 171 | 170 | |
| 172 | - if(isset($this->aExportMethods['only'])) |
|
| 171 | + if (isset($this->aExportMethods['only'])) |
|
| 173 | 172 | { |
| 174 | 173 | $aMethods = array_intersect($aMethods, $this->aExportMethods['only']); |
| 175 | 174 | } |
| 176 | 175 | $aMethods = array_diff($aMethods, $this->aProtectedMethods, |
| 177 | 176 | $this->aExportMethods['except'] ?? []); |
| 178 | - if(count($aBaseMethods) > 0 && isset($this->aExportMethods['base'])) |
|
| 177 | + if (count($aBaseMethods) > 0 && isset($this->aExportMethods['base'])) |
|
| 179 | 178 | { |
| 180 | 179 | $aBaseMethods = array_diff($aBaseMethods, $this->aExportMethods['base']); |
| 181 | 180 | } |
@@ -253,17 +252,17 @@ discard block |
||
| 253 | 252 | */ |
| 254 | 253 | private function setHookMethods(array &$aHookMethods, $xValue): void |
| 255 | 254 | { |
| 256 | - foreach($xValue as $sCalledMethod => $xMethodToCall) |
|
| 255 | + foreach ($xValue as $sCalledMethod => $xMethodToCall) |
|
| 257 | 256 | { |
| 258 | - if(!isset($aHookMethods[$sCalledMethod])) |
|
| 257 | + if (!isset($aHookMethods[$sCalledMethod])) |
|
| 259 | 258 | { |
| 260 | 259 | $aHookMethods[$sCalledMethod] = []; |
| 261 | 260 | } |
| 262 | - if(is_array($xMethodToCall)) |
|
| 261 | + if (is_array($xMethodToCall)) |
|
| 263 | 262 | { |
| 264 | 263 | $aHookMethods[$sCalledMethod] = array_merge($aHookMethods[$sCalledMethod], $xMethodToCall); |
| 265 | 264 | } |
| 266 | - elseif(is_string($xMethodToCall)) |
|
| 265 | + elseif (is_string($xMethodToCall)) |
|
| 267 | 266 | { |
| 268 | 267 | $aHookMethods[$sCalledMethod][] = $xMethodToCall; |
| 269 | 268 | } |
@@ -288,7 +287,7 @@ discard block |
||
| 288 | 287 | */ |
| 289 | 288 | private function addOption(string $sName, $xValue): void |
| 290 | 289 | { |
| 291 | - switch($sName) |
|
| 290 | + switch ($sName) |
|
| 292 | 291 | { |
| 293 | 292 | // Set the methods to call before processing the request |
| 294 | 293 | case '__before': |
@@ -316,11 +315,11 @@ discard block |
||
| 316 | 315 | */ |
| 317 | 316 | private function _addJsArrayOption(string $sFunctionName, string $sOptionName, $xOptionValue): void |
| 318 | 317 | { |
| 319 | - if(is_string($xOptionValue)) |
|
| 318 | + if (is_string($xOptionValue)) |
|
| 320 | 319 | { |
| 321 | 320 | $xOptionValue = [$xOptionValue]; |
| 322 | 321 | } |
| 323 | - if(!is_array($xOptionValue)) |
|
| 322 | + if (!is_array($xOptionValue)) |
|
| 324 | 323 | { |
| 325 | 324 | return; // Do not save. |
| 326 | 325 | } |
@@ -350,10 +349,10 @@ discard block |
||
| 350 | 349 | */ |
| 351 | 350 | private function addJsOption(string $sFunctionName, string $sOptionName, $xOptionValue): void |
| 352 | 351 | { |
| 353 | - switch($sOptionName) |
|
| 352 | + switch ($sOptionName) |
|
| 354 | 353 | { |
| 355 | 354 | case 'excluded': |
| 356 | - if((bool)$xOptionValue) |
|
| 355 | + if ((bool)$xOptionValue) |
|
| 357 | 356 | { |
| 358 | 357 | $this->addProtectedMethods($sFunctionName); |
| 359 | 358 | } |
@@ -377,12 +376,11 @@ discard block |
||
| 377 | 376 | */ |
| 378 | 377 | private function addFunctionOptions(string $sFunctionName, array $aFunctionOptions): void |
| 379 | 378 | { |
| 380 | - foreach($aFunctionOptions as $sOptionName => $xOptionValue) |
|
| 379 | + foreach ($aFunctionOptions as $sOptionName => $xOptionValue) |
|
| 381 | 380 | { |
| 382 | 381 | substr($sOptionName, 0, 2) === '__' ? |
| 383 | 382 | // Options for PHP classes. They start with "__". |
| 384 | - $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : |
|
| 385 | - // Options for javascript code. |
|
| 383 | + $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : // Options for javascript code. |
|
| 386 | 384 | $this->addJsOption($sFunctionName, $sOptionName, $xOptionValue); |
| 387 | 385 | } |
| 388 | 386 | } |
@@ -398,16 +396,15 @@ discard block |
||
| 398 | 396 | $aOptions = array_merge($this->aJsOptions['*'] ?? []); // Clone the array |
| 399 | 397 | // Then add the method options. |
| 400 | 398 | $aMethodOptions = $this->aJsOptions[$sMethodName] ?? []; |
| 401 | - foreach($aMethodOptions as $sOptionName => $xOptionValue) |
|
| 399 | + foreach ($aMethodOptions as $sOptionName => $xOptionValue) |
|
| 402 | 400 | { |
| 403 | 401 | // For databags and callbacks, merge the values in a single array. |
| 404 | 402 | // For all the other options, keep the last value. |
| 405 | 403 | $aOptions[$sOptionName] = !in_array($sOptionName, ['bags', 'callback']) ? |
| 406 | - $xOptionValue : |
|
| 407 | - array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
| 404 | + $xOptionValue : array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
| 408 | 405 | } |
| 409 | 406 | // Since callbacks are js object names, they need a special formatting. |
| 410 | - if(isset($aOptions['callback'])) |
|
| 407 | + if (isset($aOptions['callback'])) |
|
| 411 | 408 | { |
| 412 | 409 | $aOptions['callback'] = str_replace('"', '', json_encode($aOptions['callback'])); |
| 413 | 410 | } |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | public function __construct(string $sDirectory) |
| 29 | 29 | { |
| 30 | 30 | $itFile = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($sDirectory)); |
| 31 | - foreach($itFile as $xFile) |
|
| 31 | + foreach ($itFile as $xFile) |
|
| 32 | 32 | { |
| 33 | 33 | $this->insert($xFile); |
| 34 | 34 | } |