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
a12e74d8
Commit
a12e74d8
authored
Aug 07, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
81800849
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
9 deletions
+103
-9
Tokenizer.php
lib/Doctrine/Tokenizer.php
+103
-9
No files found.
lib/Doctrine/Tokenizer.php
View file @
a12e74d8
...
...
@@ -34,7 +34,7 @@ class Doctrine_Tokenizer
{
public
function
__construct
()
{
}
public
function
tokenize
()
{
...
...
@@ -181,14 +181,19 @@ class Doctrine_Tokenizer
*/
public
static
function
sqlExplode
(
$str
,
$d
=
' '
,
$e1
=
'('
,
$e2
=
')'
)
{
if
(
$d
==
' '
)
{
$d
=
array
(
' '
,
'\s'
);
}
if
(
$d
==
' '
)
{
$d
=
array
(
' '
,
'\s'
);
}
if
(
is_array
(
$d
))
{
if
(
in_array
(
' '
,
$d
))
{
$d
[]
=
'\s'
;
}
$str
=
preg_split
(
'/('
.
implode
(
'|'
,
$d
)
.
')/'
,
$str
);
$d
=
array_map
(
'preg_quote'
,
$d
);
if
(
in_array
(
' '
,
$d
))
{
$d
[]
=
'\s'
;
}
$split
=
'§('
.
implode
(
'|'
,
$d
)
.
')§'
;
$str
=
preg_split
(
$split
,
$str
);
$d
=
stripslashes
(
$d
[
0
]);
}
else
{
$str
=
explode
(
$d
,
$str
);
...
...
@@ -208,7 +213,7 @@ class Doctrine_Tokenizer
if
(
$s1
==
$s2
)
{
$i
++
;
}
}
else
{
}
else
{
if
(
!
(
substr_count
(
$term
[
$i
],
"'"
)
&
1
)
&&
!
(
substr_count
(
$term
[
$i
],
"
\"
"
)
&
1
))
{
$i
++
;
...
...
@@ -233,4 +238,93 @@ class Doctrine_Tokenizer
}
return
$term
;
}
/**
* clauseExplode
*
* explodes a string into array using custom brackets and
* quote delimeters
*
*
* example:
*
* parameters:
* $str = "(age < 20 AND age > 18) AND name LIKE 'John Doe'"
* $d = ' '
* $e1 = '('
* $e2 = ')'
*
* would return an array:
* array('(age < 20 AND age > 18)',
* 'name',
* 'LIKE',
* 'John Doe')
*
* @param string $str
* @param string $d the delimeter which explodes the string
* @param string $e1 the first bracket, usually '('
* @param string $e2 the second bracket, usually ')'
*
* @return array
*/
public
static
function
clauseExplode
(
$str
,
array
$d
,
$e1
=
'('
,
$e2
=
')'
)
{
if
(
is_array
(
$d
))
{
$d
=
array_map
(
'preg_quote'
,
$d
);
if
(
in_array
(
' '
,
$d
))
{
$d
[]
=
'\s'
;
}
$split
=
'§('
.
implode
(
'|'
,
$d
)
.
')§'
;
$str
=
preg_split
(
$split
,
$str
,
-
1
,
PREG_SPLIT_DELIM_CAPTURE
);
}
$i
=
0
;
$term
=
array
();
foreach
(
$str
as
$key
=>
$val
)
{
if
(
$key
&
1
)
{
if
(
isset
(
$term
[(
$i
-
1
)])
&&
!
is_array
(
$term
[(
$i
-
1
)]))
{
$term
[(
$i
-
1
)]
=
array
(
$term
[(
$i
-
1
)],
$val
);
}
continue
;
}
if
(
empty
(
$term
[
$i
]))
{
$term
[
$i
]
=
trim
(
$val
);
$s1
=
substr_count
(
$term
[
$i
],
$e1
);
$s2
=
substr_count
(
$term
[
$i
],
$e2
);
if
(
strpos
(
$term
[
$i
],
'('
)
!==
false
)
{
if
(
$s1
==
$s2
)
{
$i
++
;
}
}
else
{
if
(
!
(
substr_count
(
$term
[
$i
],
"'"
)
&
1
)
&&
!
(
substr_count
(
$term
[
$i
],
"
\"
"
)
&
1
))
{
$i
++
;
}
}
}
else
{
$term
[
$i
]
.=
$str
[(
$key
+
1
)]
.
trim
(
$val
);
$c1
=
substr_count
(
$term
[
$i
],
$e1
);
$c2
=
substr_count
(
$term
[
$i
],
$e2
);
if
(
strpos
(
$term
[
$i
],
'('
)
!==
false
)
{
if
(
$c1
==
$c2
)
{
$i
++
;
}
}
else
{
if
(
!
(
substr_count
(
$term
[
$i
],
"'"
)
&
1
)
&&
!
(
substr_count
(
$term
[
$i
],
"
\"
"
)
&
1
))
{
$i
++
;
}
}
}
}
$term
[
$i
-
1
]
=
array
(
$term
[
$i
-
1
],
''
);
return
$term
;
}
}
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