Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
Dwoo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Common
Dwoo
Commits
e7f5d5b4
Commit
e7f5d5b4
authored
Jul 18, 2010
by
Jordi Boggiano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #61: Allowing variable property reads
parent
e7734ba8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
5 deletions
+8
-5
Compiler.php
lib/Dwoo/Compiler.php
+0
-5
CompilerTests.php
tests/CompilerTests.php
+8
-0
No files found.
lib/Dwoo/Compiler.php
View file @
e7f5d5b4
...
...
@@ -2097,11 +2097,6 @@ class Dwoo_Compiler implements Dwoo_ICompiler
// replace useless brackets by dot accessed vars and strip enclosing quotes if present
$key
=
preg_replace
(
'#\[(["\']?)([^$%\[.>-]+)\1\]#'
,
'.$2'
,
$key
);
// prevent $foo->$bar calls because it doesn't seem worth the trouble
if
(
strpos
(
$key
,
'->$'
)
!==
false
)
{
throw
new
Dwoo_Compilation_Exception
(
$this
,
'You can not access an object\'s property using a variable name.'
);
}
if
(
$this
->
debug
)
{
if
(
$hasMethodCall
)
{
echo
'METHOD CALL FOUND : $'
.
$key
.
substr
(
$methodCall
,
0
,
30
)
.
'<br />'
;
...
...
tests/CompilerTests.php
View file @
e7f5d5b4
...
...
@@ -23,6 +23,14 @@ class CompilerTests extends PHPUnit_Framework_TestCase
$this
->
assertEquals
(
'bar'
,
$this
->
dwoo
->
get
(
$tpl
,
array
(
'foo'
=>
'bar'
),
$this
->
compiler
));
}
public
function
testVariableObjectPropertyAccess
()
{
$tpl
=
new
Dwoo_Template_String
(
'{$obj->$var}'
);
$tpl
->
forceCompilation
();
$this
->
assertEquals
(
'yay'
,
$this
->
dwoo
->
get
(
$tpl
,
array
(
'obj'
=>
new
PluginHelper
,
'var'
=>
'moo'
),
$this
->
compiler
));
}
public
function
testComplexVarReplacement
()
{
$tpl
=
new
Dwoo_Template_String
(
'{$_root[$a].0}{$_[$a][0]}{$_[$c.d].0}{$_.$a.0}{$_[$c[$x.0]].0}{$_[$c.$y.0].0}'
);
...
...
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