Passed
Push — main ( 2ea88b...5eae70 )
by Thierry
04:01
created
jaxon-storage/src/helpers.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
  */
12 12
 function storage(): StorageManager
13 13
 {
14
-    if(function_exists('jaxon'))
14
+    if (function_exists('jaxon'))
15 15
     {
16 16
         return jaxon()->di()->g(StorageManager::class);
17 17
     }
Please login to merge, or discard this patch.
jaxon-core/src/Di/Traits/UtilTrait.php 1 patch
Switch Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -17,88 +17,88 @@
 block discarded – undo
17 17
 
18 18
 trait UtilTrait
19 19
 {
20
-    /**
20
+/**
21 21
      * Register the values into the container
22 22
      *
23 23
      * @return void
24 24
      */
25
-    private function registerUtils(): void
26
-    {
27
-        // Translator
28
-        $this->set(Translator::class, function($di) {
29
-            $xTranslator = new Translator();
30
-            $sResourceDir = rtrim(trim($di->g('jaxon.core.dir.translation')), '/\\');
31
-            // Load the debug translations
32
-            $xTranslator->loadTranslations("$sResourceDir/en/errors.php", 'en');
33
-            $xTranslator->loadTranslations("$sResourceDir/fr/errors.php", 'fr');
34
-            $xTranslator->loadTranslations("$sResourceDir/es/errors.php", 'es');
35
-            // Load the config translations
36
-            $xTranslator->loadTranslations("$sResourceDir/en/config.php", 'en');
37
-            $xTranslator->loadTranslations("$sResourceDir/fr/config.php", 'fr');
38
-            $xTranslator->loadTranslations("$sResourceDir/es/config.php", 'es');
39
-            // Load the labels translations
40
-            $xTranslator->loadTranslations("$sResourceDir/en/labels.php", 'en');
41
-            $xTranslator->loadTranslations("$sResourceDir/fr/labels.php", 'fr');
42
-            $xTranslator->loadTranslations("$sResourceDir/es/labels.php", 'es');
25
+private function registerUtils(): void
26
+{
27
+// Translator
28
+$this->set(Translator::class, function($di) {
29
+$xTranslator = new Translator();
30
+$sResourceDir = rtrim(trim($di->g('jaxon.core.dir.translation')), '/\\');
31
+// Load the debug translations
32
+$xTranslator->loadTranslations("$sResourceDir/en/errors.php", 'en');
33
+$xTranslator->loadTranslations("$sResourceDir/fr/errors.php", 'fr');
34
+$xTranslator->loadTranslations("$sResourceDir/es/errors.php", 'es');
35
+// Load the config translations
36
+$xTranslator->loadTranslations("$sResourceDir/en/config.php", 'en');
37
+$xTranslator->loadTranslations("$sResourceDir/fr/config.php", 'fr');
38
+$xTranslator->loadTranslations("$sResourceDir/es/config.php", 'es');
39
+// Load the labels translations
40
+$xTranslator->loadTranslations("$sResourceDir/en/labels.php", 'en');
41
+$xTranslator->loadTranslations("$sResourceDir/fr/labels.php", 'fr');
42
+$xTranslator->loadTranslations("$sResourceDir/es/labels.php", 'es');
43 43
 
44
-            return $xTranslator;
45
-        });
46
-        // Define an alis for the translator with the base class name.
47
-        $this->alias(BaseTranslator::class, Translator::class);
44
+return $xTranslator;
45
+});
46
+// Define an alis for the translator with the base class name.
47
+$this->alias(BaseTranslator::class, Translator::class);
48 48
 
49
-        // Config reader
50
-        $this->set(ConfigReader::class, fn($di): ConfigReader =>
51
-            new ConfigReader($di->g(ConfigSetter::class)));
49
+// Config reader
50
+$this->set(ConfigReader::class, fn($di): ConfigReader =>
51
+new ConfigReader($di->g(ConfigSetter::class)));
52 52
 
53
-        // Config setter
54
-        $this->set(ConfigSetter::class, fn() => new ConfigSetter());
53
+// Config setter
54
+$this->set(ConfigSetter::class, fn() => new ConfigSetter());
55 55
 
56
-        // Template engine
57
-        $this->set(TemplateEngine::class, function($di) {
58
-            $xTemplateEngine = new TemplateEngine();
59
-            $sTemplateDir = rtrim(trim($di->g('jaxon.core.dir.template')), '/\\');
60
-            $sPaginationDir = $sTemplateDir . DIRECTORY_SEPARATOR . 'pagination';
61
-            $xTemplateEngine->addNamespace('jaxon', $sTemplateDir, '.php');
62
-            $xTemplateEngine->addNamespace('pagination', $sPaginationDir, '.php');
63
-            $xTemplateEngine->setDefaultNamespace('jaxon');
56
+// Template engine
57
+$this->set(TemplateEngine::class, function($di) {
58
+$xTemplateEngine = new TemplateEngine();
59
+$sTemplateDir = rtrim(trim($di->g('jaxon.core.dir.template')), '/\\');
60
+$sPaginationDir = $sTemplateDir . DIRECTORY_SEPARATOR . 'pagination';
61
+$xTemplateEngine->addNamespace('jaxon', $sTemplateDir, '.php');
62
+$xTemplateEngine->addNamespace('pagination', $sPaginationDir, '.php');
63
+$xTemplateEngine->setDefaultNamespace('jaxon');
64 64
 
65
-            return $xTemplateEngine;
66
-        });
65
+return $xTemplateEngine;
66
+});
67 67
 
68
-        // URI detector
69
-        $this->set(UriDetector::class, fn(): UriDetector => new UriDetector());
68
+// URI detector
69
+$this->set(UriDetector::class, fn(): UriDetector => new UriDetector());
70 70
 
71
-        // Temp cache for Jaxon components
72
-        $this->set(Stash::class, fn(): Stash => new Stash());
71
+// Temp cache for Jaxon components
72
+$this->set(Stash::class, fn(): Stash => new Stash());
73 73
 
74
-        // File storage
75
-        $this->set(StorageManager::class, function($di): StorageManager {
76
-            $xConfigGetter = function() use($di): Config {
77
-                $aConfigOptions = $di->config()->getAppOption('storage', []);
78
-                return $di->g(ConfigSetter::class)->newConfig($aConfigOptions);
79
-            };
74
+// File storage
75
+$this->set(StorageManager::class, function($di): StorageManager {
76
+$xConfigGetter = function() use($di): Config {
77
+    $aConfigOptions = $di->config()->getAppOption('storage', []);
78
+    return $di->g(ConfigSetter::class)->newConfig($aConfigOptions);
79
+};
80 80
 
81
-            return new StorageManager($xConfigGetter, $di->g(Translator::class));
82
-        });
83
-    }
81
+return new StorageManager($xConfigGetter, $di->g(Translator::class));
82
+});
83
+}
84 84
 
85
-    /**
85
+/**
86 86
      * Get the template engine
87 87
      *
88 88
      * @return TemplateEngine
89 89
      */
90
-    public function getTemplateEngine(): TemplateEngine
91
-    {
92
-        return $this->g(TemplateEngine::class);
93
-    }
90
+public function getTemplateEngine(): TemplateEngine
91
+{
92
+return $this->g(TemplateEngine::class);
93
+}
94 94
 
95
-    /**
95
+/**
96 96
      * Get the temp cache for Jaxon components
97 97
      *
98 98
      * @return Stash
99 99
      */
100
-    public function getStash(): Stash
101
-    {
102
-        return $this->g(Stash::class);
103
-    }
100
+public function getStash(): Stash
101
+{
102
+return $this->g(Stash::class);
103
+}
104 104
 }
Please login to merge, or discard this patch.
jaxon-core/src/Di/Container.php 1 patch
Switch Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -30,148 +30,148 @@  discard block
 block discarded – undo
30 30
 
31 31
 class Container implements ContainerInterface
32 32
 {
33
-    use Traits\AppTrait;
34
-    use Traits\PsrTrait;
35
-    use Traits\RequestTrait;
36
-    use Traits\ResponseTrait;
37
-    use Traits\PluginTrait;
38
-    use Traits\CallableTrait;
39
-    use Traits\ViewTrait;
40
-    use Traits\UtilTrait;
41
-    use Traits\MetadataTrait;
42
-    use Traits\DiAutoTrait;
33
+use Traits\AppTrait;
34
+use Traits\PsrTrait;
35
+use Traits\RequestTrait;
36
+use Traits\ResponseTrait;
37
+use Traits\PluginTrait;
38
+use Traits\CallableTrait;
39
+use Traits\ViewTrait;
40
+use Traits\UtilTrait;
41
+use Traits\MetadataTrait;
42
+use Traits\DiAutoTrait;
43 43
 
44
-    /**
44
+/**
45 45
      * The library Dependency Injection Container
46 46
      *
47 47
      * @var PimpleContainer
48 48
      */
49
-    private $xLibContainer;
49
+private $xLibContainer;
50 50
 
51
-    /**
51
+/**
52 52
      * The application or framework Dependency Injection Container
53 53
      *
54 54
      * @var ContainerInterface
55 55
      */
56
-    private $xAppContainer = null;
56
+private $xAppContainer = null;
57 57
 
58
-    /**
58
+/**
59 59
      * The class constructor
60 60
      */
61
-    public function __construct()
62
-    {
63
-        $this->xLibContainer = new PimpleContainer();
61
+public function __construct()
62
+{
63
+$this->xLibContainer = new PimpleContainer();
64 64
 
65
-        // The container instance is saved in the container.
66
-        $this->val(Container::class, $this);
65
+// The container instance is saved in the container.
66
+$this->val(Container::class, $this);
67 67
 
68
-        // Register the null logger by default
69
-        $this->setLogger(new NullLogger());
68
+// Register the null logger by default
69
+$this->setLogger(new NullLogger());
70 70
 
71
-        // Setup the logger facade. Don't overwrite if it's already set.
72
-        ContainerWrapper::setContainer($this, false);
71
+// Setup the logger facade. Don't overwrite if it's already set.
72
+ContainerWrapper::setContainer($this, false);
73 73
 
74
-        $sBaseDir = dirname(__DIR__, 2);
75
-        // Template directory
76
-        $this->val('jaxon.core.dir.template', "$sBaseDir/templates");
74
+$sBaseDir = dirname(__DIR__, 2);
75
+// Template directory
76
+$this->val('jaxon.core.dir.template', "$sBaseDir/templates");
77 77
 
78
-        // Translation directory
79
-        $this->val('jaxon.core.dir.translation', "$sBaseDir/translations");
78
+// Translation directory
79
+$this->val('jaxon.core.dir.translation', "$sBaseDir/translations");
80 80
 
81
-        $this->registerAll();
82
-        $this->setEventHandlers();
83
-    }
81
+$this->registerAll();
82
+$this->setEventHandlers();
83
+}
84 84
 
85
-    /**
85
+/**
86 86
      * The container for parameters
87 87
      *
88 88
      * @return Container
89 89
      */
90
-    protected function cn(): Container
91
-    {
92
-        return $this;
93
-    }
90
+protected function cn(): Container
91
+{
92
+return $this;
93
+}
94 94
 
95
-    /**
95
+/**
96 96
      * Register the values into the container
97 97
      *
98 98
      * @return void
99 99
      */
100
-    private function registerAll()
101
-    {
102
-        $this->registerApp();
103
-        $this->registerPsr();
104
-        $this->registerRequests();
105
-        $this->registerResponses();
106
-        $this->registerPlugins();
107
-        $this->registerCallables();
108
-        $this->registerViews();
109
-        $this->registerUtils();
110
-        $this->registerMetadataReader();
111
-    }
100
+private function registerAll()
101
+{
102
+$this->registerApp();
103
+$this->registerPsr();
104
+$this->registerRequests();
105
+$this->registerResponses();
106
+$this->registerPlugins();
107
+$this->registerCallables();
108
+$this->registerViews();
109
+$this->registerUtils();
110
+$this->registerMetadataReader();
111
+}
112 112
 
113
-    /**
113
+/**
114 114
      * Set the logger
115 115
      *
116 116
      * @param LoggerInterface|Closure $xLogger
117 117
      *
118 118
      * @return void
119 119
      */
120
-    public function setLogger(LoggerInterface|Closure $xLogger)
121
-    {
122
-        is_a($xLogger, LoggerInterface::class) ?
123
-            $this->val(LoggerInterface::class, $xLogger) :
124
-            $this->set(LoggerInterface::class, $xLogger);
125
-    }
120
+public function setLogger(LoggerInterface|Closure $xLogger)
121
+{
122
+is_a($xLogger, LoggerInterface::class) ?
123
+$this->val(LoggerInterface::class, $xLogger) :
124
+$this->set(LoggerInterface::class, $xLogger);
125
+}
126 126
 
127
-    /**
127
+/**
128 128
      * Get the logger
129 129
      *
130 130
      * @return LoggerInterface
131 131
      */
132
-    public function getLogger(): LoggerInterface
133
-    {
134
-        return $this->get(LoggerInterface::class);
135
-    }
132
+public function getLogger(): LoggerInterface
133
+{
134
+return $this->get(LoggerInterface::class);
135
+}
136 136
 
137
-    /**
137
+/**
138 138
      * Set the container provided by the integrated framework
139 139
      *
140 140
      * @param ContainerInterface $xContainer    The container implementation
141 141
      *
142 142
      * @return void
143 143
      */
144
-    public function setContainer(ContainerInterface $xContainer)
145
-    {
146
-        $this->xAppContainer = $xContainer;
147
-    }
144
+public function setContainer(ContainerInterface $xContainer)
145
+{
146
+$this->xAppContainer = $xContainer;
147
+}
148 148
 
149
-    /**
149
+/**
150 150
      * Check if a class is defined in the container
151 151
      *
152 152
      * @param string $sClass    The full class name
153 153
      *
154 154
      * @return bool
155 155
      */
156
-    public function h(string $sClass): bool
157
-    {
158
-        return $this->xLibContainer->offsetExists($sClass);
159
-    }
156
+public function h(string $sClass): bool
157
+{
158
+return $this->xLibContainer->offsetExists($sClass);
159
+}
160 160
 
161
-    /**
161
+/**
162 162
      * Check if a class is defined in the container
163 163
      *
164 164
      * @param string $sClass    The full class name
165 165
      *
166 166
      * @return bool
167 167
      */
168
-    public function has(string $sClass): bool
169
-    {
170
-        return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ?
171
-            true : $this->xLibContainer->offsetExists($sClass);
172
-    }
168
+public function has(string $sClass): bool
169
+{
170
+return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ?
171
+true : $this->xLibContainer->offsetExists($sClass);
172
+}
173 173
 
174
-    /**
174
+/**
175 175
      * Get a class instance
176 176
      *
177 177
      * @template T
@@ -179,12 +179,12 @@  discard block
 block discarded – undo
179 179
      *
180 180
      * @return T
181 181
      */
182
-    public function g(string $sClass): mixed
183
-    {
184
-        return $this->xLibContainer->offsetGet($sClass);
185
-    }
182
+public function g(string $sClass): mixed
183
+{
184
+return $this->xLibContainer->offsetGet($sClass);
185
+}
186 186
 
187
-    /**
187
+/**
188 188
      * Get a class instance
189 189
      *
190 190
      * @template T
@@ -193,24 +193,24 @@  discard block
 block discarded – undo
193 193
      * @return T
194 194
      * @throws SetupException
195 195
      */
196
-    public function get(string $sClass): mixed
197
-    {
198
-        try
199
-        {
200
-            return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ?
201
-                $this->xAppContainer->get($sClass) : $this->xLibContainer->offsetGet($sClass);
202
-        }
203
-        catch(Throwable $e)
204
-        {
205
-            $xLogger = $this->g(LoggerInterface::class);
206
-            $xTranslator = $this->g(Translator::class);
207
-            $sMessage = $e->getMessage() . ': ' . $xTranslator->trans('errors.class.container', ['name' => $sClass]);
208
-            $xLogger->error($e->getMessage(), ['message' => $sMessage]);
209
-            throw new SetupException($sMessage);
210
-        }
211
-    }
196
+public function get(string $sClass): mixed
197
+{
198
+try
199
+{
200
+return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ?
201
+    $this->xAppContainer->get($sClass) : $this->xLibContainer->offsetGet($sClass);
202
+}
203
+catch(Throwable $e)
204
+{
205
+$xLogger = $this->g(LoggerInterface::class);
206
+$xTranslator = $this->g(Translator::class);
207
+$sMessage = $e->getMessage() . ': ' . $xTranslator->trans('errors.class.container', ['name' => $sClass]);
208
+$xLogger->error($e->getMessage(), ['message' => $sMessage]);
209
+throw new SetupException($sMessage);
210
+}
211
+}
212 212
 
213
-    /**
213
+/**
214 214
      * Save a closure in the container
215 215
      *
216 216
      * @param string|class-string $sClass    The full class name
@@ -219,15 +219,15 @@  discard block
 block discarded – undo
219 219
      *
220 220
      * @return void
221 221
      */
222
-    public function set(string $sClass, Closure $xClosure, bool $bIsSingleton = true)
223
-    {
224
-        // Wrap the user closure into a new closure, so it can take this container as a parameter.
225
-        $xClosure = fn() => $xClosure($this);
226
-        $this->xLibContainer->offsetSet($sClass, $bIsSingleton ?
227
-            $xClosure : $this->xLibContainer->factory($xClosure));
228
-    }
222
+public function set(string $sClass, Closure $xClosure, bool $bIsSingleton = true)
223
+{
224
+// Wrap the user closure into a new closure, so it can take this container as a parameter.
225
+$xClosure = fn() => $xClosure($this);
226
+$this->xLibContainer->offsetSet($sClass, $bIsSingleton ?
227
+$xClosure : $this->xLibContainer->factory($xClosure));
228
+}
229 229
 
230
-    /**
230
+/**
231 231
      * Save a value in the container
232 232
      *
233 233
      * @param string|class-string $sKey    The key
@@ -235,12 +235,12 @@  discard block
 block discarded – undo
235 235
      *
236 236
      * @return void
237 237
      */
238
-    public function val(string $sKey, $xValue)
239
-    {
240
-       $this->xLibContainer->offsetSet($sKey, $xValue);
241
-    }
238
+public function val(string $sKey, $xValue)
239
+{
240
+$this->xLibContainer->offsetSet($sKey, $xValue);
241
+}
242 242
 
243
-    /**
243
+/**
244 244
      * Set an alias in the container
245 245
      *
246 246
      * @param string|class-string $sAlias    The alias name
@@ -248,32 +248,32 @@  discard block
 block discarded – undo
248 248
      *
249 249
      * @return void
250 250
      */
251
-    public function alias(string $sAlias, string $sClass)
252
-    {
253
-        $this->set($sAlias, function($di) use ($sClass) {
254
-            return $di->get($sClass);
255
-        });
256
-    }
251
+public function alias(string $sAlias, string $sClass)
252
+{
253
+$this->set($sAlias, function($di) use ($sClass) {
254
+return $di->get($sClass);
255
+});
256
+}
257 257
 
258
-    /**
258
+/**
259 259
      * Get the session manager
260 260
      *
261 261
      * @return SessionInterface|null
262 262
      */
263
-    public function getSessionManager(): ?SessionInterface
264
-    {
265
-        return $this->h(SessionInterface::class) ? $this->g(SessionInterface::class) : null;
266
-    }
263
+public function getSessionManager(): ?SessionInterface
264
+{
265
+return $this->h(SessionInterface::class) ? $this->g(SessionInterface::class) : null;
266
+}
267 267
 
268
-    /**
268
+/**
269 269
      * Set the session manager
270 270
      *
271 271
      * @param Closure $xClosure    A closure to create the session manager instance
272 272
      *
273 273
      * @return void
274 274
      */
275
-    public function setSessionManager(Closure $xClosure)
276
-    {
277
-        $this->set(SessionInterface::class, $xClosure);
278
-    }
275
+public function setSessionManager(Closure $xClosure)
276
+{
277
+$this->set(SessionInterface::class, $xClosure);
278
+}
279 279
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Code/AssetManager.php 2 patches
Switch Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -35,328 +35,328 @@  discard block
 block discarded – undo
35 35
 
36 36
 class AssetManager
37 37
 {
38
-    /**
38
+/**
39 39
      * @var array<Filesystem>
40 40
      */
41
-    protected array $aStorage = [];
41
+protected array $aStorage = [];
42 42
 
43
-    /**
43
+/**
44 44
      * Default library URL
45 45
      *
46 46
      * @var string
47 47
      */
48
-    private const JS_LIB_URL = 'https://cdn.jsdelivr.net/gh/jaxon-php/[email protected]/dist';
48
+private const JS_LIB_URL = 'https://cdn.jsdelivr.net/gh/jaxon-php/[email protected]/dist';
49 49
 
50
-    /**
50
+/**
51 51
      * The constructor
52 52
      *
53 53
      * @param ConfigManager $xConfigManager
54 54
      * @param StorageManager $xStorageManager
55 55
      * @param MinifierInterface $xMinifier
56 56
      */
57
-    public function __construct(private ConfigManager $xConfigManager,
58
-        private StorageManager $xStorageManager, private MinifierInterface $xMinifier)
59
-    {}
57
+public function __construct(private ConfigManager $xConfigManager,
58
+private StorageManager $xStorageManager, private MinifierInterface $xMinifier)
59
+{}
60 60
 
61
-    /**
61
+/**
62 62
      * @return Config
63 63
      */
64
-    protected function config(): Config
65
-    {
66
-        return $this->xConfigManager->getExportConfig();
67
-    }
64
+protected function config(): Config
65
+{
66
+return $this->xConfigManager->getExportConfig();
67
+}
68 68
 
69
-    /**
69
+/**
70 70
      * @param string $sAsset "js" or "css"
71 71
      *
72 72
      * @return Filesystem
73 73
      */
74
-    protected function _storage(string $sAsset): Filesystem
75
-    {
76
-        if($this->config()->hasOption('storage'))
77
-        {
78
-            return $this->xStorageManager->get($this->config()->getOption('storage'));
79
-        }
80
-
81
-        $sRootDir = $this->getAssetDir($sAsset);
82
-        // Fylsystem options: we don't want the root dir to be created if it doesn't exist.
83
-        $aAdapterOptions = ['lazyRootCreation' => true];
84
-        $aDirOptions = [
85
-            'config' => [
86
-                'public_url' => $this->getAssetUri($sAsset),
87
-            ],
88
-        ];
89
-        return $this->xStorageManager
90
-            ->adapter('local', $aAdapterOptions)
91
-            ->make($sRootDir, $aDirOptions);
92
-    }
93
-
94
-    /**
74
+protected function _storage(string $sAsset): Filesystem
75
+{
76
+if($this->config()->hasOption('storage'))
77
+{
78
+return $this->xStorageManager->get($this->config()->getOption('storage'));
79
+}
80
+
81
+$sRootDir = $this->getAssetDir($sAsset);
82
+// Fylsystem options: we don't want the root dir to be created if it doesn't exist.
83
+$aAdapterOptions = ['lazyRootCreation' => true];
84
+$aDirOptions = [
85
+'config' => [
86
+    'public_url' => $this->getAssetUri($sAsset),
87
+],
88
+];
89
+return $this->xStorageManager
90
+->adapter('local', $aAdapterOptions)
91
+->make($sRootDir, $aDirOptions);
92
+}
93
+
94
+/**
95 95
      * @param string $sAsset "js" or "css"
96 96
      *
97 97
      * @return Filesystem
98 98
      */
99
-    protected function storage(string $sAsset): Filesystem
100
-    {
101
-        return $this->aStorage[$sAsset] ??= $this->_storage($sAsset);
102
-    }
99
+protected function storage(string $sAsset): Filesystem
100
+{
101
+return $this->aStorage[$sAsset] ??= $this->_storage($sAsset);
102
+}
103 103
 
104
-    /**
104
+/**
105 105
      * @param array $aValues
106 106
      *
107 107
      * @return string
108 108
      */
109
-    public function makeFileOptions(array $aValues): string
110
-    {
111
-        if(!isset($aValues['options']) || !$aValues['options'])
112
-        {
113
-            return '';
114
-        }
115
-        if(is_array($aValues['options']))
116
-        {
117
-            $aOptions = [];
118
-            foreach($aValues['options'] as $sName => $sValue)
119
-            {
120
-                $aOptions[] = "{$sName}=\"" . trim($sValue) . '"';
121
-            }
122
-            return implode(' ', $aOptions);
123
-        }
124
-        if(is_string($aValues['options']))
125
-        {
126
-            return trim($aValues['options']);
127
-        }
128
-        return '';
129
-    }
130
-
131
-    /**
109
+public function makeFileOptions(array $aValues): string
110
+{
111
+if(!isset($aValues['options']) || !$aValues['options'])
112
+{
113
+return '';
114
+}
115
+if(is_array($aValues['options']))
116
+{
117
+$aOptions = [];
118
+foreach($aValues['options'] as $sName => $sValue)
119
+{
120
+    $aOptions[] = "{$sName}=\"" . trim($sValue) . '"';
121
+}
122
+return implode(' ', $aOptions);
123
+}
124
+if(is_string($aValues['options']))
125
+{
126
+return trim($aValues['options']);
127
+}
128
+return '';
129
+}
130
+
131
+/**
132 132
      * Get app js options
133 133
      *
134 134
      * @return string
135 135
      */
136
-    public function getJsOptions(): string
137
-    {
138
-        // Revert to the options in the "lib" section in the config,
139
-        // if there is no options defined in the 'app' section.
140
-        if(!$this->xConfigManager->hasAppOption('assets'))
141
-        {
142
-            $sOptions = trim($this->config()->getOption('js.options', ''));
143
-            return $sOptions === '' ? 'charset="UTF-8"' : "$sOptions charset=\"UTF-8\"";
144
-        }
145
-
146
-        return $this->makeFileOptions([
147
-            'options' => $this->config()->getOption('js.options', ''),
148
-        ]);
149
-    }
150
-
151
-    /**
136
+public function getJsOptions(): string
137
+{
138
+// Revert to the options in the "lib" section in the config,
139
+// if there is no options defined in the 'app' section.
140
+if(!$this->xConfigManager->hasAppOption('assets'))
141
+{
142
+$sOptions = trim($this->config()->getOption('js.options', ''));
143
+return $sOptions === '' ? 'charset="UTF-8"' : "$sOptions charset=\"UTF-8\"";
144
+}
145
+
146
+return $this->makeFileOptions([
147
+'options' => $this->config()->getOption('js.options', ''),
148
+]);
149
+}
150
+
151
+/**
152 152
      * Get app js options
153 153
      *
154 154
      * @return string
155 155
      */
156
-    public function getCssOptions(): string
157
-    {
158
-        return $this->makeFileOptions([
159
-            'options' => $this->config()->getOption('css.options', ''),
160
-        ]);
161
-    }
162
-
163
-    /**
156
+public function getCssOptions(): string
157
+{
158
+return $this->makeFileOptions([
159
+'options' => $this->config()->getOption('css.options', ''),
160
+]);
161
+}
162
+
163
+/**
164 164
      * Check if the assets of this plugin shall be included in Jaxon generated code.
165 165
      *
166 166
      * @param Generator|CssGenerator|JsGenerator $xGenerator
167 167
      *
168 168
      * @return bool
169 169
      */
170
-    public function shallIncludeAssets(Generator|CssGenerator|JsGenerator $xGenerator): bool
171
-    {
172
-        if(!is_subclass_of($xGenerator, AbstractPlugin::class))
173
-        {
174
-            return true;
175
-        }
176
-
177
-        /** @var AbstractPlugin */
178
-        $xPlugin = $xGenerator;
179
-        $sPluginOptionName = 'include.' . $xPlugin->getName();
180
-
181
-        return $this->config()->hasOption($sPluginOptionName) ?
182
-            $this->config()->getOption($sPluginOptionName) :
183
-            $this->config()->getOption('include.all', true);
184
-    }
185
-
186
-    /**
170
+public function shallIncludeAssets(Generator|CssGenerator|JsGenerator $xGenerator): bool
171
+{
172
+if(!is_subclass_of($xGenerator, AbstractPlugin::class))
173
+{
174
+return true;
175
+}
176
+
177
+/** @var AbstractPlugin */
178
+$xPlugin = $xGenerator;
179
+$sPluginOptionName = 'include.' . $xPlugin->getName();
180
+
181
+return $this->config()->hasOption($sPluginOptionName) ?
182
+$this->config()->getOption($sPluginOptionName) :
183
+$this->config()->getOption('include.all', true);
184
+}
185
+
186
+/**
187 187
      * Get the HTML tags to include Jaxon javascript files into the page
188 188
      *
189 189
      * @return array
190 190
      */
191
-    public function getJsLibUrls(): array
192
-    {
193
-        $sJsExtension = $this->config()->getOption('minify') ? '.min.js' : '.js';
194
-        // The URI for the javascript library files
195
-        $sJsLibUri = $this->xConfigManager->getOption('js.lib.uri', self::JS_LIB_URL);
196
-        $sJsLibUri = rtrim($sJsLibUri, '/');
197
-
198
-        // Add component files to the javascript file array.
199
-        $sChibiUrl = "$sJsLibUri/libs/chibi/chibi$sJsExtension";
200
-        $aJsUrls = [
201
-            $this->xConfigManager->getOption('js.lib.jq', $sChibiUrl),
202
-            "$sJsLibUri/jaxon.core$sJsExtension",
203
-        ];
204
-        if($this->xConfigManager->getOption('core.debug.on'))
205
-        {
206
-            $sLanguage = $this->xConfigManager->getOption('core.language');
207
-            $aJsUrls[] = "$sJsLibUri/jaxon.debug$sJsExtension";
208
-            $aJsUrls[] = "$sJsLibUri/lang/jaxon.$sLanguage$sJsExtension";
209
-        }
210
-
211
-        return $aJsUrls;
212
-    }
213
-
214
-    /**
191
+public function getJsLibUrls(): array
192
+{
193
+$sJsExtension = $this->config()->getOption('minify') ? '.min.js' : '.js';
194
+// The URI for the javascript library files
195
+$sJsLibUri = $this->xConfigManager->getOption('js.lib.uri', self::JS_LIB_URL);
196
+$sJsLibUri = rtrim($sJsLibUri, '/');
197
+
198
+// Add component files to the javascript file array.
199
+$sChibiUrl = "$sJsLibUri/libs/chibi/chibi$sJsExtension";
200
+$aJsUrls = [
201
+$this->xConfigManager->getOption('js.lib.jq', $sChibiUrl),
202
+"$sJsLibUri/jaxon.core$sJsExtension",
203
+];
204
+if($this->xConfigManager->getOption('core.debug.on'))
205
+{
206
+$sLanguage = $this->xConfigManager->getOption('core.language');
207
+$aJsUrls[] = "$sJsLibUri/jaxon.debug$sJsExtension";
208
+$aJsUrls[] = "$sJsLibUri/lang/jaxon.$sLanguage$sJsExtension";
209
+}
210
+
211
+return $aJsUrls;
212
+}
213
+
214
+/**
215 215
      * @param string $sAsset "js" or "css"
216 216
      *
217 217
      * @return string
218 218
      */
219
-    private function getAssetUri(string $sAsset): string
220
-    {
221
-        return rtrim($this->config()->hasOption("$sAsset.uri") ?
222
-            $this->config()->getOption("$sAsset.uri") :
223
-            $this->config()->getOption('uri', ''), '/');
224
-    }
225
-
226
-    /**
219
+private function getAssetUri(string $sAsset): string
220
+{
221
+return rtrim($this->config()->hasOption("$sAsset.uri") ?
222
+$this->config()->getOption("$sAsset.uri") :
223
+$this->config()->getOption('uri', ''), '/');
224
+}
225
+
226
+/**
227 227
      * @param string $sAsset "js" or "css"
228 228
      *
229 229
      * @return string
230 230
      */
231
-    private function getAssetDir(string $sAsset): string
232
-    {
233
-        return rtrim($this->config()->hasOption("$sAsset.dir") ?
234
-            $this->config()->getOption("$sAsset.dir") :
235
-            $this->config()->getOption('dir', ''), '/\/');
236
-    }
237
-
238
-    /**
231
+private function getAssetDir(string $sAsset): string
232
+{
233
+return rtrim($this->config()->hasOption("$sAsset.dir") ?
234
+$this->config()->getOption("$sAsset.dir") :
235
+$this->config()->getOption('dir', ''), '/\/');
236
+}
237
+
238
+/**
239 239
      * @param Closure $cGetHash
240 240
      * @param string $sAsset "js" or "css"
241 241
      *
242 242
      * @return string
243 243
      */
244
-    private function getAssetFile(Closure $cGetHash, string $sAsset): string
245
-    {
246
-        return $this->config()->hasOption("$sAsset.file") ?
247
-            $this->config()->getOption("$sAsset.file") :
248
-            // Make sure to call invoke callback only if required.
249
-            ($this->config()->hasOption("file") ?
250
-            $this->config()->getOption("file") : $cGetHash());
251
-    }
252
-
253
-    /**
244
+private function getAssetFile(Closure $cGetHash, string $sAsset): string
245
+{
246
+return $this->config()->hasOption("$sAsset.file") ?
247
+$this->config()->getOption("$sAsset.file") :
248
+// Make sure to call invoke callback only if required.
249
+($this->config()->hasOption("file") ?
250
+$this->config()->getOption("file") : $cGetHash());
251
+}
252
+
253
+/**
254 254
      * @param string $sAsset "js" or "css"
255 255
      *
256 256
      * @return bool
257 257
      */
258
-    private function minifyEnabled(string $sAsset): bool
259
-    {
260
-        return $this->config()->hasOption("$sAsset.minify") ?
261
-            $this->config()->getOption("$sAsset.minify") :
262
-            $this->config()->getOption('minify', false);
263
-    }
264
-
265
-    /**
258
+private function minifyEnabled(string $sAsset): bool
259
+{
260
+return $this->config()->hasOption("$sAsset.minify") ?
261
+$this->config()->getOption("$sAsset.minify") :
262
+$this->config()->getOption('minify', false);
263
+}
264
+
265
+/**
266 266
      * @param string $sAsset "js" or "css"
267 267
      *
268 268
      * @return bool
269 269
      */
270
-    private function exportEnabled(string $sAsset): bool
271
-    {
272
-        return $this->config()->hasOption("$sAsset.export") ?
273
-            $this->config()->getOption("$sAsset.export") :
274
-            $this->config()->getOption('export', false);
275
-    }
276
-
277
-    /**
270
+private function exportEnabled(string $sAsset): bool
271
+{
272
+return $this->config()->hasOption("$sAsset.export") ?
273
+$this->config()->getOption("$sAsset.export") :
274
+$this->config()->getOption('export', false);
275
+}
276
+
277
+/**
278 278
      * @param Filesystem $xStorage
279 279
      * @param string $sFilePath
280 280
      *
281 281
      * @return bool
282 282
      */
283
-    private function fileExists(Filesystem $xStorage, string $sFilePath): bool
284
-    {
285
-        try
286
-        {
287
-            return $xStorage->fileExists($sFilePath);
288
-        }
289
-        catch(Throwable $e)
290
-        {
291
-            Logger::warning("Unable to check asset file at $sFilePath.", [
292
-                'error' => $e->getMessage(),
293
-            ]);
294
-            return false;
295
-        }
296
-    }
297
-
298
-    /**
283
+private function fileExists(Filesystem $xStorage, string $sFilePath): bool
284
+{
285
+try
286
+{
287
+return $xStorage->fileExists($sFilePath);
288
+}
289
+catch(Throwable $e)
290
+{
291
+Logger::warning("Unable to check asset file at $sFilePath.", [
292
+    'error' => $e->getMessage(),
293
+]);
294
+return false;
295
+}
296
+}
297
+
298
+/**
299 299
      * @param Filesystem $xStorage
300 300
      * @param string $sFilePath
301 301
      * @param string $sContent
302 302
      *
303 303
      * @return bool
304 304
      */
305
-    private function writeFile(Filesystem $xStorage, string $sFilePath, string $sContent): bool
306
-    {
307
-        try
308
-        {
309
-            $xStorage->write($sFilePath, $sContent);
310
-            return true;
311
-        }
312
-        catch(Throwable $e)
313
-        {
314
-            Logger::warning("Unable to write to asset file at $sFilePath.", [
315
-                'error' => $e->getMessage(),
316
-            ]);
317
-            return false;
318
-        }
319
-    }
320
-
321
-    /**
305
+private function writeFile(Filesystem $xStorage, string $sFilePath, string $sContent): bool
306
+{
307
+try
308
+{
309
+$xStorage->write($sFilePath, $sContent);
310
+return true;
311
+}
312
+catch(Throwable $e)
313
+{
314
+Logger::warning("Unable to write to asset file at $sFilePath.", [
315
+    'error' => $e->getMessage(),
316
+]);
317
+return false;
318
+}
319
+}
320
+
321
+/**
322 322
      * @param string $sAsset "js" or "css"
323 323
      * @param string $sFilePath
324 324
      * @param string $sMinFilePath
325 325
      *
326 326
      * @return bool
327 327
      */
328
-    private function minifyAsset(string $sAsset, string $sFilePath, string $sMinFilePath): bool
329
-    {
330
-        if(!$this->minifyEnabled($sAsset))
331
-        {
332
-            return false;
333
-        }
334
-
335
-        $xStorage = $this->storage($sAsset);
336
-        if($xStorage->fileExists($sMinFilePath))
337
-        {
338
-            return true;
339
-        }
340
-
341
-        $sMinContent = $sAsset === 'js' ?
342
-            $this->xMinifier->minifyJsCode($xStorage->read($sFilePath)) :
343
-            $this->xMinifier->minifyCssCode($xStorage->read($sFilePath));
344
-        if($sMinContent === false || $sMinContent === '')
345
-        {
346
-            return false;
347
-        }
348
-
349
-        return $this->writeFile($xStorage, $sMinFilePath, $sMinContent);
350
-    }
351
-
352
-    private function getPublicUrl(string $sFilePath, string $sAsset): string
353
-    {
354
-        $sUri = $this->getAssetUri($sAsset);
355
-        return $sUri !== '' ? "$sUri/$sFilePath" :
356
-            $this->storage($sAsset)->publicUrl($sFilePath);
357
-    }
358
-
359
-    /**
328
+private function minifyAsset(string $sAsset, string $sFilePath, string $sMinFilePath): bool
329
+{
330
+if(!$this->minifyEnabled($sAsset))
331
+{
332
+return false;
333
+}
334
+
335
+$xStorage = $this->storage($sAsset);
336
+if($xStorage->fileExists($sMinFilePath))
337
+{
338
+return true;
339
+}
340
+
341
+$sMinContent = $sAsset === 'js' ?
342
+$this->xMinifier->minifyJsCode($xStorage->read($sFilePath)) :
343
+$this->xMinifier->minifyCssCode($xStorage->read($sFilePath));
344
+if($sMinContent === false || $sMinContent === '')
345
+{
346
+return false;
347
+}
348
+
349
+return $this->writeFile($xStorage, $sMinFilePath, $sMinContent);
350
+}
351
+
352
+private function getPublicUrl(string $sFilePath, string $sAsset): string
353
+{
354
+$sUri = $this->getAssetUri($sAsset);
355
+return $sUri !== '' ? "$sUri/$sFilePath" :
356
+$this->storage($sAsset)->publicUrl($sFilePath);
357
+}
358
+
359
+/**
360 360
      * Write javascript or css files and return the corresponding URI
361 361
      *
362 362
      * @param Closure $cGetHash
@@ -365,49 +365,49 @@  discard block
 block discarded – undo
365 365
      *
366 366
      * @return string
367 367
      */
368
-    public function createFiles(Closure $cGetHash, Closure $cGetCode, string $sAsset): string
369
-    {
370
-        // Check if the config options allow the file creation.
371
-        // - The assets.js.export option must be set to true
372
-        // - The assets.js.uri and assets.js.dir options must be set to non null values
373
-        if(!$this->exportEnabled($sAsset) ||
374
-            // $this->getAssetUri($sAsset) === '' ||
375
-            $this->getAssetDir($sAsset) === '')
376
-        {
377
-            return '';
378
-        }
379
-
380
-        // Check dir access
381
-        $xStorage = $this->storage($sAsset);
382
-        $sFileName = $this->getAssetFile($cGetHash, $sAsset);
383
-        // - The assets.js.dir must be writable
384
-        if(!$sFileName || !$xStorage->directoryExists('') /*|| $xStorage->visibility('') !== 'public'*/)
385
-        {
386
-            return '';
387
-        }
388
-
389
-        $sFilePath = "{$sFileName}.{$sAsset}";
390
-        $sMinFilePath = "{$sFileName}.min.{$sAsset}";
391
-
392
-        // Try to create the file and write the code, if it doesn't exist.
393
-        if(!$this->fileExists($xStorage, $sFilePath) &&
394
-            !$this->writeFile($xStorage, $sFilePath, $cGetCode()))
395
-        {
396
-            return '';
397
-        }
398
-
399
-        if(!$this->minifyEnabled($sAsset))
400
-        {
401
-            return $this->getPublicUrl($sFilePath, $sAsset);
402
-        }
403
-
404
-        // If the file cannot be minified, return the plain js file.
405
-        return $this->minifyAsset($sAsset, $sFilePath, $sMinFilePath) ?
406
-            $this->getPublicUrl($sMinFilePath, $sAsset) :
407
-            $this->getPublicUrl($sFilePath, $sAsset);
408
-    }
409
-
410
-    /**
368
+public function createFiles(Closure $cGetHash, Closure $cGetCode, string $sAsset): string
369
+{
370
+// Check if the config options allow the file creation.
371
+// - The assets.js.export option must be set to true
372
+// - The assets.js.uri and assets.js.dir options must be set to non null values
373
+if(!$this->exportEnabled($sAsset) ||
374
+// $this->getAssetUri($sAsset) === '' ||
375
+$this->getAssetDir($sAsset) === '')
376
+{
377
+return '';
378
+}
379
+
380
+// Check dir access
381
+$xStorage = $this->storage($sAsset);
382
+$sFileName = $this->getAssetFile($cGetHash, $sAsset);
383
+// - The assets.js.dir must be writable
384
+if(!$sFileName || !$xStorage->directoryExists('') /*|| $xStorage->visibility('') !== 'public'*/)
385
+{
386
+return '';
387
+}
388
+
389
+$sFilePath = "{$sFileName}.{$sAsset}";
390
+$sMinFilePath = "{$sFileName}.min.{$sAsset}";
391
+
392
+// Try to create the file and write the code, if it doesn't exist.
393
+if(!$this->fileExists($xStorage, $sFilePath) &&
394
+!$this->writeFile($xStorage, $sFilePath, $cGetCode()))
395
+{
396
+return '';
397
+}
398
+
399
+if(!$this->minifyEnabled($sAsset))
400
+{
401
+return $this->getPublicUrl($sFilePath, $sAsset);
402
+}
403
+
404
+// If the file cannot be minified, return the plain js file.
405
+return $this->minifyAsset($sAsset, $sFilePath, $sMinFilePath) ?
406
+$this->getPublicUrl($sMinFilePath, $sAsset) :
407
+$this->getPublicUrl($sFilePath, $sAsset);
408
+}
409
+
410
+/**
411 411
      * Write javascript files and return the corresponding URI
412 412
      *
413 413
      * @param Closure $cGetHash
@@ -415,13 +415,13 @@  discard block
 block discarded – undo
415 415
      *
416 416
      * @return string
417 417
      */
