Extracts quads from query, if available.

@param string $query

@return array
346543
public function extractQuads($query)
    {
        $quads = [];

        /**
         * Matches the following pattern: Graph <http://uri/> { ?s ?p ?o }
         * Whereas ?s ?p ?o stands for any triple, so also for an URI. It also matches multi line strings
         * which have { and triple on different lines.
         */
        $result = preg_match_all('/GRAPH\s*\<(.*?)\>\s*\{\n*\s*(.*?)\s*\n*\}/si', $query, $matches);

        // if no errors occour and graphs and triple where found
        if (false !== $result
            && true === isset($matches[1])
            && true === isset($matches[2])) {
            foreach ($matches[1] as $key => $graph) {
                // parse according triple string, for instance: <http://saft/test/s1> dc:p1 <http://saft/test/o1>
                // and extract S, P and O.
                $triplePattern = $this->extractTriplePattern($matches[2][$key]);

                // TODO Handle case that more than one triple pattern was found

                if (0 == count($triplePattern)) {
                    throw new \Exception('Quad related part of the query is invalid: '.$matches[2][$key]);
                }

                $quad = $triplePattern[0];
                $quad['g'] = $graph;
                $quad['g_type'] = 'uri';

                $quads[] = $quad;
            }
        }

        return $quads;
    }
112616
public function extractFromQuery(ParameterBag $query)
    {
        $trackingParameters = [];

        if (
            (null !== $cuv = $query->get('cuv'))
            && (preg_match('`^(?<c>[a-z0-9]+)~(?<u>[a-z0-9]+)~(?<v>[a-z0-9]+)$`i', $cuv, $matches))
        ) {
            $trackingParameters['c'] = $matches['c'];
            $trackingParameters['u'] = $matches['u'];
            $trackingParameters['v'] = $matches['v'];
        }

        return $trackingParameters;
    }
968229
public function getAllAsArray($query = null)
    {
        return [
            'skips' => $this->getSkipsCount($query),
            'success' => $this->getSuccessCount($query),
            'failures' => $this->getFailuresCount($query),
            'noops' => $this->getNoopsCount($query),
        ];
    }
425137
public function allArray(Query $query = null) {
		$iterator = $this->getIterator();
		$array = $iterator->all($query);
		$array = $this->forgeEntity($array);
		return $array;
	}
150443
public function getAllAsArray($query = null)
    {
        return [
            'unchangedCount' => $this->getUnchangedCount($query),
            'changedCount' => $this->getChangedCount($query),
            'failedCount' => $this->getFailedCount($query),
            'nodesCount' => $this->getNodesCount($query),
            'nodesCountByOS' => $this->getNodesCountByOS($query),
            'nodesPercentageByOS' => $this->getNodesPercentageByOS($query),
            'osCount' => $this->getOSCount($query),
            'recentlyRebootedNodes' => $this->getRecentlyRebootedNodes($query),
        ];
    }
1042140
public function findTypes($query)
    {
        $facet = new TermsAggregation('type');
        $facet->setField('_type');
        $facet->setSize(200);
        $query->aggregate($facet);
        return $query->limit(1);
    }
786773
protected function parseRQL($query) {
    if (strlen($query) > 0) {
      // replace rql operators
      $operatorMap = ['eq' => '=', 'ne' => '!=', 'lt' => '<', 'lte' => '<=',
          'gt' => '>', 'gte' => '>=', 'in' => 'in', 'match' => 'regexp', '=' => '='];
      $combineMap = ['|' => 'OR', '&' => 'AND'];
      $queryType = $this->getQueryType();
      $mapper = self::getMapper($queryType);
      $persistenceFacade = ObjectFactory::getInstance('persistenceFacade');
      foreach ($operatorMap as $rqlOp => $sqlOp) {
        // add '=' separator for letter-only operators
        $operator = preg_match('/^[a-zA-Z]+$/', $rqlOp) ? '='.$rqlOp.'=' : $rqlOp;
        $query = preg_replace_callback('/([^ <>!=|&\(\)]+) ?'.$operator.' ?([^ <>!=|&\(\)]+)/', function ($match)
                use($rqlOp, $sqlOp, $mapper, $persistenceFacade) {
          $typeAttr = $match[1];
          $value = preg_replace('/^[\'"]|[\'"]$/', '', $match[2]);

          // try to determine value type
          list($typeOrRole, $attribute) = explode('.', preg_replace('/[`"\'\(\)]/', '', $typeAttr), 2);
          $attributeDef = null;
          if ($persistenceFacade->isKnownType($typeOrRole) &&
                  $persistenceFacade->getFullyQualifiedType($typeOrRole) == $mapper->getType() && $mapper->hasAttribute($attribute)) {
            $attributeDef = $mapper->getAttribute($attribute);
          }
          elseif ($mapper->hasRelation($typeOrRole)) {
            $otherMapper = self::getMapper($mapper->getRelation($typeOrRole)->getOtherType());
            $attributeDef = $otherMapper->hasAttribute($attribute) ? $otherMapper->getAttribute($attribute) : null;
          }
          $attributeType = $attributeDef != null ? strtolower($attributeDef->getType()) : null;
          $isNumber = $attributeType == 'integer' || $attributeType == 'float';

          // strip slashes from regexp
          if ($sqlOp === 'regexp') {
            $value = preg_replace('/^\/|\/[a-zA-Z]*$/', '', $value);
          }

          // handle null values
          if ($value === 'null') {
            $sqlOp = $sqlOp == '=' ? 'is' : 'is not';
            $replace = $typeAttr.' '.$sqlOp.' null';
          }
          else {
            // quote value according to type
            $replace = $typeAttr.' '.$sqlOp.' ';
            if ($rqlOp == 'in') {
              $replace .= '('.($isNumber ? $value : join(',', array_map([$mapper, 'quoteValue'], explode(',', $value)))).')';
            }
            else {
              $replace .= $isNumber ? $value : $mapper->quoteValue($value);
            }
          }

          return $replace;
        }, $query);
      }
      foreach ($combineMap as $rqlOp => $sqlOp) {
        $query = str_replace($rqlOp, ' '.$sqlOp.' ', $query);
      }
    }
    return $query;
  }
