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
e7734ba8
Commit
e7734ba8
authored
Jul 18, 2010
by
Jordi Boggiano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #74: Added support for static vars and methods access on namespaced classes
parent
68c813a5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
7 deletions
+41
-7
CHANGELOG
CHANGELOG
+1
-0
Compiler.php
lib/Dwoo/Compiler.php
+3
-3
CompilerTests.php
tests/CompilerTests.php
+25
-4
namespace.php
tests/resources/namespace.php
+12
-0
No files found.
CHANGELOG
View file @
e7734ba8
...
...
@@ -15,6 +15,7 @@
+
Added
{
return
}
plugin
that
allows
any
included
template
to
return
variables
into
the
one
that
included
it
,
or
to
the
main
controller
code
via
$
dwoo
->
getReturnValues
()
+
Added
support
for
static
vars
and
methods
access
on
namespaced
classes
+
Moved
Dwoo
code
to
Dwoo_Core
that
is
extended
by
Dwoo
,
so
you
can
use
the
Dwoo
directory
as
an
svn
:
externals
without
problems
now
and
just
use
Dwoo_Core
in
place
of
Dwoo
in
your
code
...
...
lib/Dwoo/Compiler.php
View file @
e7734ba8
...
...
@@ -1360,7 +1360,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
}
elseif
((
$first
===
'"'
||
$first
===
"'"
)
&&
!
(
is_array
(
$parsingParams
)
&&
preg_match
(
'#^([\'"])[a-z0-9_]+\1\s*=>?(?:\s+|[^=])#i'
,
$substr
)))
{
// string
$out
=
$this
->
parseString
(
$in
,
$from
,
$to
,
$parsingParams
,
$curBlock
,
$pointer
);
}
elseif
(
preg_match
(
'/^
[a-z_][a-z0-9_]
*(?:::[a-z_][a-z0-9_]*)?('
.
(
is_array
(
$parsingParams
)
||
$curBlock
!=
'root'
?
''
:
'\s+[^(]|'
)
.
'\s*\(|\s*'
.
$this
->
rdr
.
'|\s*;)/i'
,
$substr
))
{
}
elseif
(
preg_match
(
'/^
\\\\?[a-z_](?:\\\\?[a-z0-9_]+)
*(?:::[a-z_][a-z0-9_]*)?('
.
(
is_array
(
$parsingParams
)
||
$curBlock
!=
'root'
?
''
:
'\s+[^(]|'
)
.
'\s*\(|\s*'
.
$this
->
rdr
.
'|\s*;)/i'
,
$substr
))
{
// func
$out
=
$this
->
parseFunction
(
$in
,
$from
,
$to
,
$parsingParams
,
$curBlock
,
$pointer
);
$parsed
=
'func'
;
...
...
@@ -1412,7 +1412,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
$parsingParams
[]
=
$output
;
return
$parsingParams
;
}
elseif
(
preg_match
(
'#^(
[a-z0-9_]+
::\$[a-z0-9_]+)#i'
,
$substr
,
$match
))
{
}
elseif
(
preg_match
(
'#^(
\\\\?[a-z_](?:\\\\?[a-z0-9_]+)*
::\$[a-z0-9_]+)#i'
,
$substr
,
$match
))
{
// static member access
$parsed
=
'var'
;
if
(
is_array
(
$parsingParams
))
{
...
...
@@ -1573,7 +1573,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
protected
function
parseFunction
(
$in
,
$from
,
$to
,
$parsingParams
=
false
,
$curBlock
=
''
,
&
$pointer
=
null
)
{
$cmdstr
=
substr
(
$in
,
$from
,
$to
-
$from
);
preg_match
(
'/^(
[a-z_][a-z0-9_]
*(?:::[a-z_][a-z0-9_]*)?)(\s*'
.
$this
->
rdr
.
'|\s*;)?/i'
,
$cmdstr
,
$match
);
preg_match
(
'/^(
\\\\?[a-z_](?:\\\\?[a-z0-9_]+)
*(?:::[a-z_][a-z0-9_]*)?)(\s*'
.
$this
->
rdr
.
'|\s*;)?/i'
,
$cmdstr
,
$match
);
if
(
empty
(
$match
[
1
]))
{
throw
new
Dwoo_Compilation_Exception
(
$this
,
'Parse error, invalid function name : '
.
substr
(
$cmdstr
,
0
,
15
));
...
...
tests/CompilerTests.php
View file @
e7734ba8
...
...
@@ -711,14 +711,35 @@ fail
$tpl
->
forceCompilation
();
$this
->
assertEquals
(
'testtest'
,
$this
->
dwoo
->
get
(
$tpl
,
array
(
'obj'
=>
new
PluginHelper
()),
$this
->
compiler
));
}
public
function
testFunctionCanStartWithUnderscore
()
{
$tpl
=
new
Dwoo_Template_String
(
'{_underscoreHelper("test", _underscoreHelper("bar", 10))|_underscoreModifierHelper}'
);
$tpl
->
forceCompilation
();
$this
->
assertEquals
(
'_--10bar-test-_'
,
$this
->
dwoo
->
get
(
$tpl
,
array
(),
$this
->
compiler
));
}
public
function
testNamespaceStaticMethodAccess
()
{
if
(
version_compare
(
phpversion
(),
'5.3.0'
,
'<'
))
{
$this
->
markTestSkipped
();
}
include_once
__DIR__
.
'/resources/namespace.php'
;
$tpl
=
new
Dwoo_Template_String
(
'{\Dwoo\TestHelper::execute(foo)}'
);
$tpl
->
forceCompilation
();
$this
->
assertEquals
(
'foo'
,
$this
->
dwoo
->
get
(
$tpl
,
array
()));
}
public
function
testNamespaceStaticVarAccess
()
{
if
(
version_compare
(
phpversion
(),
'5.3.0'
,
'<'
))
{
$this
->
markTestSkipped
();
}
include_once
__DIR__
.
'/resources/namespace.php'
;
$tpl
=
new
Dwoo_Template_String
(
'{\Dwoo\TestHelper::$var}'
);
$tpl
->
forceCompilation
();
$this
->
assertEquals
(
'foo'
,
$this
->
dwoo
->
get
(
$tpl
,
array
()));
}
}
function
excessArgsHelper
(
$a
)
{
...
...
@@ -837,11 +858,11 @@ class MethodCallsHelper
public
static
function
staticFoo
(
$bar
,
$baz
)
{
return
"-
$baz$bar
-"
;
}
public
function
_foo
(
$bar
,
$baz
)
{
return
"-
$baz$bar
-"
;
}
public
function
_fooChain
()
{
return
$this
;
}
...
...
tests/resources/namespace.php
0 → 100755
View file @
e7734ba8
<?php
namespace
Dwoo
;
class
TestHelper
{
public
static
$var
=
'foo'
;
public
static
function
execute
(
$arg
)
{
return
$arg
;
}
}
\ No newline at end of file
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