Passed
Push — main ( 5ca287...d84479 )
by Thierry
05:24
created
jaxon-core/src/Request/Handler/RequestHandler.php 2 patches
Switch Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -30,14 +30,14 @@  discard block
 block discarded – undo
30 30
 
31 31
 class RequestHandler
32 32
 {
33
-    /**
33
+/**
34 34
      * The request plugin that is able to process the current request
35 35
      *
36 36
      * @var RequestHandlerInterface
37 37
      */
38
-    private $xRequestPlugin = null;
38
+private $xRequestPlugin = null;
39 39
 
40
-    /**
40
+/**
41 41
      * The constructor
42 42
      *
43 43
      * @param Container $di
@@ -46,113 +46,113 @@  discard block
 block discarded – undo
46 46
      * @param CallbackManager $xCallbackManager
47 47
      * @param DatabagPlugin $xDatabagPlugin
48 48
      */
49
-    public function __construct(private Container $di, private PluginManager $xPluginManager,
50
-        private ResponseManager $xResponseManager, private CallbackManager $xCallbackManager,
51
-        private DatabagPlugin $xDatabagPlugin)
52
-    {}
49
+public function __construct(private Container $di, private PluginManager $xPluginManager,
50
+private ResponseManager $xResponseManager, private CallbackManager $xCallbackManager,
51
+private DatabagPlugin $xDatabagPlugin)
52
+{}
53 53
 
54
-    /**
54
+/**
55 55
      * Check if the current request can be processed
56 56
      *
57 57
      * Calls each of the request plugins and determines if the current request can be processed by one of them.
58 58
      *
59 59
      * @return bool
60 60
      */
61
-    public function canProcessRequest(): bool
62
-    {
63
-        // Return true if the request plugin was already found
64
-        if($this->xRequestPlugin !== null)
65
-        {
66
-            return true;
67
-        }
61
+public function canProcessRequest(): bool
62
+{
63
+// Return true if the request plugin was already found
64
+if($this->xRequestPlugin !== null)
65
+{
66
+return true;
67
+}
68 68
 
69
-        // The HTTP request
70
-        $xRequest = $this->di->getRequest();
69
+// The HTTP request
70
+$xRequest = $this->di->getRequest();
71 71
 
72
-        // Find a plugin to process the request
73
-        foreach($this->xPluginManager->getRequestHandlers() as $sClassName)
74
-        {
75
-            if($sClassName::canProcessRequest($xRequest))
76
-            {
77
-                $this->xRequestPlugin = $this->di->g($sClassName);
78
-                $xTarget = $this->xRequestPlugin->setTarget($xRequest);
79
-                $xTarget->setMethodArgs($this->di->getRequestArguments());
80
-                return true;
81
-            }
82
-        }
83
-        return false;
84
-    }
72
+// Find a plugin to process the request
73
+foreach($this->xPluginManager->getRequestHandlers() as $sClassName)
74
+{
75
+if($sClassName::canProcessRequest($xRequest))
76
+{
77
+    $this->xRequestPlugin = $this->di->g($sClassName);
78
+    $xTarget = $this->xRequestPlugin->setTarget($xRequest);
79
+    $xTarget->setMethodArgs($this->di->getRequestArguments());
80
+    return true;
81
+}
82
+}
83
+return false;
84
+}
85 85
 
86
-    /**
86
+/**
87 87
      * Process the current request and handle errors and exceptions.
88 88
      *
89 89
      * @return void
90 90
      * @throws RequestException
91 91
      */
92
-    private function _processRequest(): void
93
-    {
94
-        // Process the request
95
-        if($this->xRequestPlugin !== null)
96
-        {
97
-            $this->xRequestPlugin->processRequest();
98
-            // Process the databag
99
-            $this->xDatabagPlugin->writeCommand();
100
-        }
101
-    }
92
+private function _processRequest(): void
93
+{
94
+// Process the request
95
+if($this->xRequestPlugin !== null)
96
+{
97
+$this->xRequestPlugin->processRequest();
98
+// Process the databag
99
+$this->xDatabagPlugin->writeCommand();
100
+}
101
+}
102 102
 
103
-    /**
103
+/**
104 104
      * Process the current request.
105 105
      *
106 106
      * @return void
107 107
      * @throws RequestException
108 108
      */
109
-    public function processRequest(): void
110
-    {
111
-        // We need the library to have been bootstrapped.
112
-        $this->di->getBootstrap()->onBoot();
109
+public function processRequest(): void
110
+{
111
+// We need the library to have been bootstrapped.
112
+$this->di->getBootstrap()->onBoot();
113 113
 
114
-        // Check if there is a plugin to process this request
115
-        if(!$this->canProcessRequest())
116
-        {
117
-            return;
118
-        }
114
+// Check if there is a plugin to process this request
115
+if(!$this->canProcessRequest())
116
+{
117
+return;
118
+}
119 119
 
120
-        try
121
-        {
122
-            $bEndRequest = false;
123
-            // Handle before processing event
124
-            if($this->xRequestPlugin !== null)
125
-            {
126
-                $this->xCallbackManager->onBefore($this->xRequestPlugin->getTarget(), $bEndRequest);
127
-            }
128
-            if($bEndRequest)
129
-            {
130
-                return;
131
-            }
120
+try
121
+{
122
+$bEndRequest = false;
123
+// Handle before processing event
124
+if($this->xRequestPlugin !== null)
125
+{
126
+    $this->xCallbackManager->onBefore($this->xRequestPlugin->getTarget(), $bEndRequest);
127
+}
128
+if($bEndRequest)
129
+{
130
+    return;
131
+}
132 132
 
133
-            $this->_processRequest();
133
+$this->_processRequest();
134 134
 
135
-            // Handle after processing event
136
-            if($this->xRequestPlugin !== null)
137
-            {
138
-                $this->xCallbackManager->onAfter($this->xRequestPlugin->getTarget(), $bEndRequest);
139
-            }
140
-        }
141
-        // An exception was thrown while processing the request.
142
-        // The request missed the corresponding handler function,
143
-        // or an error occurred while attempting to execute the handler.
144
-        catch(RequestException $e)
145
-        {
146
-            $this->xResponseManager->error($e->getMessage());
147
-            $this->xCallbackManager->onInvalid($e);
148
-        }
149
-        catch(Exception $e)
150
-        {
151
-            $this->xResponseManager->error($e->getMessage());
152
-            $this->xCallbackManager->onError($e);
153
-        }
135
+// Handle after processing event
136
+if($this->xRequestPlugin !== null)
137
+{
138
+    $this->xCallbackManager->onAfter($this->xRequestPlugin->getTarget(), $bEndRequest);
139
+}
140
+}
141
+// An exception was thrown while processing the request.
142
+// The request missed the corresponding handler function,
143
+// or an error occurred while attempting to execute the handler.
144
+catch(RequestException $e)
145
+{
146
+$this->xResponseManager->error($e->getMessage());
147
+$this->xCallbackManager->onInvalid($e);
148
+}
149
+catch(Exception $e)
150
+{
151
+$this->xResponseManager->error($e->getMessage());
152
+$this->xCallbackManager->onError($e);
153
+}
154 154
 
155
-        // Print the debug messages
156
-        $this->xResponseManager->printDebug();
157
-    }
155
+// Print the debug messages
156
+$this->xResponseManager->printDebug();
157
+}
158 158
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     public function canProcessRequest(): bool
62 62
     {
63 63
         // Return true if the request plugin was already found
64
-        if($this->xRequestPlugin !== null)
64
+        if ($this->xRequestPlugin !== null)
65 65
         {
66 66
             return true;
67 67
         }
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
         $xRequest = $this->di->getRequest();
71 71
 
72 72
         // Find a plugin to process the request
73
-        foreach($this->xPluginManager->getRequestHandlers() as $sClassName)
73
+        foreach ($this->xPluginManager->getRequestHandlers() as $sClassName)
74 74
         {
75
-            if($sClassName::canProcessRequest($xRequest))
75
+            if ($sClassName::canProcessRequest($xRequest))
76 76
             {
77 77
                 $this->xRequestPlugin = $this->di->g($sClassName);
78 78
                 $xTarget = $this->xRequestPlugin->setTarget($xRequest);
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
     private function _processRequest(): void
93 93
     {
94 94
         // Process the request
95
-        if($this->xRequestPlugin !== null)
95
+        if ($this->xRequestPlugin !== null)
96 96
         {
97 97
             $this->xRequestPlugin->processRequest();
98 98
             // Process the databag
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         $this->di->getBootstrap()->onBoot();
113 113
 
114 114
         // Check if there is a plugin to process this request
115
-        if(!$this->canProcessRequest())
115
+        if (!$this->canProcessRequest())
116 116
         {
117 117
             return;
118 118
         }
@@ -121,11 +121,11 @@  discard block
 block discarded – undo
121 121
         {
122 122
             $bEndRequest = false;
123 123
             // Handle before processing event
124
-            if($this->xRequestPlugin !== null)
124
+            if ($this->xRequestPlugin !== null)
125 125
             {
126 126
                 $this->xCallbackManager->onBefore($this->xRequestPlugin->getTarget(), $bEndRequest);
127 127
             }
128
-            if($bEndRequest)
128
+            if ($bEndRequest)
129 129
             {
130 130
                 return;
131 131
             }
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
             $this->_processRequest();
134 134
 
135 135
             // Handle after processing event
136
-            if($this->xRequestPlugin !== null)
136
+            if ($this->xRequestPlugin !== null)
137 137
             {
138 138
                 $this->xCallbackManager->onAfter($this->xRequestPlugin->getTarget(), $bEndRequest);
139 139
             }
@@ -141,12 +141,12 @@  discard block
 block discarded – undo
141 141
         // An exception was thrown while processing the request.
142 142
         // The request missed the corresponding handler function,
143 143
         // or an error occurred while attempting to execute the handler.
144
-        catch(RequestException $e)
144
+        catch (RequestException $e)
145 145
         {
146 146
             $this->xResponseManager->error($e->getMessage());
147 147
             $this->xCallbackManager->onInvalid($e);
148 148
         }
149
-        catch(Exception $e)
149
+        catch (Exception $e)
150 150
         {
151 151
             $this->xResponseManager->error($e->getMessage());
152 152
             $this->xCallbackManager->onError($e);
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->option('core.request.uri') ?: $this->xParameterReader->uri();
56
-        $aOptions = [
57
-            'sResponseType'      => 'JSON',
58
-            'sVersion'           => $this->option('core.version'),
59
-            'sLanguage'          => $this->option('core.language'),
60
-            'sRequestURI'        => $sUri,
61
-            'sDefaultMode'       => $this->option('core.request.mode'),
62
-            'sDefaultMethod'     => $this->option('core.request.method'),
63
-            'sCsrfMetaName'      => $this->option('core.request.csrf_meta'),
64
-            'bLoggingEnabled'    => $this->xConfigManager->loggingEnabled(),
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->option('core.request.uri') ?: $this->xParameterReader->uri();
56
+$aOptions = [
57
+'sResponseType'      => 'JSON',
58
+'sVersion'           => $this->option('core.version'),
59
+'sLanguage'          => $this->option('core.language'),
60
+'sRequestURI'        => $sUri,
61
+'sDefaultMode'       => $this->option('core.request.mode'),
62
+'sDefaultMethod'     => $this->option('core.request.method'),
63
+'sCsrfMetaName'      => $this->option('core.request.csrf_meta'),
64
+'bLoggingEnabled'    => $this->xConfigManager->loggingEnabled(),
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 $xCodeGenerator
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 2 patches
Switch Indentation   +207 added lines, -207 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 bool
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,39 +107,39 @@  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(fn($sClassName) =>
137
-            $this->getCodeGenerator($sClassName)->getHash(), $this->aCodeGenerators);
138
-        $aHashes[] = $this->sVersion;
139
-        return md5(implode('', $aHashes));
140
-    }
141
-
142
-    /**
134
+public function getHash(): string
135
+{
136
+$aHashes = array_map(fn($sClassName) =>
137
+$this->getCodeGenerator($sClassName)->getHash(), $this->aCodeGenerators);
138
+$aHashes[] = $this->sVersion;
139
+return md5(implode('', $aHashes));
140
+}
141
+
142
+/**
143 143
      * Render a template in the 'plugins' subdir
144 144
      *
145 145
      * @param string $sTemplate    The template filename
@@ -147,185 +147,185 @@  discard block
 block discarded – undo
147 147
      *
148 148
      * @return string
149 149
      */
150
-    private function render(string $sTemplate, array $aVars = []): string
151
-    {
152
-        $aVars['sJsOptions'] = $this->sJsOptions;
153
-        return $this->xTemplateEngine->render("jaxon::plugins/$sTemplate", $aVars);
154
-    }
150
+private function render(string $sTemplate, array $aVars = []): string
151
+{
152
+$aVars['sJsOptions'] = $this->sJsOptions;
153
+return $this->xTemplateEngine->render("jaxon::plugins/$sTemplate", $aVars);
154
+}
155 155
 
156
-    /**
156
+/**
157 157
      * Generate the Jaxon CSS and js codes for a given plugin
158 158
      *
159 159
      * @param CodeGeneratorInterface $xGenerator
160 160
      *
161 161
      * @return void
162 162
      */
163
-    private function generatePluginCodes(CodeGeneratorInterface $xGenerator): void
164
-    {
165
-        if(!is_subclass_of($xGenerator, AbstractPlugin::class) ||
166
-            $this->xAssetManager->shallIncludeAssets($xGenerator))
167
-        {
168
-            // HTML tags for CSS
169
-            if(($sCss = trim($xGenerator->getCss(), " \n")) !== '')
170
-            {
171
-                $this->aCss[] = $sCss;
172
-            }
173
-            // HTML tags for js
174
-            if(($sJs = trim($xGenerator->getJs(), " \n")) !== '')
175
-            {
176
-                $this->aJs[] = $sJs;
177
-            }
178
-        }
179
-
180
-        // Additional js codes
181
-        if(($xJsCode = $xGenerator->getJsCode()) !== null)
182
-        {
183
-            if(($sJs = trim($xJsCode->sJs, " \n")) !== '')
184
-            {
185
-                $this->aCodeJs[] = $sJs;
186
-            }
187
-            if(($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '')
188
-            {
189
-                $this->aCodeJsBefore[] = $sJsBefore;
190
-            }
191
-            if(($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '')
192
-            {
193
-                $this->aCodeJsAfter[] = $sJsAfter;
194
-            }
195
-            $this->aCodeJsFiles = array_merge($this->aCodeJsFiles, $xJsCode->aFiles);
196
-        }
197
-    }
198
-
199
-    /**
163
+private function generatePluginCodes(CodeGeneratorInterface $xGenerator): void
164
+{
165
+if(!is_subclass_of($xGenerator, AbstractPlugin::class) ||
166
+$this->xAssetManager->shallIncludeAssets($xGenerator))
167
+{
168
+// HTML tags for CSS
169
+if(($sCss = trim($xGenerator->getCss(), " \n")) !== '')
170
+{
171
+    $this->aCss[] = $sCss;
172
+}
173
+// HTML tags for js
174
+if(($sJs = trim($xGenerator->getJs(), " \n")) !== '')
175
+{
176
+    $this->aJs[] = $sJs;
177
+}
178
+}
179
+
180
+// Additional js codes
181
+if(($xJsCode = $xGenerator->getJsCode()) !== null)
182
+{
183
+if(($sJs = trim($xJsCode->sJs, " \n")) !== '')
184
+{
185
+    $this->aCodeJs[] = $sJs;
186
+}
187
+if(($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '')
188
+{
189
+    $this->aCodeJsBefore[] = $sJsBefore;
190
+}
191
+if(($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '')
192
+{
193
+    $this->aCodeJsAfter[] = $sJsAfter;
194
+}
195
+$this->aCodeJsFiles = array_merge($this->aCodeJsFiles, $xJsCode->aFiles);
196
+}
197
+}
198
+
199
+/**
200 200
      * Generate the Jaxon CSS ans js codes
201 201
      *
202 202
      * @return void
203 203
      * @throws UriException
204 204
      */
205
-    private function generateCodes(): void
206
-    {
207
-        if($this->bGenerated)
208
-        {
209
-            return;
210
-        }
211
-
212
-        // We need the library to have been bootstrapped.
213
-        $this->di->getBootstrap()->onBoot();
214
-
215
-        // Sort the code generators by ascending priority
216
-        ksort($this->aCodeGenerators);
217
-
218
-        // Cannot be injected because of dependency loop.
219
-        $this->xAssetManager = $this->di->getAssetManager();
220
-
221
-        $this->sJsOptions = $this->xAssetManager->getJsOptions();
222
-        foreach($this->aCodeGenerators as $sClassName)
223
-        {
224
-            $this->generatePluginCodes($this->getCodeGenerator($sClassName));
225
-        }
226
-
227
-        // Load the Jaxon lib js files, after the other libs js files.
228
-        $this->aJs[] = trim($this->render('includes.js', [
229
-            'aUrls' => $this->xAssetManager->getJsLibFiles(),
230
-        ]));
231
-
232
-        // The codes are already generated.
233
-        $this->bGenerated = true;
234
-    }
235
-
236
-    /**
205
+private function generateCodes(): void
206
+{
207
+if($this->bGenerated)
208
+{
209
+return;
210
+}
211
+
212
+// We need the library to have been bootstrapped.
213
+$this->di->getBootstrap()->onBoot();
214
+
215
+// Sort the code generators by ascending priority
216
+ksort($this->aCodeGenerators);
217
+
218
+// Cannot be injected because of dependency loop.
219
+$this->xAssetManager = $this->di->getAssetManager();
220
+
221
+$this->sJsOptions = $this->xAssetManager->getJsOptions();
222
+foreach($this->aCodeGenerators as $sClassName)
223
+{
224
+$this->generatePluginCodes($this->getCodeGenerator($sClassName));
225
+}
226
+
227
+// Load the Jaxon lib js files, after the other libs js files.
228
+$this->aJs[] = trim($this->render('includes.js', [
229
+'aUrls' => $this->xAssetManager->getJsLibFiles(),
230
+]));
231
+
232
+// The codes are already generated.
233
+$this->bGenerated = true;
234
+}
235
+
236
+/**
237 237
      * Get the HTML tags to include Jaxon CSS code and files into the page
238 238
      *
239 239
      * @return string
240 240
      * @throws UriException
241 241
      */
242
-    public function getCss(): string
243
-    {
244
-        $this->generateCodes();
245
-        return implode("\n\n", $this->aCss);
246
-    }
242
+public function getCss(): string
243
+{
244
+$this->generateCodes();
245
+return implode("\n\n", $this->aCss);
246
+}
247 247
 
248
-    /**
248
+/**
249 249
      * Get the HTML tags to include Jaxon javascript files into the page
250 250
      *
251 251
      * @return string
252 252
      * @throws UriException
253 253
      */
254
-    public function getJs(): string
255
-    {
256
-        $this->generateCodes();
257
-        return implode("\n\n", $this->aJs);
258
-    }
254
+public function getJs(): string
255
+{
256
+$this->generateCodes();
257
+return implode("\n\n", $this->aJs);
258
+}
259 259
 
260
-    /**
260
+/**
261 261
      * Get the Javascript code
262 262
      *
263 263
      * @return string
264 264
      */
265
-    public function getJsScript(): string
266
-    {
267
-        $aJsScripts = [];
268
-        foreach($this->aCodeGenerators as $sClassName)
269
-        {
270
-            $xGenerator = $this->getCodeGenerator($sClassName);
271
-            // Javascript code
272
-            if(($sJsScript = trim($xGenerator->getScript(), " \n")) !== '')
273
-            {
274
-                $aJsScripts[] = $sJsScript;
275
-            }
276
-        }
277
-        return implode("\n\n", $aJsScripts);
278
-    }
279
-
280
-    /**
265
+public function getJsScript(): string
266
+{
267
+$aJsScripts = [];
268
+foreach($this->aCodeGenerators as $sClassName)
269
+{
270
+$xGenerator = $this->getCodeGenerator($sClassName);
271
+// Javascript code
272
+if(($sJsScript = trim($xGenerator->getScript(), " \n")) !== '')
273
+{
274
+    $aJsScripts[] = $sJsScript;
275
+}
276
+}
277
+return implode("\n\n", $aJsScripts);
278
+}
279
+
280
+/**
281 281
      * @param bool $bIncludeJs Also get the JS files
282 282
      * @param bool $bIncludeCss Also get the CSS files
283 283
      *
284 284
      * @return array<string>
285 285
      */
286
-    private function renderCodes(bool $bIncludeJs, bool $bIncludeCss): array
287
-    {
288
-        $aCodes = [];
289
-        if($bIncludeCss)
290
-        {
291
-            $aCodes[] = $this->getCss();
292
-        }
293
-        if($bIncludeJs)
294
-        {
295
-            $aCodes[] = $this->getJs();
296
-        }
297
-
298
-        $sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' :
299
-            $this->xAssetManager->createJsFiles($this);
300
-        // Wrap the js code into the corresponding HTML tag.
301
-        $aCodes[] = $sUrl !== '' ?
302
-            $this->render('include.js', ['sUrl' => $sUrl]) :
303
-            $this->render('wrapper.js', ['sScript' => $this->getJsScript()]);
304
-
305
-        // Wrap the js codes into HTML tags.
306
-        if(count($this->aCodeJsBefore) > 0)
307
-        {
308
-            $sScript = implode("\n\n", $this->aCodeJsBefore);
309
-            $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]);
310
-        }
311
-        if(count($this->aCodeJs) > 0)
312
-        {
313
-            $sScript = implode("\n\n", $this->aCodeJs);
314
-            $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]);
315
-        }
316
-        if(count($this->aCodeJsFiles) > 0)
317
-        {
318
-            $aCodes[] = $this->render('includes.js', ['aUrls' => $this->aCodeJsFiles]);
319
-        }
320
-        if(count($this->aCodeJsAfter) > 0)
321
-        {
322
-            $sScript = implode("\n\n", $this->aCodeJsAfter);
323
-            $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]);
324
-        }
325
-        return $aCodes;
326
-    }
327
-
328
-    /**
286
+private function renderCodes(bool $bIncludeJs, bool $bIncludeCss): array
287
+{
288
+$aCodes = [];
289
+if($bIncludeCss)
290
+{
291
+$aCodes[] = $this->getCss();
292
+}
293
+if($bIncludeJs)
294
+{
295
+$aCodes[] = $this->getJs();
296
+}
297
+
298
+$sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' :
299
+$this->xAssetManager->createJsFiles($this);
300
+// Wrap the js code into the corresponding HTML tag.
301
+$aCodes[] = $sUrl !== '' ?
302
+$this->render('include.js', ['sUrl' => $sUrl]) :
303
+$this->render('wrapper.js', ['sScript' => $this->getJsScript()]);
304
+
305
+// Wrap the js codes into HTML tags.
306
+if(count($this->aCodeJsBefore) > 0)
307
+{
308
+$sScript = implode("\n\n", $this->aCodeJsBefore);
309
+$aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]);
310
+}
311
+if(count($this->aCodeJs) > 0)
312
+{
313
+$sScript = implode("\n\n", $this->aCodeJs);
314
+$aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]);
315
+}
316
+if(count($this->aCodeJsFiles) > 0)
317
+{
318
+$aCodes[] = $this->render('includes.js', ['aUrls' => $this->aCodeJsFiles]);
319
+}
320
+if(count($this->aCodeJsAfter) > 0)
321
+{
322
+$sScript = implode("\n\n", $this->aCodeJsAfter);
323
+$aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]);
324
+}
325
+return $aCodes;
326
+}
327
+
328
+/**
329 329
      * Get the javascript code to be sent to the browser
330 330
      *
331 331
      * @param bool $bIncludeJs Also get the JS files
@@ -334,10 +334,10 @@  discard block
 block discarded – undo
334 334
      * @return string
335 335
      * @throws UriException
336 336
      */
337
-    public function getScript(bool $bIncludeJs, bool $bIncludeCss): string
338
-    {
339
-        $this->generateCodes();
340
-        $aCodes = $this->renderCodes($bIncludeJs, $bIncludeCss);
341
-        return implode("\n\n", $aCodes);
342
-    }
337
+public function getScript(bool $bIncludeJs, bool $bIncludeCss): string
338
+{
339
+$this->generateCodes();
340
+$aCodes = $this->renderCodes($bIncludeJs, $bIncludeCss);
341
+return implode("\n\n", $aCodes);
342
+}
343 343
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -22 removed lines patch added patch discarded remove patch
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
      */
110 110
     public function addCodeGenerator(string $sClassName, int $nPriority): void
111 111
     {
112
-        while(isset($this->aCodeGenerators[$nPriority]))
112
+        while (isset($this->aCodeGenerators[$nPriority]))
113 113
         {
114 114
             $nPriority++;
115 115
         }
@@ -162,33 +162,33 @@  discard block
 block discarded – undo
162 162
      */
163 163
     private function generatePluginCodes(CodeGeneratorInterface $xGenerator): void
164 164
     {
165
-        if(!is_subclass_of($xGenerator, AbstractPlugin::class) ||
165
+        if (!is_subclass_of($xGenerator, AbstractPlugin::class) ||
166 166
             $this->xAssetManager->shallIncludeAssets($xGenerator))
167 167
         {
168 168
             // HTML tags for CSS
169
-            if(($sCss = trim($xGenerator->getCss(), " \n")) !== '')
169
+            if (($sCss = trim($xGenerator->getCss(), " \n")) !== '')
170 170
             {
171 171
                 $this->aCss[] = $sCss;
172 172
             }
173 173
             // HTML tags for js
174
-            if(($sJs = trim($xGenerator->getJs(), " \n")) !== '')
174
+            if (($sJs = trim($xGenerator->getJs(), " \n")) !== '')
175 175
             {
176 176
                 $this->aJs[] = $sJs;
177 177
             }
178 178
         }
179 179
 
180 180
         // Additional js codes
181
-        if(($xJsCode = $xGenerator->getJsCode()) !== null)
181
+        if (($xJsCode = $xGenerator->getJsCode()) !== null)
182 182
         {
183
-            if(($sJs = trim($xJsCode->sJs, " \n")) !== '')
183
+            if (($sJs = trim($xJsCode->sJs, " \n")) !== '')
184 184
             {
185 185
                 $this->aCodeJs[] = $sJs;
186 186
             }
187
-            if(($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '')
187
+            if (($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '')
188 188
             {
189 189
                 $this->aCodeJsBefore[] = $sJsBefore;
190 190
             }
191
-            if(($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '')
191
+            if (($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '')
192 192
             {
193 193
                 $this->aCodeJsAfter[] = $sJsAfter;
194 194
             }
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
      */
205 205
     private function generateCodes(): void
206 206
     {
207
-        if($this->bGenerated)
207
+        if ($this->bGenerated)
208 208
         {
209 209
             return;
210 210
         }
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
         $this->xAssetManager = $this->di->getAssetManager();
220 220
 
221 221
         $this->sJsOptions = $this->xAssetManager->getJsOptions();
222
-        foreach($this->aCodeGenerators as $sClassName)
222
+        foreach ($this->aCodeGenerators as $sClassName)
223 223
         {
224 224
             $this->generatePluginCodes($this->getCodeGenerator($sClassName));
225 225
         }
@@ -265,11 +265,11 @@  discard block
 block discarded – undo
265 265
     public function getJsScript(): string
266 266
     {
267 267
         $aJsScripts = [];
268
-        foreach($this->aCodeGenerators as $sClassName)
268
+        foreach ($this->aCodeGenerators as $sClassName)
269 269
         {
270 270
             $xGenerator = $this->getCodeGenerator($sClassName);
271 271
             // Javascript code
272
-            if(($sJsScript = trim($xGenerator->getScript(), " \n")) !== '')
272
+            if (($sJsScript = trim($xGenerator->getScript(), " \n")) !== '')
273 273
             {
274 274
                 $aJsScripts[] = $sJsScript;
275 275
             }
@@ -286,38 +286,36 @@  discard block
 block discarded – undo
286 286
     private function renderCodes(bool $bIncludeJs, bool $bIncludeCss): array
287 287
     {
288 288
         $aCodes = [];
289
-        if($bIncludeCss)
289
+        if ($bIncludeCss)
290 290
         {
291 291
             $aCodes[] = $this->getCss();
292 292
         }
293
-        if($bIncludeJs)
293
+        if ($bIncludeJs)
294 294
         {
295 295
             $aCodes[] = $this->getJs();
296 296
         }
297 297
 
298
-        $sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' :
299
-            $this->xAssetManager->createJsFiles($this);
298
+        $sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' : $this->xAssetManager->createJsFiles($this);
300 299
         // Wrap the js code into the corresponding HTML tag.
301 300
         $aCodes[] = $sUrl !== '' ?
302
-            $this->render('include.js', ['sUrl' => $sUrl]) :
303
-            $this->render('wrapper.js', ['sScript' => $this->getJsScript()]);
301
+            $this->render('include.js', ['sUrl' => $sUrl]) : $this->render('wrapper.js', ['sScript' => $this->getJsScript()]);
304 302
 
305 303
         // Wrap the js codes into HTML tags.
306
-        if(count($this->aCodeJsBefore) > 0)
304
+        if (count($this->aCodeJsBefore) > 0)
307 305
         {
308 306
             $sScript = implode("\n\n", $this->aCodeJsBefore);
309 307
             $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]);
310 308
         }
311
-        if(count($this->aCodeJs) > 0)
309
+        if (count($this->aCodeJs) > 0)
312 310
         {
313 311
             $sScript = implode("\n\n", $this->aCodeJs);
314 312
             $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]);
315 313
         }
316
-        if(count($this->aCodeJsFiles) > 0)
314
+        if (count($this->aCodeJsFiles) > 0)
317 315
         {
318 316
             $aCodes[] = $this->render('includes.js', ['aUrls' => $this->aCodeJsFiles]);
319 317
         }
320
-        if(count($this->aCodeJsAfter) > 0)
318
+        if (count($this->aCodeJsAfter) > 0)
321 319
         {
322 320
             $sScript = implode("\n\n", $this->aCodeJsAfter);
323 321
             $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]);
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Request/CallableClass/CallableClassPlugin.php 1 patch
Spacing   +15 added lines, -17 removed lines patch added patch discarded remove patch
@@ -82,15 +82,15 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function checkOptions(string $sCallable, $xOptions): array
84 84
     {
85
-        if(!$this->xValidator->validateClass(trim($sCallable)))
85
+        if (!$this->xValidator->validateClass(trim($sCallable)))
86 86
         {
87 87
             throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration'));
88 88
         }
89
-        if(is_string($xOptions))
89
+        if (is_string($xOptions))
90 90
         {
91 91
             $xOptions = ['include' => $xOptions];
92 92
         }
93
-        elseif(!is_array($xOptions))
93
+        elseif (!is_array($xOptions))
94 94
         {
95 95
             throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration'));
96 96
         }
@@ -135,15 +135,15 @@  discard block
 block discarded – undo
135 135
     private function addCallable(CallableObject $xCallableObject): void
136 136
     {
137 137
         $aCallableMethods = $xCallableObject->getCallableMethods();
138
-        if($xCallableObject->excluded() || count($aCallableMethods) === 0)
138
+        if ($xCallableObject->excluded() || count($aCallableMethods) === 0)
139 139
         {
140 140
             return;
141 141
         }
142 142
 
143 143
         $aCallableObject = &$this->aCallableObjects;
144
-        foreach(explode('.', $xCallableObject->getJsName()) as $sName)
144
+        foreach (explode('.', $xCallableObject->getJsName()) as $sName)
145 145
         {
146
-            if(!isset($aCallableObject['children'][$sName]))
146
+            if (!isset($aCallableObject['children'][$sName]))
147 147
             {
148 148
                 $aCallableObject['children'][$sName] = [];
149 149
             }
@@ -161,12 +161,11 @@  discard block
 block discarded – undo
161 161
     private function renderMethod(string $sIndent, array $aTemplateVars): string
162 162
     {
163 163
         $aOptions = [];
164
-        foreach($aTemplateVars['aMethod']['options'] as $sKey => $sValue)
164
+        foreach ($aTemplateVars['aMethod']['options'] as $sKey => $sValue)
165 165
         {
166 166
             $aOptions[] = "$sKey: $sValue";
167 167
         }
168
-        $aTemplateVars['sArguments'] = count($aOptions) === 0 ? 'args' :
169
-            'args, { ' . implode(',', $aOptions) . ' }';
168
+        $aTemplateVars['sArguments'] = count($aOptions) === 0 ? 'args' : 'args, { ' . implode(',', $aOptions) . ' }';
170 169
 
171 170
         return $sIndent . trim($this->xTemplateEngine
172 171
             ->render('jaxon::callables/method.js', $aTemplateVars));
@@ -186,11 +185,10 @@  discard block
 block discarded – undo
186 185
 
187 186
         $fMethodCallback = fn($aMethod) => $this->renderMethod($sIndent,
188 187
             ['sJsClass' => $sJsClass, 'aMethod' => $aMethod]);
189
-        $aMethods = !isset($aCallable['methods']) ? [] :
190
-            array_map($fMethodCallback, $aCallable['methods']);
188
+        $aMethods = !isset($aCallable['methods']) ? [] : array_map($fMethodCallback, $aCallable['methods']);
191 189
 
192 190
         $aChildren = [];
193
-        foreach($aCallable['children'] ?? [] as $sName => $aChild)
191
+        foreach ($aCallable['children'] ?? [] as $sName => $aChild)
194 192
         {
195 193
             $aChildren[] = $this->renderChild("$sName:", "$sJsClass.$sName",
196 194
                 $aChild, $nRepeat) . ',';
@@ -231,13 +229,13 @@  discard block
 block discarded – undo
231 229
         $this->xRegistry->registerAllComponents();
232 230
 
233 231
         $this->aCallableObjects = ['children' => []];
234
-        foreach($this->cdi->getCallableObjects() as $xCallableObject)
232
+        foreach ($this->cdi->getCallableObjects() as $xCallableObject)
235 233
         {
236 234
             $this->addCallable($xCallableObject);
237 235
         }
238 236
 
239 237
         $aScripts = [];
240
-        foreach($this->aCallableObjects['children'] as $sJsClass => $aCallable)
238
+        foreach ($this->aCallableObjects['children'] as $sJsClass => $aCallable)
241 239
         {
242 240
             $aScripts[] = $this->renderChild("{$this->sPrefix}$sJsClass =",
243 241
                 $sJsClass, $aCallable) . ';';
@@ -293,7 +291,7 @@  discard block
 block discarded – undo
293 291
         // Will be used to print a translated error message.
294 292
         $aErrorParams = ['class' => $sClassName, 'method' => $sMethodName];
295 293
 
296
-        if(!$this->xValidator->validateJsObject($sClassName) ||
294
+        if (!$this->xValidator->validateJsObject($sClassName) ||
297 295
             !$this->xValidator->validateMethod($sMethodName))
298 296
         {
299 297
             // Unable to find the requested object or method
@@ -307,7 +305,7 @@  discard block
 block discarded – undo
307 305
             /** @var CallableObject */
308 306
             $xCallableObject = $this->getCallable($sClassName);
309 307
 
310
-            if($xCallableObject->excluded($sMethodName))
308
+            if ($xCallableObject->excluded($sMethodName))
311 309
             {
312 310
                 // Unable to find the requested class or method
313 311
                 $this->throwException('', 'errors.objects.excluded', $aErrorParams);
@@ -316,7 +314,7 @@  discard block
 block discarded – undo
316 314
             $sError = 'errors.objects.call';
317 315
             $xCallableObject->call($this->xTarget);
318 316
         }
319
-        catch(ReflectionException|SetupException $e)
317
+        catch (ReflectionException|SetupException $e)
320 318
         {
321 319
             // Unable to execute the requested class or method
322 320
             $this->throwException($e->getMessage(), $sError, $aErrorParams);
Please login to merge, or discard this patch.
jaxon-core/templates/plugins/config.js.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -10,24 +10,24 @@
 block discarded – undo
10 10
 jxn.config.defaultMethod = '<?php echo $this->sDefaultMethod ?>';
11 11
 jxn.config.responseType = '<?php echo $this->sResponseType ?>';
12 12
 
13
-<?php if($this->nResponseQueueSize > 0): ?>
13
+<?php if ($this->nResponseQueueSize > 0): ?>
14 14
 jxn.config.responseQueueSize = <?php echo $this->nResponseQueueSize ?>;
15 15
 <?php endif ?>
16 16
 
17
-<?php if($this->bLoggingEnabled): ?>
17
+<?php if ($this->bLoggingEnabled): ?>
18 18
 jxn.debug.logger = '<?php echo Jaxon\rq(Jaxon\App\Component\Logger::class)->_class() ?>';
19 19
 <?php endif ?>
20 20
 
21
-<?php if($this->bDebug): ?>
21
+<?php if ($this->bDebug): ?>
22 22
 jxn.debug.active = true;
23
-<?php if($this->sDebugOutputID): ?>
23
+<?php if ($this->sDebugOutputID): ?>
24 24
 jxn.debug.outputID = '<?php echo $this->sDebugOutputID ?>';
25 25
 <?php endif ?>
26
-<?php if($this->bVerboseDebug): ?>
26
+<?php if ($this->bVerboseDebug): ?>
27 27
 jxn.debug.verbose.active = true;
28 28
 <?php endif ?>
29 29
 <?php endif ?>
30 30
 
31
-<?php if($this->sCsrfMetaName): ?>
31
+<?php if ($this->sCsrfMetaName): ?>
32 32
 jxn.setCsrf('<?php echo $this->sCsrfMetaName ?>');
33 33
 <?php endif ?>
Please login to merge, or discard this patch.