Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webbasics
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
webbasics
Commits
97c7d6c3
Commit
97c7d6c3
authored
Jul 20, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added default value to template expression grammar.
parent
ba551f93
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
template.php
template.php
+13
-4
tests/test_template.php
tests/test_template.php
+7
-0
No files found.
template.php
View file @
97c7d6c3
...
...
@@ -71,10 +71,12 @@ require_once 'node.php';
* curly brackets: *{expression}*. The grammar of all expressions that are
* currently supported can be described as follows:
* <code>
* <expression> : {<nested_exp>}
* | {<nested_exp>?<nested_exp>:<nested_exp>} # Conditional statement
* <expression> : {<exp>}
* <exp> : <nested_exp>
* | <nested_exp>?<nested_exp>:<nested_exp> # Conditional statement
* <nested_exp> : <variable>
* | <function>(<nested_exp>) # Static function call
* | <nested_exp>||<nested_exp> # Default value
* | <function>(<nested_exp>) # Static function call
* | <constant>
* | <html>
* <variable> : $<name> # Regular variable
...
...
@@ -83,7 +85,7 @@ require_once 'node.php';
* <function> : <name> # Global function
* | <name>::<name> # Static class method
* <constant> : An all-caps PHP constant: [A-Z0-9_]+
* <html> : A string without parentheses,
curly brackets or semicolons: [^()
{}:]*
* <html> : A string without parentheses,
pipes, curly brackets or semicolons: [^()|
{}:]*
* <name> : A non-empty variable/method name consisting of [a-zA-Z0-9-_]+
* </code>
*
...
...
@@ -423,6 +425,13 @@ class Template extends Node {
}
elseif
(
preg_match
(
"/^([A-Z0-9_]+)$/"
,
$expression
,
$matches
)
)
{
// <constant>
return
self
::
evaluate_constant
(
$expression
,
$root_level
);
}
elseif
(
(
$split_at
=
strpos
(
$expression
,
'||'
,
1
))
!==
false
)
{
// <nested_exp>||<nested_exp>
try
{
return
self
::
evaluate_expression
(
substr
(
$expression
,
0
,
$split_at
),
$data
,
false
);
}
catch
(
\RuntimeException
$e
)
{
return
self
::
evaluate_expression
(
substr
(
$expression
,
$split_at
+
2
),
$data
,
false
);
}
}
}
...
...
tests/test_template.php
View file @
97c7d6c3
...
...
@@ -334,11 +334,18 @@ class TemplateTest extends PHPUnit_Framework_TestCase {
$this
->
assert_evaluates
(
'Bar'
,
'ucfirst(strtolower($FOO))'
);
}
function
test_evaluate_default_value
()
{
$this
->
assert_evaluates
(
'bar'
,
'$foo||fallback'
);
$this
->
assert_evaluates
(
'fallback'
,
'$foo.bar||fallback'
);
$this
->
assert_evaluates
(
''
,
'$foo.bar||'
);
}
/**
* @depends test_evaluate_variable_success
* @depends test_evaluate_no_expression
* @depends test_evaluate_condition_spaces
* @depends test_evaluate_function_success
* @depends test_evaluate_default_value
*/
function
test_evaluate_expression_combined
()
{
$this
->
assert_evaluates
(
'Bar'
,
'$true?ucfirst($foo)'
);
...
...
Write
Preview
Markdown
is supported
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