private function route() { //Route determination $url = Tools::getParam("url", null); Log::write('MicroMuffin::route : url called is ' . $url); $route = Router::get(!is_null($url) ? $url : ""); if (!is_null($route)) { $this->route = $route; } else { header("HTTP/1.0 404 Not Found"); $e = new Error("Page not found", "The page you are looking for doesn't exist."); $e->display(); } }
/** * @param array|string $where_clause * @param array $order * @param int $where_mode * @throws \Exception * @return static[] */ public static function where($where_clause, $order = null, $where_mode = self::WHERE_MODE_AND) { $class = strtolower(get_called_class()); $proc = static::$_procstock_all != null ? static::$_procstock_all : 'getall' . $class . 's'; $pdo = PDOS::getInstance(); $sWhereClause = ''; if (is_array($where_clause)) { $sSeparator = $where_mode == self::WHERE_MODE_OR ? 'OR' : 'AND'; //array(array(field, operator, value), array(field, operator, value)) foreach ($where_clause as $aCondition) { if (is_array($aCondition) && count($aCondition) == 3) { $column = $aCondition[0]; $operator = $aCondition[1]; $value = $aCondition[2]; if (in_array($column, static::$_fields)) { $valid_operators = array('=', '>', '<', '>=', '<=', '<>', 'IS', 'IS NOT', 'LIKE', 'IN'); if (in_array($operator, $valid_operators)) { if (is_bool($value)) { $value = $value ? 'true' : 'false'; } else { if (is_string($value)) { $value = pg_escape_string($value); $value = '\'' . $value . '\''; } else { if (is_null($value)) { $value = 'NULL'; } else { if (is_array($value) && $operator == 'IN') { array_map(function ($item) { if (!is_int($item)) { throw new \Exception('Readeable::where : all items on IN array must be integers'); } }, $value); $sInClause = '('; foreach ($value as $item) { $sInClause .= $item . ','; } $value = substr($sInClause, 0, -1) . ')'; } } } } $sWhereClause .= $column . ' ' . $operator . ' ' . $value . ' ' . $sSeparator . ' '; } else { throw new \Exception('Readable::where : operator ' . $operator . ' is not a valid operator. Authorized operators are : ' . implode(', ', $valid_operators)); } } else { throw new \Exception('Readable::where : ' . $column . ' is not a column of table ' . static::getTableName()); } } else { throw new \Exception('Readable::where : Conditions must be arrays of this kind array(column, operator, value)'); } } //Removing that last AND or OR $sWhereClause = substr($sWhereClause, 0, -1 * (strlen($sSeparator) + 2)); } else { Log::write('Warning ! Readable::where(string) is deprecated ! Please use Readable::where(Array) or stored procedures for advanced queries.'); $sWhereClause = $where_clause; } $order = self::handleOrder($order); if (!is_null($order)) { $order = ' ORDER BY ' . $order; } $query = $pdo->prepare('SELECT * FROM ' . $proc . '() WHERE ' . $sWhereClause . $order); $query->execute(); $datas = $query->fetchAll(); $outputs = array(); foreach ($datas as $d) { $object = new $class(); self::hydrate($object, $d); $outputs[] = $object; } return $outputs; }