From 18944f39c6ce3917b8c777b7ce64eaf054e96003 Mon Sep 17 00:00:00 2001 From: zYne Date: Sat, 21 Apr 2007 22:36:46 +0000 Subject: [PATCH] --- lib/Doctrine/DataDict/Mysql.php | 4 +- lib/Doctrine/Tokenizer.php | 89 +++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 lib/Doctrine/Tokenizer.php diff --git a/lib/Doctrine/DataDict/Mysql.php b/lib/Doctrine/DataDict/Mysql.php index d8cd74160..63fda3fb7 100644 --- a/lib/Doctrine/DataDict/Mysql.php +++ b/lib/Doctrine/DataDict/Mysql.php @@ -385,7 +385,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict */ public function getCharsetFieldDeclaration($charset) { - return 'CHARACTER SET '.$charset; + return 'CHARACTER SET ' . $charset; } /** * Obtain DBMS specific SQL code portion needed to set the COLLATION @@ -397,7 +397,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict */ public function getCollationFieldDeclaration($collation) { - return 'COLLATE '.$collation; + return 'COLLATE ' . $collation; } /** * Obtain DBMS specific SQL code portion needed to declare an integer type diff --git a/lib/Doctrine/Tokenizer.php b/lib/Doctrine/Tokenizer.php new file mode 100644 index 000000000..30b28cf1b --- /dev/null +++ b/lib/Doctrine/Tokenizer.php @@ -0,0 +1,89 @@ +. + */ + +/** + * Doctrine_Tokenizer + * + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision: 1080 $ + * @author Konsta Vesterinen + */ +class Doctrine_Tokenizer +{ + public function __construct() + { + + } + public function tokenize() + { + + } + /** + * bracketExplode + * + * example: + * + * parameters: + * $str = (age < 20 AND age > 18) AND email LIKE 'John@example.com' + * $d = ' AND ' + * $e1 = '(' + * $e2 = ')' + * + * would return an array: + * array("(age < 20 AND age > 18)", + * "email LIKE 'John@example.com'") + * + * @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 ')' + * + */ + public static function bracketExplode($str, $d = ' ', $e1 = '(', $e2 = ')') + { + 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) { + if (empty($term[$i])) { + $term[$i] = trim($val); + } else { + $term[$i] .= $d . trim($val); + } + $c1 = substr_count($term[$i], $e1); + $c2 = substr_count($term[$i], $e2); + + if($c1 == $c2) { + $i++; + } + } + return $term; + } +}