Beispiel #1
0
 public function sort($object)
 {
     $object = Helper::jsonDecode($object, true);
     $this->_sortKey = Helper::firstKey($object);
     $this->_sortVal = $object[$this->_sortKey];
     uasort($this->rows, array('\\rollingWolf\\QueryablePHP\\DB\\Result', 'cmp'));
     return $this;
 }
 public static function open($config)
 {
     $configValidation = array('dbDir' => array('filter' => FILTER_CALLBACK, 'flags' => FILTER_NULL_ON_FAILURE, 'options' => function ($path) {
         return Helper::pathValidate($path, realpath('.'));
     }), 'dbName' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW, 'default' => 'database.db'), 'useGzip' => FILTER_VALIDATE_BOOLEAN, 'data' => array('filter' => FILTER_CALLBACK, 'options' => function ($json) {
         return Helper::jsonValidate($json, false);
     }));
     $newConfig = filter_var_array($config, $configValidation);
     return new QueryablePHPDB($newConfig);
 }
Beispiel #3
0
 public function load($data)
 {
     $rows = Helper::jsonDecode($data);
     foreach ($rows as $row) {
         if (array_key_exists('_id', $row)) {
             if ($row['_id'] > $this->ID) {
                 $this->setID($row['_id']);
             }
             $this->rows[$row['_id']] = $row;
         } else {
             $this->rows[++$this->ID] = $row;
         }
     }
 }
Beispiel #4
0
 private function _doQuery()
 {
     $result = $this->master->getRows();
     $clauses = @Helper::jsonDecode(func_get_arg(0));
     if (is_array($clauses) && Helper::firstKey($clauses) === null) {
         return $result;
     }
     foreach ($clauses as $key => $clause) {
         $clausetype = $this->_detectClauseType($key, $clause);
         switch ($clausetype) {
             case self::CLAUSE_NORMAL:
                 $result = $this->_matchingRowsNormal('{"key": "' . $key . '", "value": "' . $clause . '"}', $result);
                 break;
             case self::CLAUSE_CONDITIONAL:
                 $result = $this->_matchingRowsConditional('{"key": "' . $key . '", "value": ' . json_encode($clause) . '}', $result);
                 break;
             case self::CLAUSE_OR:
                 $result = $this->_matchingRowsOr($clause, $result);
                 break;
             case self::CLAUSE_AND:
                 foreach ($clause as $subclause) {
                     $result = $this->_matchingRowsAnd($subclause, $result);
                 }
             default:
                 break;
         }
     }
     return $result;
 }