418
-    public function createJsFiles(Closure $cGetHash, Closure $cGetCode): string
419
-    {
420
-        // Using closures, so the code generator is actually called only if it is really required.
421
-        return $this->createFiles($cGetHash, $cGetCode, 'js');
422
-    }
418
+public function createJsFiles(Closure $cGetHash, Closure $cGetCode): string
419
+{
420
+// Using closures, so the code generator is actually called only if it is really required.
421
+return $this->createFiles($cGetHash, $cGetCode, 'js');
422
+}
423 423
 
424
-    /**
424
+/**
425 425
      * Write javascript files and return the corresponding URI
426 426
      *
427 427
      * @param Closure $cGetHash
@@ -429,9 +429,9 @@  discard block
 block discarded – undo
429 429
      *
430 430
      * @return string
431 431
      */
432
-    public function createCssFiles(Closure $cGetHash, Closure $cGetCode): string
433
-    {
434
-        // Using closures, so the code generator is actually called only if it is really required.
435
-        return $this->createFiles($cGetHash, $cGetCode, 'css');
436
-    }
432
+public function createCssFiles(Closure $cGetHash, Closure $cGetCode): string
433
+{
434
+// Using closures, so the code generator is actually called only if it is really required.
435
+return $this->createFiles($cGetHash, $cGetCode, 'css');
436
+}
437 437
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -35 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      */
74 74
     protected function _storage(string $sAsset): Filesystem
