Passed
Push — main ( 7f530d...7aae9b )
by Thierry
05:54
created
jaxon-core/src/Plugin/Manager/PackageManager.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -218,8 +218,7 @@
 block discarded – undo
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]);
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -62,25 +62,25 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Manager/PluginManager.php 1 patch
Spacing   +9 added lines, -10 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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));
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Response/Psr/PsrPlugin.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@
 block discarded – undo
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')
Please login to merge, or discard this patch.
Switch Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -23,56 +23,56 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Code/ConfigScriptGenerator.php 2 patches
Spacing   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,8 +52,7 @@
 block discarded – undo
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'),
Please login to merge, or discard this patch.
Switch Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -22,53 +22,53 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Code/CodeGenerator.php 2 patches
Spacing   +20 added lines, -22 removed lines patch added patch discarded remove patch
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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]);
Please login to merge, or discard this patch.
Switch Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -31,75 +31,75 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Code/AssetManager.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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.
Please login to merge, or discard this patch.
Switch Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -26,142 +26,142 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Request/CallableClass/SortedFileIterator.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Request/CallableClass/CallableDirPlugin.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     private function checkDirectory(string $sDirectory): string
69 69
     {
70 70
         $sDirectory = rtrim(trim($sDirectory), '/\\');
71
-        if(!is_dir($sDirectory))
71
+        if (!is_dir($sDirectory))
72 72
         {
73 73
             throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration'));
74 74
         }
@@ -81,11 +81,11 @@  discard block
 block discarded – undo
81 81
      */
82 82
     public function checkOptions(string $sCallable, $xOptions): array
83 83
     {
84
-        if(is_string($xOptions))
84
+        if (is_string($xOptions))
85 85
         {
86 86
             $xOptions = ['namespace' => $xOptions];
87 87
         }
88
-        if(!is_array($xOptions))
88
+        if (!is_array($xOptions))
89 89
         {
90 90
             throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration'));
91 91
         }
@@ -93,14 +93,14 @@  discard block
 block discarded – undo
93 93
         $xOptions['directory'] = $this->checkDirectory($sCallable);
94 94
         // Check the namespace
95 95
         $sNamespace = $xOptions['namespace'] ?? '';
96
-        if(!($xOptions['namespace'] = trim($sNamespace, ' \\')))
96
+        if (!($xOptions['namespace'] = trim($sNamespace, ' \\')))
97 97
         {
98 98
             $xOptions['namespace'] = '';
99 99
         }
100 100
 
101 101
         // Change the keys in $xOptions to have "\" as separator
102 102
         $_aOptions = [];
103
-        foreach($xOptions as $sName => $aOption)
103
+        foreach ($xOptions as $sName => $aOption)
104 104
         {
105 105
             $sName = trim(str_replace('.', '\\', $sName), ' \\');
106 106
             $_aOptions[$sName] = $aOption;
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
     public function register(string $sType, string $sCallable, array $aOptions): bool
115 115
     {
116 116
         // The $sCallable var is not used here because the checkOptions() method copied it into the $aOptions array.
117
-        if(($aOptions['namespace']))
117
+        if (($aOptions['namespace']))
118 118
         {
119 119
             $this->xRegistry->registerNamespace($aOptions['namespace'], $aOptions);
120 120
             return true;
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Request/CallableFunction/CallableFunction.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public function configure(string $sName, string $sValue): void
106 106
     {
107
-        switch($sName)
107
+        switch ($sName)
108 108
         {
109 109
         case 'class': // The user function is a method in the given class
110 110
             $this->xPhpFunction = [$sValue, $this->xPhpFunction];
@@ -128,12 +128,12 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function call(array $aArgs = []): void
130 130
     {
131
-        if($this->sInclude !== '')
131
+        if ($this->sInclude !== '')
132 132
         {
133 133
             require_once $this->sInclude;
134 134
         }
135 135
         // If the function is an alias for a class method, then instantiate the class
136
-        if(is_array($this->xPhpFunction) && is_string($this->xPhpFunction[0]))
136
+        if (is_array($this->xPhpFunction) && is_string($this->xPhpFunction[0]))
137 137
         {
138 138
             $sClassName = $this->xPhpFunction[0];
139 139
             $this->xPhpFunction[0] = $this->di->h($sClassName) ?
Please login to merge, or discard this patch.
Switch Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -28,29 +28,29 @@  discard block
 block discarded – undo
28 28
 
29 29
 class CallableFunction
30 30
 {
31
-    /**
31
+/**
32 32
      * A string or an array which defines the registered PHP function
33 33
      *
34 34
      * @var string|array
35 35
      */
36
-    private $xPhpFunction;
36
+private $xPhpFunction;
37 37
 
38
-    /**
38
+/**
39 39
      * The path and file name of the include file where the function is defined
40 40
      *
41 41
      * @var string
42 42
      */
43
-    private $sInclude = '';
43
+private $sInclude = '';
44 44
 
45
-    /**
45
+/**
46 46
      * An associative array containing call options that will be sent
47 47
      * to the browser with the client script.
48 48
      *
49 49
      * @var array
50 50
      */
51
-    private $aOptions = [];
51
+private $aOptions = [];
52 52
 
53
-    /**
53
+/**
54 54
      * The constructor
55 55
      *
56 56
      * @param Container $di
@@ -58,43 +58,43 @@  discard block
 block discarded – undo
58 58
      * @param string $sJsFunction
59 59
      * @param string $sPhpFunction
60 60
      */
61
-    public function __construct(private Container $di, private string $sFunction,
62
-        private string $sJsFunction, string $sPhpFunction)
63
-    {
64
-        $this->xPhpFunction = $sPhpFunction;
65
-    }
61
+public function __construct(private Container $di, private string $sFunction,
62
+private string $sJsFunction, string $sPhpFunction)
63
+{
64
+$this->xPhpFunction = $sPhpFunction;
65
+}
66 66
 
67
-    /**
67
+/**
68 68
      * Get the name of the function being referenced
69 69
      *
70 70
      * @return string
71 71
      */
72
-    public function getName(): string
73
-    {
74
-        return $this->sFunction;
75
-    }
72
+public function getName(): string
73
+{
74
+return $this->sFunction;
75
+}
76 76
 
77
-    /**
77
+/**
78 78
      * Get name of the corresponding javascript function
79 79
      *
80 80
      * @return string
81 81
      */
82
-    public function getJsName(): string
83
-    {
84
-        return $this->sJsFunction;
85
-    }
82
+public function getJsName(): string
83
+{
84
+return $this->sJsFunction;
85
+}
86 86
 
87
-    /**
87
+/**
88 88
      * Get the config options of the function being referenced
89 89
      *
90 90
      * @return array
91 91
      */
92
-    public function getOptions(): array
93
-    {
94
-        return $this->aOptions;
95
-    }
92
+public function getOptions(): array
93
+{
94
+return $this->aOptions;
95
+}
96 96
 
97
-    /**
97
+/**
98 98
      * Set call options for this instance
99 99
      *
100 100
      * @param string $sName    The name of the configuration option
@@ -102,20 +102,20 @@  discard block
 block discarded – undo
102 102
      *
103 103
      * @return void
104 104
      */
105
-    public function configure(string $sName, string $sValue): void
106
-    {
107
-        switch($sName)
108
-        {
109
-        case 'class': // The user function is a method in the given class
110
-            $this->xPhpFunction = [$sValue, $this->xPhpFunction];
111
-            break;
112
-        case 'include':
113
-            $this->sInclude = $sValue;
114
-            break;
115
-        default:
116
-            $this->aOptions[$sName] = $sValue;
117
-            break;
118
-        }
105
+public function configure(string $sName, string $sValue): void
106
+{
107
+switch($sName)
108
+{
109
+case 'class': // The user function is a method in the given class
110
+$this->xPhpFunction = [$sValue, $this->xPhpFunction];
111
+break;
112
+case 'include':
113
+$this->sInclude = $sValue;
114
+break;
115
+default:
116
+$this->aOptions[$sName] = $sValue;
117
+break;
118
+}
119 119
     }
120 120
 
121 121
     /**
Please login to merge, or discard this patch.