Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
20e6b007
Commit
20e6b007
authored
Jul 01, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
cc7b1367
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
4 deletions
+68
-4
Expression.php
lib/Doctrine/Expression.php
+55
-4
ExpressionTestCase.php
tests/ExpressionTestCase.php
+13
-0
No files found.
lib/Doctrine/Expression.php
View file @
20e6b007
...
@@ -33,14 +33,65 @@ Doctrine::autoload('Doctrine_Connection_Module');
...
@@ -33,14 +33,65 @@ Doctrine::autoload('Doctrine_Connection_Module');
class
Doctrine_Expression
class
Doctrine_Expression
{
{
protected
$_expression
;
protected
$_expression
;
protected
$_conn
;
public
function
__construct
(
$expr
ession
)
public
function
__construct
(
$expr
,
$conn
=
null
)
{
{
$this
->
_expression
=
$expression
;
$this
->
setExpression
(
$expr
);
if
(
$conn
!==
null
)
{
$this
->
_conn
=
$conn
;
}
}
}
public
function
getConnection
()
{
if
(
!
isset
(
$this
->
_conn
))
{
return
Doctrine_Manager
::
connection
();
}
return
$this
->
_conn
;
}
public
function
setExpression
(
$clause
)
{
$this
->
_expression
=
$this
->
parseClause
(
$clause
);
}
public
function
parseExpression
(
$expr
)
{
$pos
=
strpos
(
$expr
,
'('
);
if
(
$pos
===
false
)
{
return
$expr
;
}
// get the name of the function
$name
=
substr
(
$expr
,
0
,
$pos
);
$argStr
=
substr
(
$expr
,
(
$pos
+
1
),
-
1
);
// parse args
foreach
(
Doctrine_Tokenizer
::
bracketExplode
(
$argStr
,
','
)
as
$arg
)
{
$args
[]
=
$this
->
parseClause
(
$arg
);
}
return
call_user_func_array
(
array
(
$this
->
getConnection
()
->
expression
,
$name
),
$args
);
}
public
function
parseClause
(
$clause
)
{
$e
=
Doctrine_Tokenizer
::
bracketExplode
(
$clause
,
' '
);
foreach
(
$e
as
$k
=>
$expr
)
{
$e
[
$k
]
=
$this
->
parseExpression
(
$expr
);
}
return
implode
(
' '
,
$e
);
}
public
function
getSql
()
public
function
getSql
()
{
{
return
$this
->
_expression
;
return
$this
->
_expression
;
}
}
}
}
tests/ExpressionTestCase.php
View file @
20e6b007
...
@@ -55,6 +55,19 @@ class Doctrine_Expression_TestCase extends Doctrine_UnitTestCase
...
@@ -55,6 +55,19 @@ class Doctrine_Expression_TestCase extends Doctrine_UnitTestCase
$this
->
assertEqual
(
$e
->
name
,
'someone'
);
$this
->
assertEqual
(
$e
->
name
,
'someone'
);
}
}
public
function
testExpressionParserSupportsNumericalClauses
()
{
$e
=
new
Doctrine_Expression
(
'1 + 2'
);
$this
->
assertEqual
(
$e
->
getSql
(),
'1 + 2'
);
}
public
function
testExpressionParserSupportsFunctionComposition
()
{
$e
=
new
Doctrine_Expression
(
"SUBSTRING(CONCAT('some', 'one'), 0, 3)"
);
$this
->
assertEqual
(
$e
->
getSql
(),
"SUBSTR(CONCAT('some', 'one'), 0, 3)"
);
}
}
}
class
ExpressionTest
extends
Doctrine_Record
class
ExpressionTest
extends
Doctrine_Record
{
{
...
...
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