Issues (2884)

src/Response/ResponseInterface.php (1 issue)

1
<?php
2
3
namespace Jaxon\Response;
4
5
use Jaxon\Plugin\ResponsePlugin;
6
use Psr\Http\Message\ResponseInterface as PsrResponseInterface;
7
8
interface ResponseInterface
9
{
10
    /**
11
     * Get the content type, which is always set to 'text/json'
12
     *
13
     * @return string
14
     */
15
    public function getContentType(): string;
16
17
    /**
18
     * Get the commands in the response
19
     *
20
     * @return array
21
     */
22
    public function getCommands(): array;
23
24
    /**
25
     * Get the number of commands in the response
26
     *
27
     * @return int
28
     */
29
    public function getCommandCount(): int;
30
31
    /**
32
     * Clear all the commands already added to the response
33
     *
34
     * @return void
35
     */
36
    public function clearCommands();
37
38
    /**
39
     * Merge the commands with those in this <Response> object
40
     *
41
     * @param array $aCommands    The commands to merge
42
     * @param bool $bBefore    Add the new commands to the beginning of the list
43
     *
44
     * @return void
45
     */
46
    public function appendCommands(array $aCommands, bool $bBefore = false);
47
48
    /**
49
     * Merge the response commands with those in this <Response> object
50
     *
51
     * @param ResponseInterface    The <Response> object
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
52
     * @param bool $bBefore    Add the new commands to the beginning of the list
53
     *
54
     * @return void
55
     */
56
    public function appendResponse(ResponseInterface $xResponse, bool $bBefore = false);
57
58
    /**
59
     * Return the output, generated from the commands added to the response, that will be sent to the browser
60
     *
61
     * @return string
62
     */
63
    public function getOutput(): string;
64
65
    /**
66
     * Add a response command that is generated by a plugin
67
     *
68
     * @param ResponsePlugin $xPlugin    The plugin object
69
     * @param array $aAttributes    The attributes for this response command
70
     * @param mixed $mData    The data to be sent with this command
71
     *
72
     * @return ResponseInterface
73
     */
74
    public function addPluginCommand(ResponsePlugin $xPlugin, array $aAttributes, $mData): ResponseInterface;
75
76
    /**
77
     * Convert this response to a PSR7 response object
78
     *
79
     * @return PsrResponseInterface
80
     */
81
    public function toPsr(): PsrResponseInterface;
82
83
    /**
84
     * Add a command to assign the specified value to the given element's attribute
85
     *
86
     * @param string $sTarget    The id of the html element on the browser
87
     * @param string $sAttribute    The attribute to be assigned
88
     * @param string $sData    The value to be assigned to the attribute
89
     *
90
     * @return ResponseInterface
91
     */
92
    public function assign(string $sTarget, string $sAttribute, string $sData): ResponseInterface;
93
94
    /**
95
     * Add a command to assign the specified HTML content to the given element
96
     *
97
     * This is a shortcut for assign() on the innerHTML attribute.
98
     *
99
     * @param string $sTarget    The id of the html element on the browser
100
     * @param string $sData    The value to be assigned to the attribute
101
     *
102
     * @return ResponseInterface
103
     */
104
    public function html(string $sTarget, string $sData): ResponseInterface;
105
106
    /**
107
     * Add a command to append the specified data to the given element's attribute
108
     *
109
     * @param string $sTarget    The id of the element to be updated
110
     * @param string $sAttribute    The name of the attribute to be appended to
111
     * @param string $sData    The data to be appended to the attribute
112
     *
113
     * @return ResponseInterface
114
     */
115
    public function append(string $sTarget, string $sAttribute, string $sData): ResponseInterface;
116
117
    /**
118
     * Add a command to prepend the specified data to the given element's attribute
119
     *
120
     * @param string $sTarget    The id of the element to be updated
121
     * @param string $sAttribute    The name of the attribute to be prepended to
122
     * @param string $sData    The value to be prepended to the attribute
123
     *
124
     * @return ResponseInterface
125
     */
126
    public function prepend(string $sTarget, string $sAttribute, string $sData): ResponseInterface;
127
128
    /**
129
     * Add a command to replace a specified value with another value within the given element's attribute
130
     *
131
     * @param string $sTarget    The id of the element to update
132
     * @param string $sAttribute    The attribute to be updated
133
     * @param string $sSearch    The needle to search for
134
     * @param string $sData    The data to use in place of the needle
135
     *
136
     * @return ResponseInterface
137
     */
138
    public function replace(string $sTarget, string $sAttribute, string $sSearch, string $sData): ResponseInterface;
139
140
    /**
141
     * Add a command to clear the specified attribute of the given element
142
     *
143
     * @param string $sTarget    The id of the element to be updated.
144
     * @param string $sAttribute    The attribute to be cleared
145
     *
146
     * @return ResponseInterface
147
     */
148
    public function clear(string $sTarget, string $sAttribute = 'innerHTML'): ResponseInterface;
149
150
    /**
151
     * Add a command to assign a value to a member of a javascript object (or element)
152
     * that is specified by the context member of the request
153
     *
154
     * The object is referenced using the 'this' keyword in the sAttribute parameter.
155
     *
156
     * @param string $sAttribute    The attribute to be updated
157
     * @param string $sData    The value to assign
158
     *
159
     * @return ResponseInterface
160
     */
161
    public function contextAssign(string $sAttribute, string $sData): ResponseInterface;
162
163
    /**
164
     * Add a command to append a value onto the specified member of the javascript
165
     * context object (or element) specified by the context member of the request
166
     *
167
     * The object is referenced using the 'this' keyword in the sAttribute parameter.
168
     *
169
     * @param string $sAttribute    The attribute to be appended to
170
     * @param string $sData    The value to append
171
     *
172
     * @return ResponseInterface
173
     */
174
    public function contextAppend(string $sAttribute, string $sData): ResponseInterface;
175
176
    /**
177
     * Add a command to prepend the speicified data to the given member of the current
178
     * javascript object specified by context in the current request
179
     *
180
     * The object is access via the 'this' keyword in the sAttribute parameter.
181
     *
182
     * @param string $sAttribute    The attribute to be updated
183
     * @param string $sData    The value to be prepended
184
     *
185
     * @return ResponseInterface
186
     */
187
    public function contextPrepend(string $sAttribute, string $sData): ResponseInterface;
188
189
    /**
190
     * Add a command to to clear the value of the attribute specified in the sAttribute parameter
191
     *
192
     * The member is access via the 'this' keyword and can be used to update a javascript
193
     * object specified by context in the request parameters.
194
     *
195
     * @param string $sAttribute    The attribute to be cleared
196
     *
197
     * @return ResponseInterface
198
     */
199
    public function contextClear(string $sAttribute): ResponseInterface;
200
201
    /**
202
     * Add a command to remove an element from the document
203
     *
204
     * @param string $sTarget    The id of the element to be removed
205
     *
206
     * @return ResponseInterface
207
     */
208
    public function remove(string $sTarget): ResponseInterface;
209
210
    /**
211
     * Add a command to create a new element on the browser
212
     *
213
     * @param string $sParent    The id of the parent element
214
     * @param string $sTag    The tag name to be used for the new element
215
     * @param string $sId    The id to assign to the new element
216
     *
217
     * @return ResponseInterface
218
     */
219
    public function create(string $sParent, string $sTag, string $sId): ResponseInterface;
220
221
    /**
222
     * Add a command to insert a new element just prior to the specified element
223
     *
224
     * @param string $sBefore    The id of the element used as a reference point for the insertion
225
     * @param string $sTag    The tag name to be used for the new element
226
     * @param string $sId    The id to assign to the new element
227
     *
228
     * @return ResponseInterface
229
     */
230
    public function insertBefore(string $sBefore, string $sTag, string $sId): ResponseInterface;
231
232
    /**
233
     * Add a command to insert a new element just prior to the specified element
234
     * This is an alias for insertBefore.
235
     *
236
     * @param string $sBefore    The id of the element used as a reference point for the insertion
237
     * @param string $sTag    The tag name to be used for the new element
238
     * @param string $sId    The id to assign to the new element
239
     *
240
     * @return ResponseInterface
241
     */
242
    public function insert(string $sBefore, string $sTag, string $sId): ResponseInterface;
243
244
    /**
245
     * Add a command to insert a new element after the specified
246
     *
247
     * @param string $sAfter    The id of the element used as a reference point for the insertion
248
     * @param string $sTag    The tag name to be used for the new element
249
     * @param string $sId    The id to assign to the new element
250
     *
251
     * @return ResponseInterface
252
     */
253
    public function insertAfter(string $sAfter, string $sTag, string $sId): ResponseInterface;
254
255
    /**
256
     * Add a command to create an input element on the browser
257
     *
258
     * @param string $sParent    The id of the parent element
259
     * @param string $sType    The type of the new input element
260
     * @param string $sName    The name of the new input element
261
     * @param string $sId    The id of the new element
262
     *
263
     * @return ResponseInterface
264
     */
265
    public function createInput(string $sParent, string $sType, string $sName, string $sId): ResponseInterface;
266
267
    /**
268
     * Add a command to insert a new input element preceding the specified element
269
     *
270
     * @param string $sBefore    The id of the element to be used as the reference point for the insertion
271
     * @param string $sType    The type of the new input element
272
     * @param string $sName    The name of the new input element
273
     * @param string $sId    The id of the new element
274
     *
275
     * @return ResponseInterface
276
     */
277
    public function insertInput(string $sBefore, string $sType, string $sName, string $sId): ResponseInterface;
278
279
    /**
280
     * Add a command to insert a new input element after the specified element
281
     *
282
     * @param string $sAfter    The id of the element to be used as the reference point for the insertion
283
     * @param string $sType    The type of the new input element
284
     * @param string $sName    The name of the new input element
285
     * @param string $sId    The id of the new element
286
     *
287
     * @return ResponseInterface
288
     */
289
    public function insertInputAfter(string $sAfter, string $sType, string $sName, string $sId): ResponseInterface;
290
291
    /**
292
     * Response command that prompts user with [ok] [cancel] style message box
293
     *
294
     * If the user clicks cancel, the specified number of response commands
295
     * following this one, will be skipped.
296
     *
297
     * @param integer $nCommandCount    The number of commands to skip upon cancel
298
     * @param string $sMessage    The message to display to the user
299
     *
300
     * @return ResponseInterface
301
     */
302
    public function confirmCommands(int $nCommandCount, string $sMessage): ResponseInterface;
303
304
    /**
305
     * Add a command to display an alert message to the user
306
     *
307
     * @param string $sMessage    The message to be displayed
308
     *
309
     * @return ResponseInterface
310
     */
311
    public function alert(string $sMessage): ResponseInterface;
312
313
    /**
314
     * Add a command to display a debug message to the user
315
     *
316
     * @param string $sMessage    The message to be displayed
317
     *
318
     * @return ResponseInterface
319
     */
320
    public function debug(string $sMessage): ResponseInterface;
321
322
    /**
323
     * Add a command to ask the browser to navigate to the specified URL
324
     *
325
     * @param string $sURL    The relative or fully qualified URL
326
     * @param integer $nDelay    Number of seconds to delay before the redirect occurs
327
     *
328
     * @return ResponseInterface
329
     */
330
    public function redirect(string $sURL, int $nDelay = 0): ResponseInterface;
331
332
    /**
333
     * Add a command to execute a portion of javascript on the browser
334
     *
335
     * The script runs in its own context, so variables declared locally, using the 'var' keyword,
336
     * will no longer be available after the call.
337
     * To construct a variable that will be accessible globally, even after the script has executed,
338
     * leave off the 'var' keyword.
339
     *
340
     * @param string $sJS    The script to execute
341
     *
342
     * @return ResponseInterface
343
     */
344
    public function script(string $sJS): ResponseInterface;
345
346
    /**
347
     * Add a command to call the specified javascript function with the given (optional) parameters
348
     *
349
     * @param string $sFunc    The name of the function to call
350
     *
351
     * @return ResponseInterface
352
     */
353
    public function call(string $sFunc): ResponseInterface;
354
355
    /**
356
     * Add a command to set an event handler on the browser
357
     *
358
     * @param string $sTarget    The id of the element that contains the event
359
     * @param string $sEvent    The name of the event
360
     * @param string $sScript    The javascript to execute when the event is fired
361
     *
362
     * @return ResponseInterface
363
     */
364
    public function setEvent(string $sTarget, string $sEvent, string $sScript): ResponseInterface;
365
366
    /**
367
     * Add a command to set a click handler on the browser
368
     *
369
     * @param string $sTarget    The id of the element that contains the event
370
     * @param string $sScript    The javascript to execute when the event is fired
371
     *
372
     * @return ResponseInterface
373
     */
374
    public function onClick(string $sTarget, string $sScript): ResponseInterface;
375
376
    /**
377
     * Add a command to install an event handler on the specified element
378
     *
379
     * You can add more than one event handler to an element's event using this method.
380
     *
381
     * @param string $sTarget    The id of the element
382
     * @param string $sEvent    The name of the event
383
     * @param string $sHandler    The name of the javascript function to call when the event is fired
384
     *
385
     * @return ResponseInterface
386
     */
387
    public function addHandler(string $sTarget, string $sEvent, string $sHandler): ResponseInterface;
388
389
    /**
390
     * Add a command to remove an event handler from an element
391
     *
392
     * @param string $sTarget    The id of the element
393
     * @param string $sEvent    The name of the event
394
     * @param string $sHandler    The name of the javascript function called when the event is fired
395
     *
396
     * @return ResponseInterface
397
     */
398
    public function removeHandler(string $sTarget, string $sEvent, string $sHandler): ResponseInterface;
399
400
    /**
401
     * Add a command to construct a javascript function on the browser
402
     *
403
     * @param string $sFunction    The name of the function to construct
404
     * @param string $sArgs    Comma separated list of parameter names
405
     * @param string $sScript    The javascript code that will become the body of the function
406
     *
407
     * @return ResponseInterface
408
     */
409
    public function setFunction(string $sFunction, string $sArgs, string $sScript): ResponseInterface;
410
411
    /**
412
     * Add a command to construct a wrapper function around an existing javascript function on the browser
413
     *
414
     * @param string $sFunction    The name of the existing function to wrap
415
     * @param string $sArgs    The comma separated list of parameters for the function
416
     * @param array $aScripts    An array of javascript code snippets that will be used to build
417
     *                                             the body of the function
418
     *                                             The first piece of code specified in the array will occur before
419
     *                                             the call to the original function, the second will occur after
420
     *                                             the original function is called.
421
     * @param string $sReturnValueVar    The name of the variable that will retain the return value
422
     *                                             from the call to the original function
423
     *
424
     * @return ResponseInterface
425
     */
426
    public function wrapFunction(string $sFunction, string $sArgs, array $aScripts, string $sReturnValueVar): ResponseInterface;
427
428
    /**
429
     * Add a command to load a javascript file on the browser
430
     *
431
     * @param string $sFileName    The relative or fully qualified URI of the javascript file
432
     * @param string $sType    Determines the script type. Defaults to 'text/javascript'
433
     * @param string $sId    The wrapper id
434
     *
435
     * @return ResponseInterface
436
     */
437
    public function includeScript(string $sFileName, string $sType = '', string $sId = ''): ResponseInterface;
438
439
    /**
440
     * Add a command to include a javascript file on the browser if it has not already been loaded
441
     *
442
     * @param string $sFileName    The relative or fully qualified URI of the javascript file
443
     * @param string $sType    Determines the script type. Defaults to 'text/javascript'
444
     * @param string $sId    The wrapper id
445
     *
446
     * @return ResponseInterface
447
     */
448
    public function includeScriptOnce(string $sFileName, string $sType = '', string $sId = ''): ResponseInterface;
449
450
    /**
451
     * Add a command to remove a SCRIPT reference to a javascript file on the browser
452
     *
453
     * Optionally, you can call a javascript function just prior to the file being unloaded (for cleanup).
454
     *
455
     * @param string $sFileName    The relative or fully qualified URI of the javascript file
456
     * @param string $sUnload    Name of a javascript function to call prior to unlaoding the file
457
     *
458
     * @return ResponseInterface
459
     */
460
    public function removeScript(string $sFileName, string $sUnload = ''): ResponseInterface;
461
462
    /**
463
     * Add a command to include a LINK reference to the specified CSS file on the browser.
464
     *
465
     * This will cause the browser to load and apply the style sheet.
466
     *
467
     * @param string $sFileName    The relative or fully qualified URI of the css file
468
     * @param string $sMedia    The media type of the CSS file. Defaults to 'screen'
469
     *
470
     * @return ResponseInterface
471
     */
472
    public function includeCSS(string $sFileName, string $sMedia = ''): ResponseInterface;
473
474
    /**
475
     * Add a command to remove a LINK reference to a CSS file on the browser
476
     *
477
     * This causes the browser to unload the style sheet, effectively removing the style changes it caused.
478
     *
479
     * @param string $sFileName The relative or fully qualified URI of the css file
480
     * @param string $sMedia
481
     *
482
     * @return ResponseInterface
483
     */
484
    public function removeCSS(string $sFileName, string $sMedia = ''): ResponseInterface;
485
486
    /**
487
     * Add a command to make Jaxon pause while the CSS files are loaded
488
     *
489
     * The browser is not typically a multi-threading application, with regards to javascript code.
490
     * Therefore, the CSS files included or removed with <Response->includeCSS> and
491
     * <Response->removeCSS> respectively, will not be loaded or removed until the browser regains
492
     * control from the script.
493
     * This command returns control back to the browser and pauses the execution of the response
494
     * until the CSS files, included previously, are loaded.
495
     *
496
     * @param integer $nTimeout    The number of 1/10ths of a second to pause before timing out
497
     *                                             and continuing with the execution of the response commands
498
     *
499
     * @return ResponseInterface
500
     */
501
    public function waitForCSS(int $nTimeout = 600): ResponseInterface;
502
503
    /**
504
     * Add a command to make Jaxon to delay execution of the response commands until a specified condition is met
505
     *
506
     * Note, this returns control to the browser, so that other script operations can execute.
507
     * Jaxon will continue to monitor the specified condition and, when it evaluates to true,
508
     * will continue processing response commands.
509
     *
510
     * @param string $script    A piece of javascript code that evaulates to true or false
511
     * @param integer $tenths    The number of 1/10ths of a second to wait before timing out
512
     *                                             and continuing with the execution of the response commands.
513
     *
514
     * @return ResponseInterface
515
     */
516
    public function waitFor(string $script, int $tenths): ResponseInterface;
517
518
    /**
519
     * Add a command to make Jaxon to pause execution of the response commands,
520
     * returning control to the browser so it can perform other commands asynchronously.
521
     *
522
     * After the specified delay, Jaxon will continue execution of the response commands.
523
     *
524
     * @param integer $tenths    The number of 1/10ths of a second to sleep
525
     *
526
     * @return ResponseInterface
527
     */
528
    public function sleep(int $tenths): ResponseInterface;
529
}
530