75 75
     {
76
-        if($this->config()->hasOption('storage'))
76
+        if ($this->config()->hasOption('storage'))
77 77
         {
78 78
             return $this->xStorageManager->get($this->config()->getOption('storage'));
79 79
         }
@@ -108,20 +108,20 @@  discard block
 block discarded – undo
108 108
      */
109 109
     public function makeFileOptions(array $aValues): string
110 110
     {
111
-        if(!isset($aValues['options']) || !$aValues['options'])
111
+        if (!isset($aValues['options']) || !$aValues['options'])
112 112
         {
113 113
             return '';
114 114
         }
115
-        if(is_array($aValues['options']))
115
+        if (is_array($aValues['options']))
116 116
         {
117 117
             $aOptions = [];
118
-            foreach($aValues['options'] as $sName => $sValue)
118
+            foreach ($aValues['options'] as $sName => $sValue)
119 119
             {
120 120
                 $aOptions[] = "{$sName}=\"" . trim($sValue) . '"';
121 121
             }
122 122
             return implode(' ', $aOptions);
123 123
         }
124
-        if(is_string($aValues['options']))
124
+        if (is_string($aValues['options']))
125 125
         {
126 126
             return trim($aValues['options']);
127 127
         }
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
     {
138 138
         // Revert to the options in the "lib" section in the config,
139 139
         // if there is no options defined in the 'app' section.
140
-        if(!$this->xConfigManager->hasAppOption('assets'))
140
+        if (!$this->xConfigManager->hasAppOption('assets'))
141 141
         {
142 142
             $sOptions = trim($this->config()->getOption('js.options', ''));
143 143
             return $sOptions === '' ? 'charset="UTF-8"' : "$sOptions charset=\"UTF-8\"";
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
      */
170 170
     public function shallIncludeAssets(Generator|CssGenerator|JsGenerator $xGenerator): bool
171 171
     {
172
-        if(!is_subclass_of($xGenerator, AbstractPlugin::class))
172
+        if (!is_subclass_of($xGenerator, AbstractPlugin::class))
173 173
         {
174 174
             return true;
175 175
         }
@@ -179,8 +179,7 @@  discard block
 block discarded – undo
179 179
         $sPluginOptionName = 'include.' . $xPlugin->getName();
180 180
 
181 181
         return $this->config()->hasOption($sPluginOptionName) ?
182
-            $this->config()->getOption($sPluginOptionName) :
183
-            $this->config()->getOption('include.all', true);
182
+            $this->config()->getOption($sPluginOptionName) : $this->config()->getOption('include.all', true);
184 183
     }
185 184
 
186 185
     /**
@@ -201,7 +200,7 @@  discard block
 block discarded – undo
201 200
             $this->xConfigManager->getOption('js.lib.jq', $sChibiUrl),
202 201
             "$sJsLibUri/jaxon.core$sJsExtension",
203 202
         ];
204
-        if($this->xConfigManager->getOption('core.debug.on'))
203
+        if ($this->xConfigManager->getOption('core.debug.on'))
205 204
         {
206 205
             $sLanguage = $this->xConfigManager->getOption('core.language');
207 206
             $aJsUrls[] = "$sJsLibUri/jaxon.debug$sJsExtension";
@@ -219,8 +218,7 @@  discard block
 block discarded – undo
219 218
     private function getAssetUri(string $sAsset): string
220 219
     {
221 220
         return rtrim($this->config()->hasOption("$sAsset.uri") ?
222
-            $this->config()->getOption("$sAsset.uri") :
223
-            $this->config()->getOption('uri', ''), '/');
221
+            $this->config()->getOption("$sAsset.uri") : $this->config()->getOption('uri', ''), '/');
224 222
     }
225 223
 
226 224
     /**
@@ -231,8 +229,7 @@  discard block
 block discarded – undo
231 229
     private function getAssetDir(string $sAsset): string
232 230
     {
233 231
         return rtrim($this->config()->hasOption("$sAsset.dir") ?
234
-            $this->config()->getOption("$sAsset.dir") :
235
-            $this->config()->getOption('dir', ''), '/\/');
232
+            $this->config()->getOption("$sAsset.dir") : $this->config()->getOption('dir', ''), '/\/');
236 233
     }
237 234
 
238 235
     /**
@@ -244,8 +241,7 @@  discard block
 block discarded – undo
244 241
     private function getAssetFile(Closure $cGetHash, string $sAsset): string
245 242
     {
246 243
         return $this->config()->hasOption("$sAsset.file") ?
247
-            $this->config()->getOption("$sAsset.file") :
248
-            // Make sure to call invoke callback only if required.
244
+            $this->config()->getOption("$sAsset.file") : // Make sure to call invoke callback only if required.
249 245
             ($this->config()->hasOption("file") ?
250 246
             $this->config()->getOption("file") : $cGetHash());
251 247
     }
@@ -258,8 +254,7 @@  discard block
 block discarded – undo
258 254
     private function minifyEnabled(string $sAsset): bool
259 255
     {
260 256
         return $this->config()->hasOption("$sAsset.minify") ?
261
-            $this->config()->getOption("$sAsset.minify") :
262
-            $this->config()->getOption('minify', false);
257
+            $this->config()->getOption("$sAsset.minify") : $this->config()->getOption('minify', false);
263 258
     }
264 259
 
265 260
     /**
@@ -270,8 +265,7 @@  discard block
 block discarded – undo
270 265
     private function exportEnabled(string $sAsset): bool
271 266
     {
272 267
         return $this->config()->hasOption("$sAsset.export") ?
273
-            $this->config()->getOption("$sAsset.export") :
274
-            $this->config()->getOption('export', false);
268
+            $this->config()->getOption("$sAsset.export") : $this->config()->getOption('export', false);
275 269
     }
276 270
 
277 271
     /**
@@ -286,7 +280,7 @@  discard block
 block discarded – undo
286 280
         {
287 281
             return $xStorage->fileExists($sFilePath);
288 282
         }
289
-        catch(Throwable $e)
283
+        catch (Throwable $e)
290 284
         {
291 285
             Logger::warning("Unable to check asset file at $sFilePath.", [
292 286
                 'error' => $e->getMessage(),
@@ -309,7 +303,7 @@  discard block
 block discarded – undo
309 303
             $xStorage->write($sFilePath, $sContent);
310 304
             return true;
311 305
         }
312
-        catch(Throwable $e)
306
+        catch (Throwable $e)
313 307
         {
314 308
             Logger::warning("Unable to write to asset file at $sFilePath.", [
315 309
                 'error' => $e->getMessage(),
@@ -327,21 +321,20 @@  discard block
 block discarded – undo
327 321
      */
328 322
     private function minifyAsset(string $sAsset, string $sFilePath, string $sMinFilePath): bool
329 323
     {
330
-        if(!$this->minifyEnabled($sAsset))
324
+        if (!$this->minifyEnabled($sAsset))
331 325
         {
332 326
             return false;
333 327
         }
334 328
 
335 329
         $xStorage = $this->storage($sAsset);
336
-        if($xStorage->fileExists($sMinFilePath))
330
+        if ($xStorage->fileExists($sMinFilePath))
337 331
         {
338 332
             return true;
339 333
         }
340 334
 
341 335
         $sMinContent = $sAsset === 'js' ?
342
-            $this->xMinifier->minifyJsCode($xStorage->read($sFilePath)) :
343
-            $this->xMinifier->minifyCssCode($xStorage->read($sFilePath));
344
-        if($sMinContent === false || $sMinContent === '')
336
+            $this->xMinifier->minifyJsCode($xStorage->read($sFilePath)) : $this->xMinifier->minifyCssCode($xStorage->read($sFilePath));
337
+        if ($sMinContent === false || $sMinContent === '')
345 338
         {
346 339
             return false;
347 340
         }
@@ -352,8 +345,7 @@  discard block
 block discarded – undo
352 345
     private function getPublicUrl(string $sFilePath, string $sAsset): string
353 346
     {
354 347
         $sUri = $this->getAssetUri($sAsset);
355
-        return $sUri !== '' ? "$sUri/$sFilePath" :
356
-            $this->storage($sAsset)->publicUrl($sFilePath);
348
+        return $sUri !== '' ? "$sUri/$sFilePath" : $this->storage($sAsset)->publicUrl($sFilePath);
357 349
     }
358 350
 
359 351
     /**
@@ -370,7 +362,7 @@  discard block
 block discarded – undo
370 362
         // Check if the config options allow the file creation.
371 363
         // - The assets.js.export option must be set to true
372 364
         // - The assets.js.uri and assets.js.dir options must be set to non null values
373
-        if(!$this->exportEnabled($sAsset) ||
365
+        if (!$this->exportEnabled($sAsset) ||
374 366
             // $this->getAssetUri($sAsset) === '' ||
375 367
             $this->getAssetDir($sAsset) === '')
376 368
         {
@@ -381,7 +373,7 @@  discard block
 block discarded – undo
381 373
         $xStorage = $this->storage($sAsset);
382 374
         $sFileName = $this->getAssetFile($cGetHash, $sAsset);
383 375
         // - The assets.js.dir must be writable
384
-        if(!$sFileName || !$xStorage->directoryExists('') /*|| $xStorage->visibility('') !== 'public'*/)
376
+        if (!$sFileName || !$xStorage->directoryExists('') /*|| $xStorage->visibility('') !== 'public'*/)
385 377
         {
386 378
             return '';
387 379
         }
@@ -390,21 +382,20 @@  discard block
 block discarded – undo
390 382
         $sMinFilePath = "{$sFileName}.min.{$sAsset}";
391 383
 
392 384
         // Try to create the file and write the code, if it doesn't exist.
393
-        if(!$this->fileExists($xStorage, $sFilePath) &&
385
+        if (!$this->fileExists($xStorage, $sFilePath) &&
394 386
             !$this->writeFile($xStorage, $sFilePath, $cGetCode()))
395 387
         {
396 388
             return '';
397 389
         }
398 390
 
399
-        if(!$this->minifyEnabled($sAsset))
391
+        if (!$this->minifyEnabled($sAsset))
400 392
         {
401 393
             return $this->getPublicUrl($sFilePath, $sAsset);
402 394
         }
403 395
 
404 396
         // If the file cannot be minified, return the plain js file.
405 397
         return $this->minifyAsset($sAsset, $sFilePath, $sMinFilePath) ?
406
-            $this->getPublicUrl($sMinFilePath, $sAsset) :
407
-            $this->getPublicUrl($sFilePath, $sAsset);
398
+            $this->getPublicUrl($sMinFilePath, $sAsset) : $this->getPublicUrl($sFilePath, $sAsset);
408 399
     }
409 400
 
410 401
     /**
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Code/Code.php 2 patches
Switch Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -165,68 +165,68 @@
 block discarded – undo
165 165
                 $aCssFile = match(true) {
166 166
                     is_string($xUrl) => ['uri' => $xUrl, 'options' => []],
167 167
                     is_array($xUrl) => $xUrl,
168
-                    default => null,
169
-                };
170
-                if($aCssFile !== null)
171
-                {
172
-                    // Save the HTML tag for the file.
173
-                    $this->aCssTags[] = $renderTag($aCssFile);
174
-                }
175
-            }
176
-        }
177
-        // CSS code
178
-        if(($aCssCode = trim($xCode->code(), self::TRIM)) !== '')
179
-        {
180
-            $this->aCssCodes[] = $aCssCode;
181
-        }
182
-    }
168
+default => null,
169
+};
170
+if($aCssFile !== null)
171
+{
172
+// Save the HTML tag for the file.
173
+$this->aCssTags[] = $renderTag($aCssFile);
174
+}
175
+}
176
+}
177
+// CSS code
178
+if(($aCssCode = trim($xCode->code(), self::TRIM)) !== '')
179
+{
180
+$this->aCssCodes[] = $aCssCode;
181
+}
182
+}
183 183
 
184
-    /**
184
+/**
185 185
      * @param CodeGeneratorInterface $xCodeGenerator
186 186
      * @param Closure $renderTag
187 187
      *
188 188
      * @return void
189 189
      */
190
-    public function mergeJsCode(JsCodeGeneratorInterface $xGenerator,
191
-        Closure $renderTag, bool $bIncludeAssets): void
192
-    {
193
-        $xCode = $xGenerator->getJsCode();
194
-        if($bIncludeAssets)
195
-        {
196
-            // Javascript html tags
197
-            if(($aJsHtml = trim($xCode->html(), self::TRIM)) !== '')
198
-            {
199
-                $this->aJsTags[] = $aJsHtml;
200
-            }
201
-            // HTML tags for js
202
-            foreach($xCode->urls() as $xUrl)
203
-            {
204
-                $aJsFile = match(true) {
205
-                    is_string($xUrl) => ['uri' => $xUrl, 'options' => []],
206
-                    is_array($xUrl) => $xUrl,
207
-                    default => null,
208
-                };
209
-                if($aJsFile !== null)
210
-                {
211
-                    // Save the HTML tag for the file.
212
-                    $this->aJsTags[] = $renderTag($aJsFile);
213
-                }
214
-            }
215
-        }
216
-        // Javascript codes
217
-        if(($aJsCode = trim($xCode->code(), self::TRIM)) !== '')
218
-        {
219
-            $this->aJsCodes[] = $aJsCode;
220
-        }
221
-        // Javascript codes before the main code
222
-        if(($aJsCode = trim($xCode->before(), self::TRIM)) !== '')
223
-        {
224
-            $this->aJsCodesBefore[] = $aJsCode;
225
-        }
226
-        // Javascript codes after the main code
227
-        if(($aJsCode = trim($xCode->after(), self::TRIM)) !== '')
228
-        {
229
-            $this->aJsCodesAfter[] = $aJsCode;
230
-        }
231
-    }
190
+public function mergeJsCode(JsCodeGeneratorInterface $xGenerator,
191
+Closure $renderTag, bool $bIncludeAssets): void
192
+{
193
+$xCode = $xGenerator->getJsCode();
194
+if($bIncludeAssets)
195
+{
196
+// Javascript html tags
197
+if(($aJsHtml = trim($xCode->html(), self::TRIM)) !== '')
198
+{
199
+$this->aJsTags[] = $aJsHtml;
200
+}
201
+// HTML tags for js
202
+foreach($xCode->urls() as $xUrl)
203
+{
204
+$aJsFile = match(true) {
205
+is_string($xUrl) => ['uri' => $xUrl, 'options' => []],
206
+is_array($xUrl) => $xUrl,
207
+default => null,
208
+};
209
+if($aJsFile !== null)
210
+{
211
+// Save the HTML tag for the file.
212
+$this->aJsTags[] = $renderTag($aJsFile);
213
+}
214
+}
215
+}
216
+// Javascript codes
217
+if(($aJsCode = trim($xCode->code(), self::TRIM)) !== '')
218
+{
219
+$this->aJsCodes[] = $aJsCode;
220
+}
221
+// Javascript codes before the main code
222
+if(($aJsCode = trim($xCode->before(), self::TRIM)) !== '')
223
+{
224
+$this->aJsCodesBefore[] = $aJsCode;
225
+}
226
+// Javascript codes after the main code
227
+if(($aJsCode = trim($xCode->after(), self::TRIM)) !== '')
228
+{
229
+$this->aJsCodesAfter[] = $aJsCode;
230
+}
231
+}
232 232
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -122,21 +122,21 @@  discard block
 block discarded – undo
122 122
      */
123 123
     public function mergeCode(CodeGeneratorInterface $xGenerator, bool $bIncludeAssets): void
124 124
     {
125
-        if($bIncludeAssets)
125
+        if ($bIncludeAssets)
126 126
         {
127 127
             // HTML tags for CSS
128
-            if(($sCssTags = trim($xGenerator->getCss(), self::TRIM)) !== '')
128
+            if (($sCssTags = trim($xGenerator->getCss(), self::TRIM)) !== '')
129 129
             {
130 130
                 $this->aCssTags[] = $sCssTags;
131 131
             }
132 132
             // HTML tags for js
133
-            if(($sJsTags = trim($xGenerator->getJs(), self::TRIM)) !== '')
133
+            if (($sJsTags = trim($xGenerator->getJs(), self::TRIM)) !== '')
134 134
             {
135 135
                 $this->aJsTags[] = $sJsTags;
136 136
             }
137 137
         }
138 138
         // Javascript code
139
-        if(($sJsScript = trim($xGenerator->getScript(), self::TRIM)) !== '')
139
+        if (($sJsScript = trim($xGenerator->getScript(), self::TRIM)) !== '')
140 140
         {
141 141
             $this->aJsCodes[] = $sJsScript;
142 142
         }
@@ -152,22 +152,22 @@  discard block
 block discarded – undo
152 152
         Closure $renderTag, bool $bIncludeAssets): void
153 153
     {
154 154
         $xCode = $xGenerator->getCssCode();
155
-        if($bIncludeAssets)
155
+        if ($bIncludeAssets)
156 156
         {
157 157
             // CSS html tags
158
-            if(($aCssHtml = trim($xCode->html(), self::TRIM)) !== '')
158
+            if (($aCssHtml = trim($xCode->html(), self::TRIM)) !== '')
159 159
             {
160 160
                 $this->aCssTags[] = $aCssHtml;
161 161
             }
162 162
             // HTML tags for CSS
163
-            foreach($xCode->urls() as $xUrl)
163
+            foreach ($xCode->urls() as $xUrl)
164 164
             {
165 165
                 $aCssFile = match(true) {
166 166
                     is_string($xUrl) => ['uri' => $xUrl, 'options' => []],
167 167
                     is_array($xUrl) => $xUrl,
168 168
                     default => null,
169 169
                 };
170
-                if($aCssFile !== null)
170
+                if ($aCssFile !== null)
171 171
                 {
172 172
                     // Save the HTML tag for the file.
173 173
                     $this->aCssTags[] = $renderTag($aCssFile);
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
             }
176 176
         }
177 177
         // CSS code
178
-        if(($aCssCode = trim($xCode->code(), self::TRIM)) !== '')
178
+        if (($aCssCode = trim($xCode->code(), self::TRIM)) !== '')
179 179
         {
180 180
             $this->aCssCodes[] = $aCssCode;
181 181
         }
@@ -191,22 +191,22 @@  discard block
 block discarded – undo
191 191
         Closure $renderTag, bool $bIncludeAssets): void
192 192
     {
193 193
         $xCode = $xGenerator->getJsCode();
194
-        if($bIncludeAssets)
194
+        if ($bIncludeAssets)
195 195
         {
196 196
             // Javascript html tags
197
-            if(($aJsHtml = trim($xCode->html(), self::TRIM)) !== '')
197
+            if (($aJsHtml = trim($xCode->html(), self::TRIM)) !== '')
198 198
             {
199 199
                 $this->aJsTags[] = $aJsHtml;
200 200
             }
201 201
             // HTML tags for js
202
-            foreach($xCode->urls() as $xUrl)
202
+            foreach ($xCode->urls() as $xUrl)
203 203
             {
204 204
                 $aJsFile = match(true) {
205 205
                     is_string($xUrl) => ['uri' => $xUrl, 'options' => []],
206 206
                     is_array($xUrl) => $xUrl,
207 207
                     default => null,
208 208
                 };
209
-                if($aJsFile !== null)
209
+                if ($aJsFile !== null)
210 210
                 {
211 211
                     // Save the HTML tag for the file.
212 212
                     $this->aJsTags[] = $renderTag($aJsFile);
@@ -214,17 +214,17 @@  discard block
 block discarded – undo
214 214
             }
215 215
         }
216 216
         // Javascript codes
217
-        if(($aJsCode = trim($xCode->code(), self::TRIM)) !== '')
217
+        if (($aJsCode = trim($xCode->code(), self::TRIM)) !== '')
218 218
         {
219 219
             $this->aJsCodes[] = $aJsCode;
220 220
         }
221 221
         // Javascript codes before the main code
222
-        if(($aJsCode = trim($xCode->before(), self::TRIM)) !== '')
222
+        if (($aJsCode = trim($xCode->before(), self::TRIM)) !== '')
223 223
         {
224 224
             $this->aJsCodesBefore[] = $aJsCode;
225 225
         }
226 226
         // Javascript codes after the main code
227
-        if(($aJsCode = trim($xCode->after(), self::TRIM)) !== '')
227
+        if (($aJsCode = trim($xCode->after(), self::TRIM)) !== '')
228 228
         {
229 229
             $this->aJsCodesAfter[] = $aJsCode;
230 230
         }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/JsCode.php 1 patch
Switch Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -16,75 +16,75 @@
 block discarded – undo
16 16
 
17 17
 class JsCode
18 18
 {
19
-    /**
19
+/**
20 20
      * @param string $sCode
21 21
      * @param string $sHtml
22 22
      * @param array $aUrls
23 23
      * @param string $sCodeBefore
24 24
      * @param string $sCodeAfter
25 25
      */
26
-    public function __construct(protected string $sCode = '',
27
-        protected string $sHtml = '', protected array $aUrls = [],
28
-        protected string $sCodeBefore = '', protected string $sCodeAfter = '')
29
-    {}
26
+public function __construct(protected string $sCode = '',
27
+protected string $sHtml = '', protected array $aUrls = [],
28
+protected string $sCodeBefore = '', protected string $sCodeAfter = '')
29
+{}
30 30
 
31
-    /**
31
+/**
32 32
      * Get the javascript files to include into the page
33 33
      *
34 34
      * Each entry can be a string or an array with "uri" and "options".
35 35
      *
36 36
      * @return array
37 37
      */
38
-    public function urls(): array
39
-    {
40
-        return $this->aUrls;
41
-    }
38
+public function urls(): array
39
+{
40
+return $this->aUrls;
41
+}
42 42
 
43
-    /**
43
+/**
44 44
      * Get the javascript code to include into the page
45 45
      *
46 46
      * The code must NOT be enclosed in HTML tags.
47 47
      *
48 48
      * @return string
49 49
      */
50
-    public function code(): string
51
-    {
52
-        return $this->sCode;
53
-    }
50
+public function code(): string
51
+{
52
+return $this->sCode;
53
+}
54 54
 
55
-    /**
55
+/**
56 56
      * Get the javascript code to include into the page
57 57
      *
58 58
      * The code must be enclosed in HTML tags.
59 59
      *
60 60
      * @return string
61 61
      */
62
-    public function html(): string
63
-    {
64
-        return $this->sHtml;
65
-    }
62
+public function html(): string
63
+{
64
+return $this->sHtml;
65
+}
66 66
 
67
-    /**
67
+/**
68 68
      * Get the javascript code to be inserted inline before the main code
69 69
      *
70 70
      * The code must NOT be enclosed in HTML tags.
71 71
      *
72 72
      * @return string
73 73
      */
74
-    public function before(): string
75
-    {
76
-        return $this->sCodeBefore;
77
-    }
74
+public function before(): string
75
+{
76
+return $this->sCodeBefore;
77
+}
78 78
 
79
-    /**
79
+/**
80 80
      * Get the javascript code to be inserted inline after the main code
81 81
      *
82 82
      * The code must NOT be enclosed in HTML tags.
83 83
      *
84 84
      * @return string
85 85
      */
86
-    public function after(): string
87
-    {
88
-        return $this->sCodeAfter;
89
-    }
86
+public function after(): string
87
+{
88
+return $this->sCodeAfter;
89
+}
90 90
 }
Please login to merge, or discard this patch.