499093
public function runCount($query)
	{
		if (isset($this->stored_query_totals[md5(serialize($query))])) {
			return $this->stored_query_totals[md5(serialize($query))];
		}
		
		$query['terms'] = trim($query['terms']);
		if (isset($query['numericFilters'])) {
			$query['numericFilters'] = implode(',', $query['numericFilters']);
		}
		if (isset($query['facets'])) {
			$query['facets'] = implode(',', $query['facets']);
		}
		
		try {
			return array_get($this->getIndex()->search(array_get($query, 'terms'), array_get($query, 'query')), 'nbHits');
		} catch (\Exception $e) {
			return 0;
		}
	}
1090401
public static function executeRows(string $query): array
  {
    self::logQuery($query);

    return self::$dl->executeRows($query);
  }
831223
public static function plainSql($query)
    {
        $query = static::getBaseQuery($query);
        return self::inlineBindings($query->toSql(), $query->getBindings());
    }
510540
protected function processMultipleResults($query)
    {
        if (!empty($this->fetchRefs)) {
            $models = [];
            foreach ($query->fetchAll() as $model) {
                $models[] = $this->populateModelFromJoin($model);
            }
        } else {
            $models = $query->fetchAllClass($this->modelClass);
        }
        if (isset($this->manager)) {
            foreach ($models as $model) {
                $this->manager->manageModel($model);
            }
        }
        $this->fetchReferences(false);
        return $models;
    }
537376
protected function parseSubSelect($query) {
        if ($query instanceof self) {
            $query->columns = [$query->columns[0]];

            return [$query->toSql(), $query->getBindings()];
        } elseif (is_string($query)) {
            return [$query, []];
        } else {
            throw new \InvalidArgumentException();
        }
    }
666871
public static function query($query = [])
    {
        if (func_num_args()) {
            static::$_query[static::class] = is_array($query) ? $query : [];
        }
        return isset(static::$_query[static::class]) ? static::$_query[static::class] : [];
    }
105681
protected function extractResult($query)
    {
        $result = null;
        $i = 0;
        $hits                  = sizeof($query['hits']['hits']);
        $hit                   = $query['hits']['hits'];
        $result['searchfound'] = $hits;
        while ($i < $hits) {
            $result['result'][$i] = $query['hits']['hits'][$i]['_source'];
            
            $i++;
        }
        return $result;
    }
159781
public function run($query)
    {
        $result = array();
        $result['draw'] = $query['draw'];
        $result['recordsTotal'] = $this->data->count();
        $filtered = $this->filter($query);
        $this->sort($filtered, $query);
        $result['recordsFiltered'] = $filtered->count();
        $models = $filtered->limit($query['length'], $query['start']);
        $result['data'] = array();
        foreach ($models->getModels() as $model) {
            $item = array();
            foreach ($this->columns as $index => $column) {
                $item[] = $this->getFiledValue($model, $index);
            }
            $result['data'][] = $item;
        }

        return $result;
    }
11220
public function pairs(string $query, array $params = []): array
	{
		return $this->all($query, $params, PDO::FETCH_KEY_PAIR);
	}
1139467
private static function splitQueryNames($query) {
        $resultado = [];
        if (($left = (stripos($query, "`"))) !== false) {
            while ($left !== false) {
                //echo "<pre>" . print_r($query, true) . "</pre>";
                if (($right = stripos($query, "`", $left + 1)) === false) {
                    $right = strlen($query);
                }
                $piece = substr($query, $left + 1, $right - ($left + 1));
                $resultado[] = $piece;
                $query = substr($query, $right + 1);
                //echo "<pre>" . print_r(['prefix' => config("sirgrimorum.crudgenerator.trans_prefix"), 'lenprefix' => strlen(config("sirgrimorum.crudgenerator.trans_prefix")), 'left' => $left, 'rigth' => $right, 'piece' => $piece, 'lenpiece' => strlen($piece), 'csss' => $item], true) . "</pre>";
                $left = (stripos($query, "`"));
            }
        }
        return $resultado;
    }