Passed
Branch develop (4dde40)
by Thierry
05:11
created

JsCommands::confirm()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Js.php - Provides javascript related commands for the Response
5
 *
6
 * @author Thierry Feuzeu <[email protected]>
7
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
8
 * @link https://github.com/jaxon-php/jaxon-core
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
10
11
namespace Jaxon\Response\Features;
12
13
trait JsCommands
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait JsCommands
Loading history...
14
{
15
    /**
16
     * Add a response command to the array of commands that will be sent to the browser
17
     *
18
     * @param array         $aAttributes        Associative array of attributes that will describe the command
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 8 found
Loading history...
19
     * @param mixed            $mData                The data to be associated with this command
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 12 found
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter name; 16 found
Loading history...
20
     *
21
     * @return Response
22
     */
23
    abstract public function addCommand(array $aAttributes, $mData);
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
24
25
    /**
26
     * Add a response command to the array of commands that will be sent to the browser
27
     *
28
     * @param string        $sName              The command name
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter name; 14 found
Loading history...
29
     * @param array         $aAttributes        Associative array of attributes that will describe the command
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 8 found
Loading history...
30
     * @param mixed         $mData              The data to be associated with this command
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter name; 14 found
Loading history...
31
     * @param boolean       $bRemoveEmpty       If true, remove empty attributes
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 7 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 7 found
Loading history...
32
     *
33
     * @return Response
34
     */
35
    abstract protected function _addCommand($sName, array $aAttributes, $mData, $bRemoveEmpty = false);
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
36
37
    /**
38
     * Merge the response commands from the specified <Response> object with
39
     * the response commands in this <Response> object
40
     *
41
     * @param Response|array    $mCommands          The <Response> object
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 4 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 10 found
Loading history...
42
     * @param boolean           $bBefore            Add the new commands to the beginning of the list
0 ignored issues
show
Coding Style introduced by
Expected 8 spaces after parameter type; 11 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 12 found
Loading history...
43
     *
44
     * @return void
45
     */
46
    abstract public function appendResponse($mCommands, $bBefore = false);
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
47
48
    /**
49
     * Response command that prompts user with [ok] [cancel] style message box
50
     *
51
     * If the user clicks cancel, the specified number of response commands
52
     * following this one, will be skipped.
53
     *
54
     * @param integer       $iCommandCount      The number of commands to skip upon cancel
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 7 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 6 found
Loading history...
55
     * @param string        $sMessage           The message to display to the user
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter name; 11 found
Loading history...
56
     *
57
     * @return Response
58
     */
59
    public function confirmCommands($iCommandCount, $sMessage)
60
    {
61
        $aAttributes = ['count' => $iCommandCount];
62
        return $this->_addCommand('cc', $aAttributes, $sMessage);
63
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
64
65
    /**
66
     * Response command that prompts user with [ok] [cancel] style message box
67
     *
68
     * If the user clicks cancel, the specified number of response commands
69
     * following this one, will be skipped.
70
     *
71
     * @param string        $sMessage           The message to display to the user
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 11 found
Loading history...
72
     * @param callable      $xCallable          The function
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 6 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 10 found
Loading history...
73
     *
74
     * @return Response
0 ignored issues
show
Documentation introduced by
Should the return type not be JsCommands?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
75
     */
76
    public function confirm($sMessage, $xCallable)
77
    {
78
        $xResponse = jaxon()->newResponse();
79
        \call_user_func($xCallable, $xResponse);
80
        $iCommandCount = $xResponse->getCommandCount();
81
        if($iCommandCount > 0)
82
        {
83
            $this->confirmCommands($iCommandCount, $sMessage);
84
            $this->appendResponse($xResponse);
0 ignored issues
show
Documentation introduced by
$xResponse is of type object<Jaxon\Response\Response>, but the function expects a object<Jaxon\Response\Features\Response>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
85
        }
86
        return $this;
87
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
88
89
    /**
90
     * Add a command to display an alert message to the user
91
     *
92
     * @param string        $sMessage            The message to be displayed
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
93
     *
94
     * @return Response
95
     */
96
    public function alert($sMessage)
97
    {
98
        return $this->_addCommand('al', [], $sMessage);
99
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
100
101
    /**
102
     * Add a command to display a debug message to the user
103
     *
104
     * @param string        $sMessage            The message to be displayed
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
105
     *
106
     * @return Response
107
     */
108
    public function debug($sMessage)
109
    {
110
        return $this->_addCommand('dbg', [], $sMessage);
111
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
112
113
    /**
114
     * Add a command to ask the browser to navigate to the specified URL
115
     *
116
     * @param string        $sURL                The relative or fully qualified URL
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 16 found
Loading history...
117
     * @param integer        $iDelay                Number of seconds to delay before the redirect occurs
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 16 found
Loading history...
118
     *
119
     * @return Response
120
     */
121
    public function redirect($sURL, $iDelay = 0)
122
    {
123
        // we need to parse the query part so that the values are rawurlencode()'ed
124
        // can't just use parse_url() cos we could be dealing with a relative URL which
125
        // parse_url() can't deal with.
126
        $queryStart = strpos($sURL, '?', strrpos($sURL, '/'));
127
        if($queryStart !== false)
128
        {
129
            $queryStart++;
130
            $queryEnd = strpos($sURL, '#', $queryStart);
131
            if($queryEnd === false)
132
            {
133
                $queryEnd = strlen($sURL);
134
            }
135
            $queryPart = substr($sURL, $queryStart, $queryEnd - $queryStart);
136
            parse_str($queryPart, $queryParts);
137
            $newQueryPart = "";
138
            if($queryParts)
139
            {
140
                $first = true;
141
                foreach($queryParts as $key => $value)
142
                {
143
                    if($first)
144
                    {
145
                        $first = false;
146
                    }
147
                    else
148
                    {
149
                        $newQueryPart .= '&';
150
                    }
151
                    $newQueryPart .= rawurlencode($key) . '=' . rawurlencode($value);
152
                }
153
            }
154
            elseif($_SERVER['QUERY_STRING'])
155
            {
156
                //couldn't break up the query, but there's one there
157
                //possibly "http://url/page.html?query1234" type of query?
158
                //just encode it and hope it works
159
                $newQueryPart = rawurlencode($_SERVER['QUERY_STRING']);
160
            }
161
            $sURL = str_replace($queryPart, $newQueryPart, $sURL);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $sURL. This often makes code more readable.
Loading history...
162
        }
163
164
        if($iDelay > 0)
165
        {
166
            return $this->script('window.setTimeout("window.location = \'' . $sURL . '\';",' . ($iDelay * 1000) . ');');
167
        }
168
        return $this->script('window.location = "' . $sURL . '";');
169
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
170
171
    /**
172
     * Add a command to execute a portion of javascript on the browser
173
     *
174
     * The script runs in it's own context, so variables declared locally, using the 'var' keyword,
175
     * will no longer be available after the call.
176
     * To construct a variable that will be accessable globally, even after the script has executed,
177
     * leave off the 'var' keyword.
178
     *
179
     * @param string        $sJS                The script to execute
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 16 found
Loading history...
180
     *
181
     * @return Response
182
     */
183
    public function script($sJS)
184
    {
185
        return $this->_addCommand('js', [], $sJS);
186
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
187
188
    /**
189
     * Add a command to call the specified javascript function with the given (optional) parameters
190
     *
191
     * @param string        $sFunc                The name of the function to call
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 16 found
Loading history...
192
     *
193
     * @return Response
194
     */
195
    public function call($sFunc)
196
    {
197
        $aArgs = func_get_args();
198
        array_shift($aArgs);
199
        $aAttributes = ['cmd' => 'jc', 'func' => $sFunc];
200
        return $this->addCommand($aAttributes, $aArgs);
201
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
202
203
    /**
204
     * Add a command to set an event handler on the browser
205
     *
206
     * @param string        $sTarget            The id of the element that contains the event
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
207
     * @param string        $sEvent             The name of the event
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 13 found
Loading history...
208
     * @param string        $sScript            The javascript to execute when the event is fired
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
209
     *
210
     * @return Response
211
     */
212
    public function setEvent($sTarget, $sEvent, $sScript)
213
    {
214
        $aAttributes = [
215
            'id' => $sTarget,
216
            'prop' => $sEvent
217
        ];
218
        return $this->_addCommand('ev', $aAttributes, $sScript);
219
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
220
221
    /**
222
     * Add a command to set a click handler on the browser
223
     *
224
     * @param string        $sTarget            The id of the element that contains the event
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
225
     * @param string        $sScript            The javascript to execute when the event is fired
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
226
     *
227
     * @return Response
228
     */
229
    public function onClick($sTarget, $sScript)
230
    {
231
        return $this->setEvent($sTarget, 'onclick', $sScript);
232
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
233
234
    /**
235
     * Add a command to install an event handler on the specified element
236
     *
237
     * You can add more than one event handler to an element's event using this method.
238
     *
239
     * @param string        $sTarget             The id of the element
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 13 found
Loading history...
240
     * @param string        $sEvent              The name of the event
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 14 found
Loading history...
241
     * @param string        $sHandler            The name of the javascript function to call when the event is fired
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
242
     *
243
     * @return Response
244
     */
245
    public function addHandler($sTarget, $sEvent, $sHandler)
246
    {
247
        $aAttributes = [
248
            'id' => $sTarget,
249
            'prop' => $sEvent
250
        ];
251
        return $this->_addCommand('ah', $aAttributes, $sHandler);
252
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
253
254
    /**
255
     * Add a command to remove an event handler from an element
256
     *
257
     * @param string        $sTarget             The id of the element
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 13 found
Loading history...
258
     * @param string        $sEvent              The name of the event
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 14 found
Loading history...
259
     * @param string        $sHandler            The name of the javascript function called when the event is fired
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
260
     *
261
     * @return Response
262
     */
263
    public function removeHandler($sTarget, $sEvent, $sHandler)
264
    {
265
        $aAttributes = [
266
            'id' => $sTarget,
267
            'prop' => $sEvent
268
        ];
269
        return $this->_addCommand('rh', $aAttributes, $sHandler);
270
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
271
272
    /**
273
     * Add a command to construct a javascript function on the browser
274
     *
275
     * @param string        $sFunction            The name of the function to construct
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
276
     * @param string        $sArgs                Comma separated list of parameter names
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter name; 16 found
Loading history...
277
     * @param string        $sScript            The javascript code that will become the body of the function
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 12 found
Loading history...
278
     *
279
     * @return Response
280
     */
281
    public function setFunction($sFunction, $sArgs, $sScript)
282
    {
283
        $aAttributes = [
284
            'func' => $sFunction,
285
            'prop' => $sArgs
286
        ];
287
        return $this->_addCommand('sf', $aAttributes, $sScript);
288
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
289
290
    /**
291
     * Add a command to construct a wrapper function around an existing javascript function on the browser
292
     *
293
     * @param string        $sFunction            The name of the existing function to wrap
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter name; 12 found
Loading history...
294
     * @param string        $sArgs                The comma separated list of parameters for the function
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 11 spaces after parameter name; 16 found
Loading history...
295
     * @param array            $aScripts            An array of javascript code snippets that will be used to build
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 12 found
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter name; 12 found
Loading history...
296
     *                                             the body of the function
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 46 spaces but found 45
Loading history...
297
     *                                             The first piece of code specified in the array will occur before
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 46 spaces but found 45
Loading history...
298
     *                                             the call to the original function, the second will occur after
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 46 spaces but found 45
Loading history...
299
     *                                             the original function is called.
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 46 spaces but found 45
Loading history...
300
     * @param string        $sReturnValueVar    The name of the variable that will retain the return value
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
301
     *                                             from the call to the original function
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 42 spaces but found 45
Loading history...
302
     *
303
     * @return Response
304
     */
305
    public function wrapFunction($sFunction, $sArgs, $aScripts, $sReturnValueVar)
306
    {
307
        $aAttributes = [
308
            'cmd' => 'wpf',
309
            'func' => $sFunction,
310
            'prop' => $sArgs,
311
            'type' => $sReturnValueVar
312
        ];
313
        return $this->addCommand($aAttributes, $aScripts);
314
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
315
316
    /**
317
     * Add a command to load a javascript file on the browser
318
     *
319
     * @param boolean       $bIncludeOnce         Include once or not
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 7 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 9 found
Loading history...
320
     * @param string        $sFileName            The relative or fully qualified URI of the javascript file
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter name; 12 found
Loading history...
321
     * @param string        $sType                Determines the script type. Defaults to 'text/javascript'
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter name; 16 found
Loading history...
322
     * @param string        $sId                  The wrapper id
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter name; 18 found
Loading history...
323
     *
324
     * @return Response
325
     */
326
    private function _includeScript($bIncludeOnce, $sFileName, $sType, $sId)
327
    {
328
        $aAttributes = [
329
            'type' => $sType,
330
            'elm_id' => $sId
331
        ];
332
        return $this->_addCommand(($bIncludeOnce ? 'ino' : 'in'), $aAttributes, $sFileName, true);
333
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
334
335
    /**
336
     * Add a command to load a javascript file on the browser
337
     *
338
     * @param string        $sFileName            The relative or fully qualified URI of the javascript file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
339
     * @param string        $sType                Determines the script type. Defaults to 'text/javascript'
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter name; 16 found
Loading history...
340
     * @param string        $sId                  The wrapper id
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter name; 18 found
Loading history...
341
     *
342
     * @return Response
343
     */
344
    public function includeScript($sFileName, $sType = '', $sId = '')
345
    {
346
        return $this->_includeScript(false, $sFileName, $sType, $sId);
347
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
348
349
    /**
350
     * Add a command to include a javascript file on the browser if it has not already been loaded
351
     *
352
     * @param string        $sFileName            The relative or fully qualified URI of the javascript file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
353
     * @param string        $sType                Determines the script type. Defaults to 'text/javascript'
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter name; 16 found
Loading history...
354
     * @param string        $sId                  The wrapper id
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter name; 18 found
Loading history...
355
     *
356
     * @return Response
357
     */
358
    public function includeScriptOnce($sFileName, $sType = '', $sId = '')
359
    {
360
        return $this->_includeScript(true, $sFileName, $sType, $sId);
361
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
362
363
    /**
364
     * Add a command to remove a SCRIPT reference to a javascript file on the browser
365
     *
366
     * Optionally, you can call a javascript function just prior to the file being unloaded (for cleanup).
367
     *
368
     * @param string        $sFileName            The relative or fully qualified URI of the javascript file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
369
     * @param string        $sUnload            Name of a javascript function to call prior to unlaoding the file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 12 found
Loading history...
370
     *
371
     * @return Response
372
     */
373
    public function removeScript($sFileName, $sUnload = '')
374
    {
375
        $aAttributes = ['unld' => $sUnload];
376
        return $this->_addCommand('rjs', $aAttributes, $sFileName, true);
377
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
378
379
    /**
380
     * Add a command to include a LINK reference to the specified CSS file on the browser.
381
     *
382
     * This will cause the browser to load and apply the style sheet.
383
     *
384
     * @param string        $sFileName            The relative or fully qualified URI of the css file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
385
     * @param string        $sMedia                The media type of the CSS file. Defaults to 'screen'
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter name; 16 found
Loading history...
386
     *
387
     * @return Response
388
     */
389
    public function includeCSS($sFileName, $sMedia = '')
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
390
    {
391
        $aAttributes = ['media' => $sMedia];
392
        return $this->_addCommand('css', $aAttributes, $sFileName, true);
393
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
394
395
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $sMedia should have a doc-comment as per coding-style.
Loading history...
396
     * Add a command to remove a LINK reference to a CSS file on the browser
397
     *
398
     * This causes the browser to unload the style sheet, effectively removing the style changes it caused.
399
     *
400
     * @param string        $sFileName            The relative or fully qualified URI of the css file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
401
     *
402
     * @return Response
403
     */
404
    public function removeCSS($sFileName, $sMedia = '')
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
405
    {
406
        $aAttributes = ['media' => $sMedia];
407
        return $this->_addCommand('rcss', $aAttributes, $sFileName, true);
408
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
409
410
    /**
411
     * Add a command to make Jaxon pause while the CSS files are loaded
412
     *
413
     * The browser is not typically a multi-threading application, with regards to javascript code.
414
     * Therefore, the CSS files included or removed with <Response->includeCSS> and
415
     * <Response->removeCSS> respectively, will not be loaded or removed until the browser regains
416
     * control from the script.
417
     * This command returns control back to the browser and pauses the execution of the response
418
     * until the CSS files, included previously, are loaded.
419
     *
420
     * @param integer        $iTimeout            The number of 1/10ths of a second to pause before timing out
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
421
     *                                             and continuing with the execution of the response commands
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 44 spaces but found 45
Loading history...
422
     *
423
     * @return Response
424
     */
425
    public function waitForCSS($iTimeout = 600)
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
426
    {
427
        $aAttributes = ['cmd' => 'wcss', 'prop' => $iTimeout];
428
        return $this->addCommand($aAttributes, '');
429
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
430
431
    /**
432
     * Add a command to make Jaxon to delay execution of the response commands until a specified condition is met
433
     *
434
     * Note, this returns control to the browser, so that other script operations can execute.
435
     * Jaxon will continue to monitor the specified condition and, when it evaluates to true,
436
     * will continue processing response commands.
437
     *
438
     * @param string        $script                A piece of javascript code that evaulates to true or false
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 16 found
Loading history...
439
     * @param integer        $tenths                The number of 1/10ths of a second to wait before timing out
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 16 found
Loading history...
440
     *                                             and continuing with the execution of the response commands.
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 46 spaces but found 45
Loading history...
441
     *
442
     * @return Response
443
     */
444
    public function waitFor($script, $tenths)
445
    {
446
        $aAttributes = ['cmd' => 'wf', 'prop' => $tenths];
447
        return $this->addCommand($aAttributes, $script);
448
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
449
450
    /**
451
     * Add a command to make Jaxon to pause execution of the response commands,
452
     * returning control to the browser so it can perform other commands asynchronously.
453
     *
454
     * After the specified delay, Jaxon will continue execution of the response commands.
455
     *
456
     * @param integer        $tenths                The number of 1/10ths of a second to sleep
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 16 found
Loading history...
457
     *
458
     * @return Response
459
     */
460
    public function sleep($tenths)
461
    {
462
        $aAttributes = ['cmd' =>'s', 'prop' => $tenths];
0 ignored issues
show
Coding Style introduced by
Expected 1 space after "=>"; 0 found
Loading history...
463
        return $this->addCommand($aAttributes, '');
464
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
465
}
466