Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
typo3
qfq
Commits
b0cd7178
Commit
b0cd7178
authored
Jan 24, 2016
by
Carsten Rose
Browse files
KeyValueStringParser: variables and constants renamed to be more understandable
parent
0b613ec0
Changes
3
Hide whitespace changes
Inline
Side-by-side
qfq/Constants.php
View file @
b0cd7178
...
...
@@ -43,9 +43,11 @@ const ROW_EXACT_1 = "exact_1";
const
ROW_EMPTY_IS_OK
=
"empty_is_ok"
;
// KeyValueParser
const
KEY
_VALUE_
SINGLE
=
'flag
'
;
const
KEY_
VALUE_
PAIR
=
'pair
'
;
const
IF
_VALUE_
EMPTY_COPY_KEY
=
'if_value_empty_copy_key
'
;
const
VALUE_
GIVEN
=
'value_given
'
;
// FormBuildPlain
const
SUBRECORD_COLUMN_WIDTH
=
20
;
// QFQ Error Codes
const
ERROR_UNKNOW_SANATIZE_CLASS
=
1001
;
...
...
@@ -72,7 +74,7 @@ const ERROR_MISSING_OPEN_DELIMITER = 1021;
const
ERROR_RECURSION_TOO_DEEP
=
1022
;
const
ERROR_UNKNOWN_COLUMN
=
1023
;
const
ERROR_CHECKBOXMODE_UNKNOWN
=
1024
;
const
ERROR_
=
1025
;
const
ERROR_
MISSING_SQL1
=
1025
;
const
ERROR_CHECKBOX_EQUAL
=
1026
;
const
ERROR_MISSING_ITEM_VALUES
=
1027
;
...
...
qfq/helper/KeyValueStringParser.php
View file @
b0cd7178
...
...
@@ -85,12 +85,12 @@ class KeyValueStringParser {
* @param string $keyValueString string of key/value pairs
* @param string $keyValueDelimiter
* @param string $listDelimiter
* @param string $
keyV
alueMode
* @param string $
v
alueMode
* @return array associative array indexed by keys
* @throws UserException
*/
public
static
function
parse
(
$keyValueString
,
$keyValueDelimiter
=
":"
,
$listDelimiter
=
","
,
$
keyV
alueMode
=
KEY_
VALUE_
PAIR
)
{
public
static
function
parse
(
$keyValueString
,
$keyValueDelimiter
=
":"
,
$listDelimiter
=
","
,
$
v
alueMode
=
VALUE_
GIVEN
)
{
if
(
$keyValueString
===
""
)
{
return
array
();
}
...
...
@@ -123,7 +123,7 @@ class KeyValueStringParser {
$returnValue
[
$key
]
=
self
::
removeSourroundingQuotes
(
trim
(
$keyValueArray
[
1
]));
}
else
{
// no Value given: "a"
$returnValue
[
$key
]
=
(
$
keyV
alueMode
===
KEY_
VALUE_
PAIR
)
?
""
:
$key
;
$returnValue
[
$key
]
=
(
$
v
alueMode
===
VALUE_
GIVEN
)
?
""
:
$key
;
}
}
...
...
tests/phpunit/KeyValueStringParserTest.php
View file @
b0cd7178
...
...
@@ -132,7 +132,7 @@ class KeyValueStringParserTest extends \PHPUnit_Framework_TestCase {
}
public
function
testParseKeyValueSingle
()
{
$actual
=
keyValueStringParser
::
parse
(
'value1,value2'
,
':'
,
','
,
KEY
_VALUE_
SINGLE
);
$actual
=
keyValueStringParser
::
parse
(
'value1,value2'
,
':'
,
','
,
IF
_VALUE_
EMPTY_COPY_KEY
);
$expected
=
[
'value1'
=>
'value1'
,
'value2'
=>
'value2'
,
...
...
@@ -140,7 +140,7 @@ class KeyValueStringParserTest extends \PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
$expected
,
$actual
);
$this
->
assertCount
(
2
,
$actual
);
$actual
=
keyValueStringParser
::
parse
(
'key1:value1,key2:value2'
,
':'
,
','
,
KEY
_VALUE_
SINGLE
);
$actual
=
keyValueStringParser
::
parse
(
'key1:value1,key2:value2'
,
':'
,
','
,
IF
_VALUE_
EMPTY_COPY_KEY
);
$expected
=
[
'key1'
=>
'value1'
,
'key2'
=>
'value2'
,
...
...
@@ -148,7 +148,7 @@ class KeyValueStringParserTest extends \PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
$expected
,
$actual
);
$this
->
assertCount
(
2
,
$actual
);
$actual
=
keyValueStringParser
::
parse
(
'key1:value1,key2:value2'
,
':'
,
','
,
KEY_
VALUE_
PAIR
);
$actual
=
keyValueStringParser
::
parse
(
'key1:value1,key2:value2'
,
':'
,
','
,
VALUE_
GIVEN
);
$expected
=
[
'key1'
=>
'value1'
,
'key2'
=>
'value2'
,
...
...
@@ -156,7 +156,7 @@ class KeyValueStringParserTest extends \PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
$expected
,
$actual
);
$this
->
assertCount
(
2
,
$actual
);
$actual
=
keyValueStringParser
::
parse
(
'value1,value2'
,
':'
,
','
,
KEY_
VALUE_
PAIR
);
$actual
=
keyValueStringParser
::
parse
(
'value1,value2'
,
':'
,
','
,
VALUE_
GIVEN
);
$expected
=
[
'value1'
=>
''
,
'value2'
=>
''
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment