Passed
Push — main ( 938a8d...3607b0 )
by Thierry
03:58
created
jaxon-core/src/Plugin/Code/ConfigScriptGenerator.php 1 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/AssetManager.php 1 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/Code/CodeGenerator.php 1 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/JsCode.php 1 patch
Switch Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -16,31 +16,31 @@
 block discarded – undo
16 16
 
17 17
 class JsCode
18 18
 {
19
-    /**
19
+/**
20 20
      * The main javascript code
21 21
      *
22 22
      * @var string
23 23
      */
24
-    public $sJs = '';
24
+public $sJs = '';
25 25
 
26
-    /**
26
+/**
27 27
      * The js files
28 28
      *
29 29
      * @var array
30 30
      */
31
-    public $aFiles = [];
31
+public $aFiles = [];
32 32
 
33
-    /**
33
+/**
34 34
      * The javascript code to be inserted inline before the main code
35 35
      *
36 36
      * @var string
37 37
      */
38
-    public $sJsBefore = '';
38
+public $sJsBefore = '';
39 39
 
40
-    /**
40
+/**
41 41
      * The javascript code to be inserted inline after the main code
42 42
      *
43 43
      * @var string
44 44
      */
45
-    public $sJsAfter = '';
45
+public $sJsAfter = '';
46 46
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Code/ReadyScriptGenerator.php 1 patch
Switch Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -18,11 +18,11 @@
 block discarded – undo
18 18
 
19 19
 class ReadyScriptGenerator extends AbstractCodeGenerator
20 20
 {
21
-    /**
21
+/**
22 22
      * @inheritDoc
23 23
      */
24
-    public function getScript(): string
25
-    {
26
-        return "jaxon.dom.ready(() => jaxon.processCustomAttrs());";
27
-    }
24
+public function getScript(): string
25
+{
26
+return "jaxon.dom.ready(() => jaxon.processCustomAttrs());";
27
+}
28 28
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Code/MinifierInterface.php 1 patch
Switch Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 interface MinifierInterface
6 6
 {
7
-    /**
7
+/**
8 8
      * Minify javascript code
9 9
      *
10 10
      * @param string $sJsFile The javascript file to be minified
@@ -12,5 +12,5 @@  discard block
 block discarded – undo
12 12
      *
13 13
      * @return bool
14 14
      */
15
-    public function minify(string $sJsFile, string $sMinFile): bool;
15
+public function minify(string $sJsFile, string $sMinFile): bool;
16 16
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Response/Pagination/PaginatorPlugin.php 1 patch
Switch Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -43,60 +43,60 @@  discard block
 block discarded – undo
43 43
  */
44 44
 class PaginatorPlugin extends AbstractResponsePlugin
45 45
 {
46
-    /**
46
+/**
47 47
      * @const The plugin name
48 48
      */
49
-    public const NAME = 'pg';
49
+public const NAME = 'pg';
50 50
 
51
-    /**
51
+/**
52 52
      * The constructor.
53 53
      *
54 54
      * @param RendererInterface $xRenderer
55 55
      */
56
-    public function __construct(protected RendererInterface $xRenderer)
57
-    {}
56
+public function __construct(protected RendererInterface $xRenderer)
57
+{}
58 58
 
59
-    /**
59
+/**
60 60
      * @inheritDoc
61 61
      */
62
-    public function getName(): string
63
-    {
64
-        return self::NAME;
65
-    }
62
+public function getName(): string
63
+{
64
+return self::NAME;
65
+}
66 66
 
67
-    /**
67
+/**
68 68
      * @inheritDoc
69 69
      */
70
-    public function getHash(): string
71
-    {
72
-        return '5.0.0'; // Use the version number as hash
73
-    }
70
+public function getHash(): string
71
+{
72
+return '5.0.0'; // Use the version number as hash
73
+}
74 74
 
75
-    /**
75
+/**
76 76
      * @inheritDoc
77 77
      */
78
-    public function getCss(): string
79
-    {
80
-        return '
78
+public function getCss(): string
79
+{
80
+return '
81 81
 <style>
82 82
   .pagination li a {
83 83
     cursor: pointer;
84 84
   }
85 85
 </style>
86 86
 ';
87
-    }
87
+}
88 88
 
89
-    /**
89
+/**
90 90
      * Get the view renderer
91 91
      *
92 92
      * @return RendererInterface
93 93
      */
94
-    public function renderer(): RendererInterface
95
-    {
96
-        return $this->xRenderer;
97
-    }
94
+public function renderer(): RendererInterface
95
+{
96
+return $this->xRenderer;
97
+}
98 98
 
99
-    /**
99
+/**
100 100
      * Create a paginator
101 101
      *
102 102
      * @param int $nPageNumber     The current page number
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
      *
106 106
      * @return Paginator
107 107
      */
108
-    public function paginator(int $nPageNumber, int $nItemsPerPage, int $nTotalItems): Paginator
109
-    {
110
-        return new Paginator($this, $nPageNumber, $nItemsPerPage, $nTotalItems);
111
-    }
108
+public function paginator(int $nPageNumber, int $nItemsPerPage, int $nTotalItems): Paginator
109
+{
110
+return new Paginator($this, $nPageNumber, $nItemsPerPage, $nTotalItems);
111
+}
112 112
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Response/Script/ScriptPlugin.php 1 patch
Switch Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -26,56 +26,56 @@  discard block
 block discarded – undo
26 26
 
27 27
 class ScriptPlugin extends AbstractResponsePlugin
28 28
 {
29
-    /**
29
+/**
30 30
      * @const The plugin name
31 31
      */
32
-    public const NAME = 'script';
32
+public const NAME = 'script';
33 33
 
34
-    /**
34
+/**
35 35
      * The class constructor
36 36
      *
37 37
      * @param CallFactory $xFactory
38 38
      */
39
-    public function __construct(private CallFactory $xFactory)
40
-    {}
39
+public function __construct(private CallFactory $xFactory)
40
+{}
41 41
 
42
-    /**
42
+/**
43 43
      * @return Closure
44 44
      */
45
-    private function getCallback(): Closure
46
-    {
47
-        // The closure needs to capture the response object the script plugin is called with.
48
-        $xResponse = $this->response();
49
-        return function(JsExpr $xJsExpr) use($xResponse) {
50
-            // Add the newly created expression to the response
51
-            $aOptions = [
52
-                'expr' => $xJsExpr,
53
-                'context' => is_a($xResponse, NodeResponse::class) ?
54
-                    ['component' => true] : [],
55
-            ];
56
-            $xResponse->addCommand('script.exec.expr', $aOptions)
57
-                ->setOption('plugin', $this->getName());
58
-        };
59
-    }
45
+private function getCallback(): Closure
46
+{
47
+// The closure needs to capture the response object the script plugin is called with.
48
+$xResponse = $this->response();
49
+return function(JsExpr $xJsExpr) use($xResponse) {
50
+// Add the newly created expression to the response
51
+$aOptions = [
52
+    'expr' => $xJsExpr,
53
+    'context' => is_a($xResponse, NodeResponse::class) ?
54
+        ['component' => true] : [],
55
+];
56
+$xResponse->addCommand('script.exec.expr', $aOptions)
57
+    ->setOption('plugin', $this->getName());
58
+};
59
+}
60 60
 
61
-    /**
61
+/**
62 62
      * @inheritDoc
63 63
      */
64
-    public function getName(): string
65
-    {
66
-        return self::NAME;
67
-    }
64
+public function getName(): string
65
+{
66
+return self::NAME;
67
+}
68 68
 
69
-    /**
69
+/**
70 70
      * @inheritDoc
71 71
      */
72
-    public function getHash(): string
73
-    {
74
-        // Use the version number as hash
75
-        return '5.0.0';
76
-    }
72
+public function getHash(): string
73
+{
74
+// Use the version number as hash
75
+return '5.0.0';
76
+}
77 77
 
78
-    /**
78
+/**
79 79
      * Create a JQuery selector expression, and link it to the current response.
80 80
      *
81 81
      * @param string $sPath    The jQuery selector path
@@ -83,32 +83,32 @@  discard block
 block discarded – undo
83 83
      *
84 84
      * @return JqSelectorCall
85 85
      */
86
-    public function jq(string $sPath = '', $xContext = null): JqSelectorCall
87
-    {
88
-        return $this->xFactory->jq($sPath, $xContext, $this->getCallback());
89
-    }
86
+public function jq(string $sPath = '', $xContext = null): JqSelectorCall
87
+{
88
+return $this->xFactory->jq($sPath, $xContext, $this->getCallback());
89
+}
90 90
 
91
-    /**
91
+/**
92 92
      * Create a Javascript object expression, and link it to the current response.
93 93
      *
94 94
      * @param string $sObject
95 95
      *
96 96
      * @return JsObjectCall
97 97
      */
98
-    public function jo(string $sObject = ''): JsObjectCall
99
-    {
100
-        return $this->xFactory->jo($sObject, $this->getCallback());
101
-    }
98
+public function jo(string $sObject = ''): JsObjectCall
99
+{
100
+return $this->xFactory->jo($sObject, $this->getCallback());
101
+}
102 102
 
103
-    /**
103
+/**
104 104
      * Create a Javascript element selector expression, and link it to the current response.
105 105
      *
106 106
      * @param string $sElementId
107 107
      *
108 108
      * @return JsSelectorCall
109 109
      */
110
-    public function je(string $sElementId = ''): JsSelectorCall
111
-    {
112
-        return $this->xFactory->je($sElementId, $this->getCallback());
113
-    }
110
+public function je(string $sElementId = ''): JsSelectorCall
111
+{
112
+return $this->xFactory->je($sElementId, $this->getCallback());
113
+}
114 114
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Response/Dialog/DialogPlugin.php 1 patch
Switch Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -24,107 +24,107 @@
 block discarded – undo
24 24
 
25 25
 class DialogPlugin implements PluginInterface, ResponsePluginInterface, ModalInterface, AlertInterface
26 26
 {
27
-    use ResponsePluginTrait;
27
+use ResponsePluginTrait;
28 28
 
29
-    /**
29
+/**
30 30
      * @const The plugin name
31 31
      */
32
-    public const NAME = 'dialog';
32
+public const NAME = 'dialog';
33 33
 
34
-    /**
34
+/**
35 35
      * The constructor
36 36
      *
37 37
      * @param DialogCommand $xDialogCommand
38 38
      */
39
-    public function __construct(private DialogCommand $xDialogCommand)
40
-    {}
39
+public function __construct(private DialogCommand $xDialogCommand)
40
+{}
41 41
 
42
-    /**
42
+/**
43 43
      * @inheritDoc
44 44
      */
45
-    public function getName(): string
46
-    {
47
-        return self::NAME;
48
-    }
45
+public function getName(): string
46
+{
47
+return self::NAME;
48
+}
49 49
 
50
-    /**
50
+/**
51 51
      * Initialize the plugin
52 52
      *
53 53
      * @return void
54 54
      */
55
-    protected function init(): void
56
-    {}
55
+protected function init(): void
56
+{}
57 57
 
58
-    /**
58
+/**
59 59
      * Set the library to use for the next call.
60 60
      *
61 61
      * @param string $sLibrary The name of the library
62 62
      *
63 63
      * @return DialogPlugin
64 64
      */
65
-    public function with(string $sLibrary): DialogPlugin
66
-    {
67
-        $this->xDialogCommand->library($sLibrary);
68
-        return $this;
69
-    }
65
+public function with(string $sLibrary): DialogPlugin
66
+{
67
+$this->xDialogCommand->library($sLibrary);
68
+return $this;
69
+}
70 70
 
71
-    /**
71
+/**
72 72
      * @inheritDoc
73 73
      */
74
-    public function show(string $sTitle, string $sContent, array $aButtons = [], array $aOptions = []): void
75
-    {
76
-        // Show the modal dialog
77
-        $this->addCommand('dialog.modal.show',
78
-            $this->xDialogCommand->show($sTitle, $sContent, $aButtons, $aOptions));
79
-    }
80
-
81
-    /**
74
+public function show(string $sTitle, string $sContent, array $aButtons = [], array $aOptions = []): void
75
+{
76
+// Show the modal dialog
77
+$this->addCommand('dialog.modal.show',
78
+$this->xDialogCommand->show($sTitle, $sContent, $aButtons, $aOptions));
79
+}
80
+
81
+/**
82 82
      * @inheritDoc
83 83
      */
84
-    public function hide(): void
85
-    {
86
-        // Hide the modal dialog
87
-        $this->addCommand('dialog.modal.hide', $this->xDialogCommand->hide());
88
-    }
84
+public function hide(): void
85
+{
86
+// Hide the modal dialog
87
+$this->addCommand('dialog.modal.hide', $this->xDialogCommand->hide());
88
+}
89 89
 
90
-    /**
90
+/**
91 91
      * @inheritDoc
92 92
      */
93
-    public function title(string $sTitle): AlertInterface
94
-    {
95
-        $this->xDialogCommand->title($sTitle);
96
-        return $this;
97
-    }
93
+public function title(string $sTitle): AlertInterface
94
+{
95
+$this->xDialogCommand->title($sTitle);
96
+return $this;
97
+}
98 98
 
99
-    /**
99
+/**
100 100
      * @inheritDoc
101 101
      */
102
-    public function success(string $sMessage, ...$aArgs): void
103
-    {
104
-        $this->addCommand('dialog.alert.show', $this->xDialogCommand->success($sMessage, $aArgs));
105
-    }
102
+public function success(string $sMessage, ...$aArgs): void
103
+{
104
+$this->addCommand('dialog.alert.show', $this->xDialogCommand->success($sMessage, $aArgs));
105
+}
106 106
 
107
-    /**
107
+/**
108 108
      * @inheritDoc
109 109
      */
110
-    public function info(string $sMessage, ...$aArgs): void
111
-    {
112
-        $this->addCommand('dialog.alert.show', $this->xDialogCommand->info($sMessage, $aArgs));
113
-    }
110
+public function info(string $sMessage, ...$aArgs): void
111
+{
112
+$this->addCommand('dialog.alert.show', $this->xDialogCommand->info($sMessage, $aArgs));
113
+}
114 114
 
115
-    /**
115
+/**
116 116
      * @inheritDoc
117 117
      */
118
-    public function warning(string $sMessage, ...$aArgs): void
119
-    {
120
-        $this->addCommand('dialog.alert.show', $this->xDialogCommand->warning($sMessage, $aArgs));
121
-    }
118
+public function warning(string $sMessage, ...$aArgs): void
119
+{
120
+$this->addCommand('dialog.alert.show', $this->xDialogCommand->warning($sMessage, $aArgs));
121
+}
122 122
 
123
-    /**
123
+/**
124 124
      * @inheritDoc
125 125
      */
126
-    public function error(string $sMessage, ...$aArgs): void
127
-    {
128
-        $this->addCommand('dialog.alert.show', $this->xDialogCommand->error($sMessage, $aArgs));
129
-    }
126
+public function error(string $sMessage, ...$aArgs): void
127
+{
128
+$this->addCommand('dialog.alert.show', $this->xDialogCommand->error($sMessage, $aArgs));
129
+}
130 130
 }
Please login to merge, or discard this patch.