A jeżeli będę chciął w fuckji dodać opcje && lub || ?
Niestety musiałem sobie poradzić przy pomocy
Jak by ktoś potrzebował:
public function getWhere() {
$this->condition = array(); foreach ($this->where as $whereIndex => $whereValue) {
if ($whereIndex == (count($this->where) - 1
)) { unset($this->where[$whereIndex]["mode"]); }
$this->mode = "";
case "in":
foreach ($whereValue['match'] as $matchIndex => $matchValue) {
$this->conditionIn[] = "\$dataValue['{$whereValue['where']}'] == {$matchValue}";
}
if (isset($this->where[$whereIndex]['mode'])) { $this->mode = (trim(strtolower($this->where[$whereIndex]['mode'])) == "or") ?
' ||' : ' &&'; }
$this->condition[] = implode(' || ', $this->conditionIn) . " " . $this->mode;
break;
case "like":
$this->condition[] = $this->getLike($whereIndex);
break;
case "=":
$this->condition[] = $this->getEqual($whereIndex);
break;
case "<":
$this->condition[] = $this->getLower($whereIndex);
break;
case ">":
$this->condition[] = $this->getGrather($whereIndex);
break;
case ">=":
$this->condition[] = $this->getGratherEqual($whereIndex);
break;
case "<=":
$this->condition[] = $this->getLowerEqual($whereIndex);
break;
case ">=<":
$this->condition[] = $this->getBetweenEqual($whereIndex);
break;
case "><":
$this->condition[] = $this->getBetweenWithOutEqual($whereIndex);
break;
endswitch;
}
$this->condition = implode(" ", $this->condition); foreach ($this->tData as $dataIndex => $dataValue) {
eval("\$evalCondition = $this->condition;"); if ($evalCondition) {
$this->data[] = $dataValue;
}
}
return $this;
}
Przykładowa metoda z eval:
public function getLike($index) {
if (isset($this->where[$index]['mode'])) { $this->mode = (trim(strtolower($this->where[$index]['mode'])) == "or") ?
' ||' : ' &&'; }
return "strpos((string)\$dataValue['{$this->where[$index]['where']}'], (string){$this->where[$index]['match']})";
}
Ten post edytował rad11 4.12.2015, 12:06:46