Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dokuwiki
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BRIC
dokuwiki
Commits
c4e18ef9
Commit
c4e18ef9
authored
12 years ago
by
Andreas Gohr
Browse files
Options
Downloads
Patches
Plain Diff
added 3rd parameter to Input methods
This allows to treat empty parameters as default
parent
f9aa73bf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inc/Input.class.php
+21
-10
21 additions, 10 deletions
inc/Input.class.php
with
21 additions
and
10 deletions
inc/Input.class.php
+
21
−
10
View file @
c4e18ef9
...
@@ -33,7 +33,7 @@ class Input {
...
@@ -33,7 +33,7 @@ class Input {
* Basically a wrapper around isset
* Basically a wrapper around isset
*
*
* @see isset
* @see isset
* @param $name Parameter name
* @param
string
$name Parameter name
* @return bool
* @return bool
*/
*/
public
function
has
(
$name
)
{
public
function
has
(
$name
)
{
...
@@ -45,10 +45,12 @@ class Input {
...
@@ -45,10 +45,12 @@ class Input {
*
*
* @param string $name Parameter name
* @param string $name Parameter name
* @param mixed $default Default to return if parameter isn't set
* @param mixed $default Default to return if parameter isn't set
* @param bool $nonempty Return $default if parameter is set but empty()
* @return mixed
* @return mixed
*/
*/
public
function
param
(
$name
,
$default
=
null
)
{
public
function
param
(
$name
,
$default
=
null
,
$nonempty
=
false
)
{
if
(
!
isset
(
$this
->
access
[
$name
]))
return
$default
;
if
(
!
isset
(
$this
->
access
[
$name
]))
return
$default
;
if
(
$nonempty
&&
empty
(
$this
->
access
[
$name
]))
return
$default
;
return
$this
->
access
[
$name
];
return
$this
->
access
[
$name
];
}
}
...
@@ -58,12 +60,13 @@ class Input {
...
@@ -58,12 +60,13 @@ class Input {
* This avoids copying data in memory, when the parameter is not set it will be created
* This avoids copying data in memory, when the parameter is not set it will be created
* and intialized with the given $default value before a reference is returned
* and intialized with the given $default value before a reference is returned
*
*
* @param string $name Parameter name
* @param string $name Parameter name
* @param mixed $default Initialize parameter with if not set
* @param mixed $default Initialize parameter with if not set
* @param bool $nonempty Init with $default if parameter is set but empty()
* @return &mixed
* @return &mixed
*/
*/
public
function
&
ref
(
$name
,
$default
=
''
)
{
public
function
&
ref
(
$name
,
$default
=
''
,
$nonempty
=
false
)
{
if
(
!
isset
(
$this
->
access
[
$name
]))
{
if
(
!
isset
(
$this
->
access
[
$name
])
||
(
$nonempty
&&
empty
(
$this
->
access
[
$name
]))
)
{
$this
->
access
[
$name
]
=
$default
;
$this
->
access
[
$name
]
=
$default
;
}
}
...
@@ -76,11 +79,13 @@ class Input {
...
@@ -76,11 +79,13 @@ class Input {
*
*
* @param string $name Parameter name
* @param string $name Parameter name
* @param mixed $default Default to return if parameter isn't set or is an array
* @param mixed $default Default to return if parameter isn't set or is an array
* @param bool $nonempty Return $default if parameter is set but empty()
* @return int
* @return int
*/
*/
public
function
int
(
$name
,
$default
=
0
)
{
public
function
int
(
$name
,
$default
=
0
,
$nonempty
=
false
)
{
if
(
!
isset
(
$this
->
access
[
$name
]))
return
$default
;
if
(
!
isset
(
$this
->
access
[
$name
]))
return
$default
;
if
(
is_array
(
$this
->
access
[
$name
]))
return
$default
;
if
(
is_array
(
$this
->
access
[
$name
]))
return
$default
;
if
(
$nonempty
&&
empty
(
$this
->
access
[
$name
]))
return
$default
;
return
(
int
)
$this
->
access
[
$name
];
return
(
int
)
$this
->
access
[
$name
];
}
}
...
@@ -90,11 +95,13 @@ class Input {
...
@@ -90,11 +95,13 @@ class Input {
*
*
* @param string $name Parameter name
* @param string $name Parameter name
* @param mixed $default Default to return if parameter isn't set or is an array
* @param mixed $default Default to return if parameter isn't set or is an array
* @param bool $nonempty Return $default if parameter is set but empty()
* @return string
* @return string
*/
*/
public
function
str
(
$name
,
$default
=
''
)
{
public
function
str
(
$name
,
$default
=
''
,
$nonempty
=
false
)
{
if
(
!
isset
(
$this
->
access
[
$name
]))
return
$default
;
if
(
!
isset
(
$this
->
access
[
$name
]))
return
$default
;
if
(
is_array
(
$this
->
access
[
$name
]))
return
$default
;
if
(
is_array
(
$this
->
access
[
$name
]))
return
$default
;
if
(
$nonempty
&&
empty
(
$this
->
access
[
$name
]))
return
$default
;
return
(
string
)
$this
->
access
[
$name
];
return
(
string
)
$this
->
access
[
$name
];
}
}
...
@@ -104,10 +111,12 @@ class Input {
...
@@ -104,10 +111,12 @@ class Input {
*
*
* @param string $name Parameter name
* @param string $name Parameter name
* @param mixed $default Default to return if parameter isn't set
* @param mixed $default Default to return if parameter isn't set
* @param bool $nonempty Return $default if parameter is set but empty()
* @return bool
* @return bool
*/
*/
public
function
bool
(
$name
,
$default
=
''
)
{
public
function
bool
(
$name
,
$default
=
''
,
$nonempty
=
false
)
{
if
(
!
isset
(
$this
->
access
[
$name
]))
return
$default
;
if
(
!
isset
(
$this
->
access
[
$name
]))
return
$default
;
if
(
$nonempty
&&
empty
(
$this
->
access
[
$name
]))
return
$default
;
return
(
bool
)
$this
->
access
[
$name
];
return
(
bool
)
$this
->
access
[
$name
];
}
}
...
@@ -117,10 +126,12 @@ class Input {
...
@@ -117,10 +126,12 @@ class Input {
*
*
* @param string $name Parameter name
* @param string $name Parameter name
* @param mixed $default Default to return if parameter isn't set
* @param mixed $default Default to return if parameter isn't set
* @param bool $nonempty Return $default if parameter is set but empty()
* @return array
* @return array
*/
*/
public
function
arr
(
$name
,
$default
=
array
())
{
public
function
arr
(
$name
,
$default
=
array
()
,
$nonempty
=
false
)
{
if
(
!
isset
(
$this
->
access
[
$name
]))
return
$default
;
if
(
!
isset
(
$this
->
access
[
$name
]))
return
$default
;
if
(
$nonempty
&&
empty
(
$this
->
access
[
$name
]))
return
$default
;
return
(
array
)
$this
->
access
[
$name
];
return
(
array
)
$this
->
access
[
$name
];
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment