dataSource = $dataSource; } public function from($target, array $fields = null) { if ($fields !== null) { throw new InvalidArgumentException('Fields are not applicable to this kind of query'); } try { $this->base = $target instanceof MacroTemplate ? $target : new MacroTemplate((string) $target); } catch (InvalidArgumentException $e) { throw new InvalidArgumentException('Bad target', $e); } return $this; } public function applyFilter(Filter $filter) { throw new NotImplementedError(__METHOD__); } public function setFilter(Filter $filter) { throw new NotImplementedError(__METHOD__); } public function getFilter() { throw new NotImplementedError(__METHOD__); } public function addFilter(Filter $filter) { throw new NotImplementedError(__METHOD__); } public function where($condition, $value = null) { $this->filter[$condition] = preg_replace('/[^a-zA-Z0-9\*\-:]/', '_', $value); return $this; } public function fetchAll() { $result = []; foreach ($this->fetchColumn() as $metric) { $result[] = (object) ['metric' => $metric]; } return $result; } public function fetchRow() { $result = $this->fetchColumn(); return empty($result) ? false : (object) ['metric' => $result[0]]; } public function fetchColumn() { $res = Json::decode($this->dataSource->getClient()->request( Url::fromPath('metrics/expand', ['query' => $this->base->resolve($this->filter, '*')]) )); natsort($res->results); return array_values($res->results); } public function fetchOne() { $result = $this->fetchColumn(); return empty($result) ? false : $result[0]; } public function fetchPairs() { throw new NotImplementedError(__METHOD__); } }