You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: manual/en-US/chapters/packages/input.md
+83-18Lines changed: 83 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,16 @@
1
1
## The Input Package
2
2
3
-
The Input package provides a number of classes that can be used as an
4
-
alternative to using the static calls of the `JRequest` class. The package
5
-
comprises of four classes, `JInput`and three sub-classes extended from
6
-
it: `JInputCli`, `JInputCookie` and `JInputFiles`. An input object is
7
-
generally owned by the application and explicitly added to an
8
-
application class as a public property, such as can be found in
9
-
`JApplication`, `JApplicationCli` and `JApplicationDaemon`.
3
+
This package comprises of four classes, `JInput`and three sub-classes extended from it: `JInputCli`, `JInputCookie` and `JInputFiles`. It replaces the role of the now deprecated `JRequest` class. An input object is generally owned by the application and explicitly added to an application class as a public property, such as can be found in `JApplicationWeb`, `JApplicationCli` and `JApplicationDaemon`.
10
4
11
-
All classes in this package are supported by the auto-loader so can be
12
-
invoked at any time.
5
+
The intent of this package is to abstract out the input source to allow code to be reused in different applications and in different contexts through dependency injection. For example, a controller could inspect the request variables directly using `JRequest`. But suppose there is a requirement to add a web service that carries input as a JSON payload. Instead of writing a second controller to handle the different input source, it would be much easier to inject an input object, that is tailored for the type of input source, into the controller.
13
6
14
-
### Classes
7
+
Using a `JInput` object through dependency injection also makes code easier to test. Writing unit tests for code that relies on `JRequest` is problematic to say the least.
15
8
16
-
#### JInput
9
+
All classes in this package are supported by the auto-loader so can be invoked at any time.
17
10
18
-
##### Construction
11
+
### JInput
12
+
13
+
#### Construction
19
14
20
15
Unlike its predecessor `JRequest` which is used statically, the `JInput`
21
16
class is meant to be used as an instantiated concrete class. Among other
The most common usage of the `JInput` class will be through the get method
47
42
which is roughly equivalent to the `JRequest::getVar` method. The get
@@ -134,15 +129,15 @@ if ($input->server->get('SERVER_ADDR'))
134
129
$host = $input->env->get('HOSTNAME');
135
130
```
136
131
137
-
#####Serialization
132
+
#### Serialization
138
133
139
134
The `JInput` class implements the `Serializable` interface so that it can be
140
135
safely serialized and unserialized. Note that when serializing the "ENV"
141
136
and "SERVER" inputs are removed from the class as they may conflict or
142
137
inappropriately overwrite settings during unserialization. This allows
143
138
for `JInput` objects to be safely used with cached data.
144
139
145
-
####JInputCli
140
+
### JInputCli
146
141
147
142
The JInputCli class is extended from `JInput` but is tailored to work with
148
143
command line input. Once again the get method is used to get values of
@@ -210,10 +205,80 @@ bool(false)
210
205
array(1) {[0] => string(3) "bar"}
211
206
```
212
207
213
-
####JInputCookie
208
+
### JInputCookie
214
209
215
210
> Can you help improve this section of the manual?
216
211
217
-
####JInputFiles
212
+
### JInputFiles
218
213
219
-
> Can you help improve this section of the manual?
214
+
The `JInputFiles` class provides a way to handle file attachments as payloads of POSTed forms. Consider the following form which is assumed to handle an array of files to be attached (through some JavaScript behavior):
Unlike the PHP `$_FILES` supergobal, this array is very easier to parse. The example above assumes two files were submitted, but only one was specified. The 'blank' file contains an error code (see [PHP file upload errors](http://php.net/manual/en/features.file-upload.errors.php)).
283
+
284
+
The `set` method is disabled in `JInputFiles`. However,
0 commit comments