/** * Abstract method for querying InfluxDB * * @param string $query * @param ByConfigBuilder $valuesConfig Override the values section of the hydration * * @return Entity\Result */ protected function query($query, ByConfigBuilder $valuesConfig = null) { $results = $this->getRequest()->request('/query', $this->getRequest()->query()->addQueryPart('q', $query), null); foreach ($results as $mainOffset => $result) { $series = ArrayUtils::targetGet('series', $result, array()); foreach ($series as $offset => $serie) { $columns = ArrayUtils::targetGet('columns', $serie); $values = ArrayUtils::targetGet('values', $serie, array()); $tags = ArrayUtils::targetGet('tags', $serie, array()); foreach ($values as $index => $value) { $values[$index] = array_combine($columns, $value); } $series[$offset] = array('tags' => $tags, 'values' => $values); } $results[$mainOffset]['series'] = $series; } /** @var \Aviogram\InfluxDB\Collection\Result $return */ $collection = ByConfig::hydrate($results, $this->getDefaultHydrateConfig($valuesConfig)); $result = $collection->current(); // Log the error if ($result->hasError() === true) { $this->getLogger()->error($result->getError()); } return $result; }
/** * Builds an config based on the array given * array( * 'entity' => 'full_class_name', * 'is_collection' => true | false, * 'collection_entity' => 'full_class_name', * 'fields' => array( * 'fieldOne' => array( * 'getter' => 'getFieldOne', * 'setter' => 'setFieldOne', * ), * 'fieldTwo' => array( * 'getter' => 'getFieldTwo', * 'setter' => 'setFieldTwo', * 'include' => array( * 'entity' => 'full_class_name', * 'fields' => array( * 'fieldThree' => array( * 'getter' => 'getFieldThree', * 'setter' => 'setFieldThree', * ), * ), * ), * ), * ), * ); * * @param array $config * * @return ByConfigBuilder * * @throws Exception\ConfigFailed When the field definition is not an array * @throws Exception\ConfigFailed When the include definition is not an array * @throws Exception\ConfigFailed When the entity class does not exists * @throws Exception\ConfigFailed When the entity class does not contain the getMethod * @throws Exception\ConfigFailed When the entity class does not contain the setMethod */ public static function createConfigByArray(array $config) { $entity = ArrayUtils::targetGet('entity', $config); $isCollection = ArrayUtils::targetGet('entity', $config, false); $collectionEntity = ArrayUtils::targetGet('collection_entity', $config); $fields = ArrayUtils::targetGet('fields', $config, array()); $config = static::getConfigBuilder($entity, $isCollection, $collectionEntity); foreach ($fields as $fieldName => $field) { if (is_array($field) === false) { throw new Exception\ConfigFailed('ArrayConfig is invalid. Field definition should be an array.', 1); } $getter = ArrayUtils::targetGet('getter', $field); $setter = ArrayUtils::targetGet('setter', $field); $include = ArrayUtils::targetGet('include', $field); if ($include !== null) { if (is_array($include) === false) { throw new Exception\ConfigFailed('ArrayConfig is invalid. Include definition should be an array.', 1); } $include = static::createConfigByArray($include); } $config->addField($fieldName, $getter, $setter, $include); } return $config; }
/** * Get an option from the configuration * * @param string $key This can be a dotted separated string * @param null $default This value will be returned when the key cannot be found * * @return mixed */ protected function getOption($key, $default = null) { return ArrayUtils::targetGet($key, $this->options, $default); }