00001 <?php
00027 include_once(ZIGROOT.DRS.MOD_KEY_NAME_EXPLICIT.DRS."orm".DRS."nomagic.php");
00031 class zOrm_magic extends zOrm_noMagic{
00036 function lexize($clause, $args){
00037
00038 $opcode = array(
00039 'equals',
00040 'greaterthan',
00041 'greaterthanequals',
00042 'lessthan',
00043 'lessthanquals',
00044 'like',
00045 'notequals'
00046 );
00047 foreach($opcode as $op)array_push($opcode, 'may'.$op);
00048 $opcode = array_reverse($opcode);
00049 for($i=0;$i<count($opcode);$i++)$opcode[$i] = strrev($opcode[$i]);
00050 $var = preg_match('~('.implode('|', $opcode).')?(\w+)~i', strrev($clause), $m);
00051
00052 $opcode = array(
00053 'equals' => '=',
00054 'notequals' => '!=',
00055 'greaterthan' => '>',
00056 'greaterthanequals' => '>=',
00057 'lessthan' => '<',
00058 'lessthanequals' => '<=',
00059 'like' => 'LIKE'
00060 );
00061 foreach($opcode as $op => $smb)$opcode['may'.$op] = $smb;
00062
00063 for($i=0;$i<count($m);$i++)$m[$i] = strrev($m[$i]);
00064 if(!strlen($m[1]))$m[1] = 'equals';
00065 $lex = new stdClass();
00066 (eregi('may', $m[1])) ? $lex->may=false : $lex->may=true;
00067 $lex->op = $opcode[$m[1]];
00068 $lex->col = $m[2];
00069 $lex->val = $args[0];
00070
00071 return $lex;
00072 }
00077 function __call($methodName, $args, &$return){
00078 switch(true){
00079 case (preg_match('~identifyBy(\w+)~i', $methodName, $m) >= 1):
00080 if(!isset($args[0])){
00081 perror('<code>zigmoyd.orm.'.$methodName.'($value)</code><br />you must supply at least 1 Argument No argument has been Suplied');
00082 $return = false;
00083 return true;
00084 }
00085 if(eregi('pk', $m[1])){
00086 $val = array();
00087 $listArgs = func_get_args();
00088 $listArgs = $listArgs[1];
00089 foreach($listArgs as $value){
00090 if(!is_array($value)){
00091 $val[] = $value;
00092 }else{
00093 foreach($value as $innerVal){
00094 $val[] = $innerVal;
00095 }
00096 }
00097 }
00098 }else{
00099 $val = $args[0];
00100 }
00101 $lex = $this->lexize(strtolower($m[1]), $args);
00102 $return = $this->identifyBy($lex->col, $val, $lex->op, $lex->may);
00103 return true;
00104 break;
00105 case (preg_match('~set(\w+)~i', $methodName, $m) >= 1):
00106 if(!isset($args[0])){
00107 perror('<code>zigmoyd.orm.'.$methodName.'($value)</code><br />you must supply 1 Argument No argument has been Suplied');
00108 $return = false;
00109 return true;
00110 }
00111 $return = $this->set($m[1], $args[0]);
00112 return true;
00113 break;
00114 case (preg_match('~fetch(\w+)As(\w+)~i', $methodName, $m) >= 1):
00115 if(isset($this->lex['alias'][strtolower("$m[1]As$m[2]")])){
00116 if(!isset($args[0]))$args[0] = true;
00117 $return = $this->fetch(strtolower("$m[1]As$m[2]"), $args[0]);
00118 return true;
00119 }
00120 if(eregi('all', $m[1])){
00121 perror("use fetchAll() Instead, cause fetchAllAsSomeThing() doesn't have a meaning");
00122 $return = false;
00123 return true;
00124 }
00125 $return = $this->fetchAs($m[1], $m[2]);
00126 return true;
00127 break;
00128 case (preg_match('~fetch(\w+)~i', $methodName, $m) >= 1):
00129 if(!isset($args[0]))$args[0] = true;
00130 $return = $this->fetch($m[1], $args[0]);
00131 return true;
00132 break;
00133 case (preg_match('~find(\w+)~i', $methodName, $m) >= 1):
00134 if(isset($args[1]) && strlen($args[1])){
00135 $ordWay = isset($args[2]) ? $args[2] : ZIGORM_ORDER_ASC;
00136 $this->order($args[1], $ordWay);
00137 }
00138 if(isset($args[0]) && strlen($args[0])){
00139 $return = $this->find($m[1], $args[0]);
00140 }else{
00141 $return = $this->find($m[1]);
00142 }
00143 return true;
00144 break;
00145 case (preg_match('~get(\w+)As(\w+)~i', $methodName, $m) >= 1):
00146 perror('<code>zigmoyd.orm.'.$this->__struct->alias.'.'.$methodName.'()</code><br />Method doesn\'t exists Plese Check the Documentation Properly<br />However I think You meant find or fetch instead of get');
00147 return false;
00148 break;
00149 default:
00150 perror('<code>zigmoyd.orm.'.$this->__struct->alias.'.'.$methodName.'()</code><br />Method doesn\'t exists Plese Check the Documentation Properly');
00151 exit;
00152 }
00153 }
00164 function fetchCol(){}
00171 function fetchColAsAlias(){}
00183 function setCol($value){}
00196 function identifyByCol($value){}
00224 function identifyByColOp($value){}
00255 function findCol1ByCol2($value, $indxCol=null, $ordCol=null, $ordMode=ZIGORM_ORDER_ASC){}
00288 function findCol1ByCol2Op($value, $indxCol=null, $ordCol=null, $ordMode=ZIGORM_ORDER_ASC){}
00305 function findCol($indxCol=null, $ordCol=null, $ordMode=ZIGORM_ORDER_ASC){}
00306 }
00307 if(function_exists('overload')){
00308 overload('zOrm_magic');
00309 }
00313 class zOrm_inc extends zOrm_magic{
00314
00315 }
00317 ?>