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
29a6d2ef
Commit
29a6d2ef
authored
May 11, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added new methods
parent
f4ad789a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
152 additions
and
8 deletions
+152
-8
Tokenizer.php
lib/Doctrine/Tokenizer.php
+152
-8
No files found.
lib/Doctrine/Tokenizer.php
View file @
29a6d2ef
...
...
@@ -39,6 +39,21 @@ class Doctrine_Tokenizer
public
function
tokenize
()
{
}
/**
* trims brackets
*
* @param string $str
* @param string $e1 the first bracket, usually '('
* @param string $e2 the second bracket, usually ')'
*/
public
static
function
bracketTrim
(
$str
,
$e1
=
'('
,
$e2
=
')'
)
{
if
(
substr
(
$str
,
0
,
1
)
==
$e1
&&
substr
(
$str
,
-
1
)
==
$e2
)
{
return
substr
(
$str
,
1
,
-
1
);
}
else
{
return
$str
;
}
}
/**
* bracketExplode
...
...
@@ -63,25 +78,154 @@ class Doctrine_Tokenizer
*/
public
static
function
bracketExplode
(
$str
,
$d
=
' '
,
$e1
=
'('
,
$e2
=
')'
)
{
if
(
is_array
(
$d
))
{
$a
=
preg_split
(
'/('
.
implode
(
'|'
,
$d
)
.
')/'
,
$str
);
if
(
is_array
(
$d
))
{
$a
=
preg_split
(
'/('
.
implode
(
'|'
,
$d
)
.
')/'
,
$str
);
$d
=
stripslashes
(
$d
[
0
]);
}
else
{
}
else
$a
=
explode
(
$d
,
$str
);
$i
=
0
;
$term
=
array
();
foreach
(
$a
as
$key
=>
$val
)
{
if
(
empty
(
$term
[
$i
]))
{
$term
[
$i
]
=
trim
(
$val
);
$s1
=
substr_count
(
$term
[
$i
],
$e1
);
$s2
=
substr_count
(
$term
[
$i
],
$e2
);
if
(
$s1
==
$s2
)
{
$i
++
;
}
}
else
{
$term
[
$i
]
.=
$d
.
trim
(
$val
);
$c1
=
substr_count
(
$term
[
$i
],
$e1
);
$c2
=
substr_count
(
$term
[
$i
],
$e2
);
if
(
$c1
==
$c2
)
{
$i
++
;
}
}
}
return
$term
;
}
/**
* quoteExplode
*
* example:
*
* parameters:
* $str = email LIKE 'John@example.com'
* $d = ' AND '
*
* would return an array:
* array("email", "LIKE", "'John@example.com'")
*
* @param string $str
* @param string $d the delimeter which explodes the string
*/
public
static
function
quoteExplode
(
$str
,
$d
=
' '
)
{
if
(
is_array
(
$d
))
{
$a
=
preg_split
(
'/('
.
implode
(
'|'
,
$d
)
.
')/'
,
$str
);
$d
=
stripslashes
(
$d
[
0
]);
}
else
$a
=
explode
(
$d
,
$str
);
$i
=
0
;
$term
=
array
();
foreach
(
$a
as
$key
=>
$val
)
{
foreach
(
$a
as
$key
=>
$val
)
{
if
(
empty
(
$term
[
$i
]))
{
$term
[
$i
]
=
trim
(
$val
);
if
(
!
(
substr_count
(
$term
[
$i
],
"'"
)
&
1
))
{
$i
++
;
}
}
else
{
$term
[
$i
]
.=
$d
.
trim
(
$val
);
if
(
!
(
substr_count
(
$term
[
$i
],
"'"
)
&
1
))
{
$i
++
;
}
}
$c1
=
substr_count
(
$term
[
$i
],
$e1
);
$c2
=
substr_count
(
$term
[
$i
],
$e2
);
}
return
$term
;
}
/**
* sqlExplode
*
* 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
sqlExplode
(
$str
,
$d
=
' '
,
$e1
=
'('
,
$e2
=
')'
)
{
if
(
$d
==
' '
)
{
$d
=
array
(
' '
,
'\s'
);
}
if
(
is_array
(
$d
))
{
if
(
in_array
(
' '
,
$d
))
{
$d
[]
=
'\s'
;
}
$str
=
preg_split
(
'/('
.
implode
(
'|'
,
$d
)
.
')/'
,
$str
);
$d
=
stripslashes
(
$d
[
0
]);
}
else
{
$str
=
explode
(
"
$d
"
,
$str
);
}
$i
=
0
;
$term
=
array
();
foreach
(
$str
as
$key
=>
$val
)
{
if
(
empty
(
$term
[
$i
]))
{
$term
[
$i
]
=
trim
(
$val
);
$s1
=
substr_count
(
$term
[
$i
],
$e1
);
$s2
=
substr_count
(
$term
[
$i
],
$e2
);
if
(
substr
(
$term
[
$i
],
0
,
1
)
==
'('
)
{
if
(
$s1
==
$s2
)
{
$i
++
;
}
}
else
{
if
(
!
(
substr_count
(
$term
[
$i
],
"'"
)
&
1
)
&&
!
(
substr_count
(
$term
[
$i
],
"
\"
"
)
&
1
))
{
$i
++
;
}
}
}
else
{
$term
[
$i
]
.=
$d
.
trim
(
$val
);
$c1
=
substr_count
(
$term
[
$i
],
$e1
);
$c2
=
substr_count
(
$term
[
$i
],
$e2
);
if
(
$c1
==
$c2
)
{
$i
++
;
if
(
substr
(
$term
[
$i
],
0
,
1
)
==
'('
)
{
if
(
$c1
==
$c2
)
{
$i
++
;
}
}
else
{
if
(
!
(
substr_count
(
$term
[
$i
],
"'"
)
&
1
)
&&
!
(
substr_count
(
$term
[
$i
],
"
\"
"
)
&
1
))
{
$i
++
;
}
}
}
}
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