Passed
Push — main ( 7f530d...7aae9b )
by Thierry
05:54
created
jaxon-core/src/App/View/TemplateView.php 1 patch
Switch Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -18,22 +18,22 @@  discard block
 block discarded – undo
18 18
 
19 19
 class TemplateView implements ViewInterface
20 20
 {
21
-    /**
21
+/**
22 22
      * The Jaxon template engine
23 23
      *
24 24
      * @var TemplateEngine
25 25
      */
26
-    protected $xTemplateEngine;
26
+protected $xTemplateEngine;
27 27
 
28
-    /**
28
+/**
29 29
      * The class constructor
30 30
      */
31
-    public function __construct(TemplateEngine $xTemplateEngine)
32
-    {
33
-        $this->xTemplateEngine = $xTemplateEngine;
34
-    }
31
+public function __construct(TemplateEngine $xTemplateEngine)
32
+{
33
+$this->xTemplateEngine = $xTemplateEngine;
34
+}
35 35
 
36
-    /**
36
+/**
37 37
      * Add a namespace to this view renderer
38 38
      *
39 39
      * @param string $sNamespace    The namespace name
@@ -42,28 +42,28 @@  discard block
 block discarded – undo
42 42
      *
43 43
      * @return void
44 44
      */
45
-    public function addNamespace(string $sNamespace, string $sDirectory, string $sExtension = ''): void
46
-    {
47
-        $this->xTemplateEngine->addNamespace($sNamespace, $sDirectory, $sExtension);
48
-    }
45
+public function addNamespace(string $sNamespace, string $sDirectory, string $sExtension = ''): void
46
+{
47
+$this->xTemplateEngine->addNamespace($sNamespace, $sDirectory, $sExtension);
48
+}
49 49
 
50
-    /**
50
+/**
51 51
      * Render a view
52 52
      *
53 53
      * @param Store $store    A store populated with the view data
54 54
      *
55 55
      * @return string        The string representation of the view
56 56
      */
57
-    public function render(Store $store): string
58
-    {
59
-        $sViewName = $store->getViewName();
60
-        $sNamespace = $store->getNamespace();
61
-        // In this view renderer, the namespace must always be prepended to the view name.
62
-        if(substr($sViewName, 0, strlen($sNamespace) + 2) != $sNamespace . '::')
63
-        {
64
-            $sViewName = $sNamespace . '::' . $sViewName;
65
-        }
66
-        // Render the template
67
-        return trim($this->xTemplateEngine->render($sViewName, $store->getViewData()), " \t\n");
68
-    }
57
+public function render(Store $store): string
58
+{
59
+$sViewName = $store->getViewName();
60
+$sNamespace = $store->getNamespace();
61
+// In this view renderer, the namespace must always be prepended to the view name.
62
+if(substr($sViewName, 0, strlen($sNamespace) + 2) != $sNamespace . '::')
63
+{
64
+$sViewName = $sNamespace . '::' . $sViewName;
65
+}
66
+// Render the template
67
+return trim($this->xTemplateEngine->render($sViewName, $store->getViewData()), " \t\n");
68
+}
69 69
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/ResponsePluginInterface.php 1 patch
Switch Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -6,17 +6,17 @@
 block discarded – undo
6 6
 
7 7
 interface ResponsePluginInterface
8 8
 {
9
-    /**
9
+/**
10 10
      * Get the attached response
11 11
      *
12 12
      * @return AbstractResponse|null
13 13
      */
14
-    public function response(): ?AbstractResponse;
14
+public function response(): ?AbstractResponse;
15 15
 
16
-    /**
16
+/**
17 17
      * @param AbstractResponse $xResponse   The response
18 18
      *
19 19
      * @return static
20 20
      */
21
-    public function initPlugin(AbstractResponse $xResponse): static;
21
+public function initPlugin(AbstractResponse $xResponse): static;
22 22
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/CallableRegistryInterface.php 1 patch
Switch Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 interface CallableRegistryInterface
6 6
 {
7
-    /**
7
+/**
8 8
      * Check if the provided options are correct, and convert them into an array.
9 9
      *
10 10
      * @param string $sCallable
@@ -12,9 +12,9 @@  discard block
 block discarded – undo
12 12
      *
13 13
      * @return array
14 14
      */
15
-    public function checkOptions(string $sCallable, $xOptions): array;
15
+public function checkOptions(string $sCallable, $xOptions): array;
16 16
 
17
-    /**
17
+/**
18 18
      * Register a callable entity: a function or a class.
19 19
      *
20 20
      * Called by the <Jaxon\Plugin\RequestManager> when a user script
@@ -27,14 +27,14 @@  discard block
 block discarded – undo
27 27
      *
28 28
      * @return bool
29 29
      */
30
-    public function register(string $sType, string $sCallable, array $aOptions): bool;
30
+public function register(string $sType, string $sCallable, array $aOptions): bool;
31 31
 
32
-    /**
32
+/**
33 33
      * Get the callable object for a registered item
34 34
      *
35 35
      * @param string $sCallable
36 36
      *
37 37
      * @return mixed
38 38
      */
39
-    public function getCallable(string $sCallable): mixed;
39
+public function getCallable(string $sCallable): mixed;
40 40
 }
Please login to merge, or discard this patch.
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.