Skip to content
GitLab
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
0ac8d21f
Commit
0ac8d21f
authored
Jan 16, 2016
by
Carsten Rose
Browse files
Evaluate.php: Code rearranged. Doc and Typos fixed. Added parseArray()
parent
7131800f
Changes
2
Hide whitespace changes
Inline
Side-by-side
qfq/Evaluate.php
View file @
0ac8d21f
...
...
@@ -35,8 +35,29 @@ class Evaluate {
}
/**
* Evaluate a whole array.
*
* @param $tokenArray
* @return mixed
*/
public
function
parseArray
(
$tokenArray
)
{
$arr
=
array
();
foreach
(
$tokenArray
as
$key
=>
$value
)
{
$arr
[
$key
]
=
$this
->
parse
(
$value
);
}
return
$arr
;
}
/**
* Recursive evaluation of 'line'.
* Token to replaces have to be enclosed by '{{' and '}}'
*
* @param $line
* @throws UserException
* @param int $recursion
* @return array|mixed|null|string
* @throws exceptions\UserException
*/
public
function
parse
(
$line
,
$recursion
=
0
)
{
...
...
@@ -80,8 +101,9 @@ class Evaluate {
/**
* Tries to substitute $token.
* Token might be
* a) fetched from a store. Syntax: 'form', 'form:C', 'form:SC0', 'form:S:ALNUMX'
* b) Result of a fired SQL statement.
* a) fetch from a store. Syntax: 'form', 'form:C', 'form:SC0', 'form:S:ALNUMX'
* b) a SQL statement to fire
* The token have to be _without_ Delimiter '{{' / '}}'
* If neither a) or b) match, return the token itself, surrounded by single ticks, to emphase that substition failed.
*
* @param $token
...
...
@@ -121,6 +143,4 @@ class Evaluate {
// nothing replaced: put ticks around, to sanatize strings for SQL statements. Nothing to substitute is not a wished situation.
return
(
$value
===
false
)
?
"'"
.
$token
.
"'"
:
$value
;
}
}
// Hallo {{SELECT id FROM Form ='{{form}}'}} wird {{SELECT {{SHOW Table}} FROM id={{r}} }} NEW {{SQL}} ENDE
\ No newline at end of file
}
\ No newline at end of file
tests/phpunit/EvaluateTest.php
View file @
0ac8d21f
...
...
@@ -97,6 +97,21 @@ class EvaluateTest extends AbstractDatabaseTest {
}
public
function
testParseArray
()
{
$eval
=
new
\
qfq\Evaluate
(
$this
->
store
,
$this
->
db
);
$data
=
[
'formName'
=>
'MyTestForm'
,
'title'
=>
'Person: {{SELECT firstname, " ", name FROM person LIMIT 1}} / Employee'
];
$expected
=
[
'formName'
=>
'MyTestForm'
,
'title'
=>
'Person: John Doe / Employee'
];
$this
->
assertEquals
(
$expected
,
$eval
->
parseArray
(
$data
));
}
protected
function
setUp
()
{
$this
->
store
=
\
qfq\store\Store
::
getInstance
(
'form=TestFormName'
);
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment