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
d9e9c1bb
Commit
d9e9c1bb
authored
12 years ago
by
Andreas Gohr
Browse files
Options
Downloads
Patches
Plain Diff
extract method for Input class
makes it easier to access our do parameters
parent
80a47290
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
_test/tests/inc/input.test.php
+18
-1
18 additions, 1 deletion
_test/tests/inc/input.test.php
inc/Input.class.php
+34
-0
34 additions, 0 deletions
inc/Input.class.php
with
52 additions
and
1 deletion
_test/tests/inc/input.test.php
+
18
−
1
View file @
d9e9c1bb
...
...
@@ -12,7 +12,8 @@ class input_test extends DokuWikiTest {
'zero'
=>
'0'
,
'one'
=>
'1'
,
'empty'
=>
''
,
'emptya'
=>
array
()
'emptya'
=>
array
(),
'do'
=>
array
(
'save'
=>
'Speichern'
),
);
public
function
test_str
()
{
...
...
@@ -213,4 +214,20 @@ class input_test extends DokuWikiTest {
$this
->
assertEquals
(
'bla'
,
$test
);
}
public
function
test_extract
(){
$_REQUEST
=
$this
->
data
;
$_POST
=
$this
->
data
;
$_GET
=
$this
->
data
;
$INPUT
=
new
Input
();
$this
->
assertEquals
(
'save'
,
$INPUT
->
extract
(
'do'
)
->
str
(
'do'
));
$this
->
assertEquals
(
''
,
$INPUT
->
extract
(
'emptya'
)
->
str
(
'emptya'
));
$this
->
assertEquals
(
'foo'
,
$INPUT
->
extract
(
'string'
)
->
str
(
'string'
));
$this
->
assertEquals
(
'foo'
,
$INPUT
->
extract
(
'array'
)
->
str
(
'array'
));
$this
->
assertEquals
(
'save'
,
$INPUT
->
post
->
extract
(
'do'
)
->
str
(
'do'
));
$this
->
assertEquals
(
''
,
$INPUT
->
post
->
extract
(
'emptya'
)
->
str
(
'emptya'
));
$this
->
assertEquals
(
'foo'
,
$INPUT
->
post
->
extract
(
'string'
)
->
str
(
'string'
));
$this
->
assertEquals
(
'foo'
,
$INPUT
->
post
->
extract
(
'array'
)
->
str
(
'array'
));
}
}
This diff is collapsed.
Click to expand it.
inc/Input.class.php
+
34
−
0
View file @
d9e9c1bb
...
...
@@ -175,6 +175,40 @@ class Input {
return
(
array
)
$this
->
access
[
$name
];
}
/**
* Create a simple key from an array key
*
* This is useful to access keys where the information is given as an array key or as a single array value.
* For example when the information was submitted as the name of a submit button.
*
* This function directly changes the access array.
*
* Eg. $_REQUEST['do']['save']='Speichern' becomes $_REQUEST['do'] = 'save'
*
* This function returns the $INPUT object itself for easy chaining
*
* @param $name
* @return Input
*/
public
function
extract
(
$name
){
if
(
!
isset
(
$this
->
access
[
$name
]))
return
$this
;
if
(
!
is_array
(
$this
->
access
[
$name
]))
return
$this
;
$keys
=
array_keys
(
$this
->
access
[
$name
]);
if
(
!
$keys
){
// this was an empty array
$this
->
remove
(
$name
);
return
$this
;
}
// get the first key
$value
=
array_shift
(
$keys
);
if
(
$value
===
0
){
// we had a numeric array, assume the value is not in the key
$value
=
array_shift
(
$this
->
access
[
$name
]);
}
$this
->
set
(
$name
,
$value
);
return
$this
;
}
}
/**
...
...
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