Get

@param array $options
@return mixed
@throws \Exception
514633
final public function get($options = []) {
		// process parameters
		$parameters = [];
		$options['where'] = $options['where'] ?? [];
		if (!empty($this->parameters)) {
			$this->parameters = \Object\Data\Common::processDomainsAndTypes($this->parameters);
			foreach ($this->parameters as $k => $v) {
				// if we have a parameter
				if (array_key_exists($k, $options['where'])) {
					if (!empty($v['multiple_column'])) {
						if (!is_array($options['where'][$k])) $options['where'][$k] = [$options['where'][$k]];
						$parameters[$k] = [];
						foreach ($options['where'][$k] as $v2) {
							$result = \Object\Table\Columns::validateSingleColumn($k, $v, $v2);
							if (!$result['success']) {
								Throw new \Exception("Datasource: " . get_called_class() . " parameter: {$k} error" . implode(', ', $result['error']));
							} else {
								$parameters[$k][] = $result['data'][$k];
							}
						}
					} else {
						$result = \Object\Table\Columns::validateSingleColumn($k, $v, $options['where'][$k]);
						if (!$result['success']) {
							Throw new \Exception("Datasource: " . get_called_class() . " parameter: {$k} error" . implode(', ', $result['error']));
						} else {
							$parameters[$k] = $result['data'][$k];
						}
					}
				}
				// required
				if (!empty($v['required']) && empty($parameters[$k])) {
					return [];
					//Throw new \Exception("Datasource: " . get_called_class() . " parameter: {$k} error" . i18n(null, \Object\Content\Messages::required_field));
				}
			}
		}
		// we need to push existing values to parameters
		if (!empty($options['existing_values']) && !empty($this->parameters['existing_values'])) {
			$parameters['existing_values'] = $options['existing_values'];
		}
		$where = $options['where'] ?? [];
		unset($options['where']);
		// process primary model
		if (!empty($this->primary_model)) {
			$model = new $this->primary_model();
			$this->db_link = $model->db_link;
			if (empty($this->pk)) $this->pk = $model->pk;
			$this->cache_tags = array_merge($this->cache_tag ?? [], $model->cache_tags);
			if (!empty($this->primary_params)) {
				$options = array_merge_hard($options, $this->primary_params);
			}
			$options['where'] = $where[$this->primary_model] ?? [];
			unset($where[$this->primary_model]);
			foreach ($where as $k => $v) {
				if (strpos($k, '\\') === 0) {
					$options['where'][$k] = $v;
				}
			}
			// query
			$this->query = call_user_func_array([$this->primary_model, 'queryBuilderStatic'], [$options])->select();
		}
		// we need to determine db link
		if (empty($this->db_link)) {
			// get from flags first
			if (!empty($this->db_link_flag)) {
				$this->db_link = \Application::get($this->db_link_flag);
			}
			// get default link
			if (empty($this->db_link)) {
				$this->db_link = \Application::get('flag.global.default_db_link');
			}
			// if we could not determine the link we throw exception
			if (empty($this->db_link)) {
				Throw new \Exception('Could not determine db link in datasource!');
			}
		}
		// create empty query object
		if (empty($this->query)) {
			$this->query = new \Object\Query\Builder($this->db_link, $options);
			$this->query->select();
		}
		// add settings to query
		$query_settings = [];
		foreach (['pk', 'columns', 'limit', 'orderby', 'single_row', 'single_value'] as $v) {
			if (array_key_exists($v, $options)) {
				$query_settings[$v] = $options[$v];
			} else if (isset($this->{$v})) {
				$query_settings[$v] = $this->{$v};
			}
		}
		if (isset($query_settings['columns'])) $this->query->columns($query_settings['columns']);
		if (isset($query_settings['limit'])) $this->query->limit($query_settings['limit']);
		if (isset($query_settings['orderby'])) $this->query->limit($query_settings['orderby']);
		if (!empty($query_settings['single_row']) || !empty($query_settings['single_value'])) $this->query->limit(1);
		// fix variables
		$query_settings['pk'] = $query_settings['pk'] ?? null;
		if (empty($this->cache_tags)) $this->cache_tags = [];
		// check if we have query method
		if (!method_exists($this, 'query')) {
			Throw new \Exception('You must specify sql in query method!');
		}
		// process query
		$sql = $this->query($parameters, $options);
		if (!empty($sql)) {
			$db_object = new \Db($this->db_link);
			$this->sql_last_query = $sql;
		} else {
			$db_object = $this->query->db_object;
			$this->sql_last_query = $this->query->sql();
			// grab cache tags from query object
			if (!empty($this->query->cache_tags)) {
				$this->cache_tags = array_unique(array_merge($this->cache_tags, $this->query->cache_tags));
			}
		}
		// determine caching strategy
		if (method_exists($this, 'process')) {
			// retrive data from the cache
			if ($this->cache && !empty($db_object->object->options['cache_link'])) {
				$cache_id = !empty($options['cache_id']) ? $options['cache_id'] : 'Db_DataSource_' . trim(sha1($this->sql_last_query . serialize($query_settings['pk'])));
				// if we cache this query
				$cache_object = new \Cache($db_object->object->options['cache_link']);
				$cached_result = $cache_object->get($cache_id, true);
				if ($cached_result !== false) {
					// if we are debugging
					if (\Debug::$debug) {
						\Debug::$data['sql'][] = $cached_result;
					}
					return $cached_result['rows'];
				}
			} else {
				$this->cache = false;
			}
		}
		$query_options = [
			'cache' => $this->cache,
			'cache_tags' => array_unique($this->cache_tags)
		];
		// if we need to return a query
		if (!empty($options['return_query_only'])) {
			if (empty($sql)) {
				$sql = $this->query->sql();
			}
			// wrap into tabs
			if ($options['return_query_only'] == 'wrap') {
				$object = new \Object\Query\Builder($this->db_link, []);
				$sql = '(' . $object->wrapSqlIntoTabs($sql) . ')';
			}
			return [
				'sql' => $sql,
				'cache_tags' => array_unique($this->cache_tags)
			];
		}
		// if we have SQL
		if (!empty($sql)) {
			$result = $db_object->query($sql, $query_settings['pk'], $query_options);
		} else { // query builder
			$result = $this->query->query($query_settings['pk'], $query_options);
		}
		if (!$result['success']) {
			Throw new \Exception(implode(", ", $result['error']));
		}
		// put parameters beck into options
		$options['parameters'] = $parameters;
		// process data
		if (method_exists($this, 'process')) {
			$data = $this->process($result['rows'], $options);
			// if we are caching
			if ($this->cache) {
				// the same cache structure as in Db classes
				$cache_data = [
					'success' => true,
					'error' => [],
					'errno' => 0,
					'rows' => $data,
					'num_rows' => is_bool($data) ? 0 : count($data),
					'affected_rows' => 0,
					'structure' => [],
					// debug attributes
					'cache' => true,
					'cache_tags' => [],
					'time' => microtime(true),
					'sql' => $this->sql_last_query,
					'key' => $query_settings['pk'],
					'backtrace' => null
				];
				if (\Debug::$debug) {
					$cache_data['backtrace']  = implode("\n", \Object\Error\Base::debugBacktraceString());
					$cache_data['cache_tags'] = $this->cache_tags;
				}
				$cache_object->set($cache_id, $cache_data, null, $this->cache_tags);
			}
		} else {
			$data = $result['rows'];
		}
		// process not cached
		if (method_exists($this, 'processNotCached')) {
			$data = $this->processNotCached($data, $options);
		}
		// single row
		if (!empty($query_settings['single_row']) && !empty($data)) {
			$data = current($data);
		}
		// single value
		if (!empty($query_settings['single_value']) && !empty($data)) {
			$data = current($data);
			if (!empty($data)) {
				$data = current($data);
			}
		}
		return $data;
	}
814303
private function simpleGet($url, array $options = [])
    {
        return (array) \GuzzleHttp\json_decode(
          $this->getConnector()
               ->getClient()
               ->request('get', $url, $options)
               ->getBody()
               ->getContents(),
          true
        );
    }
987252
public function getObject(array $options = array())
    {
        $content = $this->getContent();

        if (is_null($content)) {
            return (object)$content;
        }

        return json_decode($this->content, false);
    }
754845
protected function getRouteAction($options)
    {
        if (is_array($options)) {
            return $this->url->route($options[0], array_slice($options, 1));
        }

        return $this->url->route($options);
    }
1041264
public function getPk($options = '')
    {
        if (!empty($this->pk)) {
            $pk = $this->pk;
        } else {
            $pk = $this->connection->getPk(is_array($options) && isset($options['table']) ? $options['table'] : $this->getTable());
        }

        return $pk;
    }
405385
public static function getInstance(array $options = array())
    {
        if (self::$instance === false) {
            $ret = new ClientImpl($options);
            self::$instance = $ret;
        } else {
            $ret = self::$instance;
        }
        return $ret;
    }
159240
public static function get($url, $query = [], $options = [])
    {
        $options['query'] = $query;
        return self::doRequest('get', $url, $options);
    }
534263
public function pull($options = "") {
        try {
            $output = $this->cmd(sprintf('pull %s', $options));
            return $output;
        } catch (Exception $ex) {
            $output['error'] = $ex;
            return $output;
        }
    }
285705
public function fetch($options = array()) {
        $options = new Values($options);

        $params = Values::of(array(
            'CountryCode' => $options['countryCode'],
            'Type' => Serialize::map($options['type'], function($e) { return $e; }),
            'AddOns' => Serialize::map($options['addOns'], function($e) { return $e; }),
        ));

        $params = array_merge($params, Serialize::prefixedCollapsibleMap($options['addOnsData'], 'AddOns'));
        $payload = $this->version->fetch(
            'GET',
            $this->uri,
            $params
        );

        return new PhoneNumberInstance($this->version, $payload, $this->solution['phoneNumber']);
    }
1233122
private function getRequestOptions(array $options)
    {
        $restOptions = isset($options['restOptions'])
            ? $options['restOptions']
            : $this->restOptions;
        $timeout = isset($options['requestTimeout'])
            ? $options['requestTimeout']
            : $this->requestTimeout;

        if ($timeout && !array_key_exists('timeout', $restOptions)) {
            $restOptions['timeout'] = $timeout;
        }

        return $restOptions;
    }
42575
public function getCollection(array $options = array())
    {
        /** @var UserEntity[] $collection */
        $collection = $this->userManager->findUsers();
        $resource   = new Resource($this->generateBrowseUrl(), array('count' => count($collection)));

        foreach ($collection as $element) {
            $resource->setEmbedded('user', $this->createResourceFromUser($element));
        }

        return $resource;
    }
101738
protected function options(array $options = null)
    {
        $dataOptions = $this->options;

        if ($options)
        {
            $dataOptions = $this->merge($dataOptions, $options);
        }

        return $dataOptions;
    }
862640
public function getQuery(array $options = array())
    {
        if ($this->query['type'] === Query::TYPE_MAP_REDUCE) {
            $this->hydrate = false;
        }

        $documentPersister = $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name);

        $query = $this->query;

        $query['query'] = $this->expr->getQuery();
        $query['query'] = $documentPersister->addDiscriminatorToPreparedQuery($query['query']);
        $query['query'] = $documentPersister->addFilterToPreparedQuery($query['query']);

        $query['newObj'] = $this->expr->getNewObj();

        if (isset($query['select'])) {
            $query['select'] = $documentPersister->prepareSortOrProjection($query['select']);
        }

        if (isset($query['sort'])) {
            $query['sort'] = $documentPersister->prepareSortOrProjection($query['sort']);
        }

        if ($this->class->slaveOkay) {
            $query['slaveOkay'] = $this->class->slaveOkay;
        }

        return new Query(
            $this->dm,
            $this->class,
            $this->collection,
            $query,
            $options,
            $this->hydrate,
            $this->refresh,
            $this->primers,
            $this->requireIndexes
        );
    }
1192789
final protected function get($option)
    {
        if (array_key_exists($key = "$option", $this->options)) {
            return $this->options[$key];
        }

        if (array_key_exists($key, $this->defaults)) {
            return $this->defaults[$key];
        }
    }
55756
public function get($menu, array $path = [], array $options = [])
    {
        return $this->helper->get($menu, $path, $options);
    }
4997
public function getData(array $options)
    {
        $provider = $this->getProvider();

        $ownerDetails = $provider->getResourceOwner($this->accessToken);

        $ownerDetailsArray = $ownerDetails->toArray();

        $email = null;
        if (isset($ownerDetailsArray['emails']) && is_array($ownerDetailsArray['emails'])) {
            foreach ($ownerDetailsArray['emails'] as $value) {
                if ($value['value']) {
                    $email = $value['value'];
                    break;
                }
            }
        }

        $location = null;
        if (isset($ownerDetailsArray['placesLived']) && is_array($ownerDetailsArray['placesLived'])) {
            foreach ($ownerDetailsArray['placesLived'] as $value) {
                if ($value['value']) {
                    $location = $value['value'];
                    break;
                }
            }
        }

        $birthday = null;
        if (isset($ownerDetailsArray['birthday']) && $ownerDetailsArray['birthday']) {
            $birthday = DateTime::createFromFormat('Y-m-d', $ownerDetailsArray['birthday']);
        }

        $photoUrl = $ownerDetailsArray['image']['url'];
        if ($photoUrl) {
            $photoUrl = $this->removeSizeParam($photoUrl);
        }

        return new Result([
            'externalId' => $ownerDetailsArray['id'],
            'name'       => $ownerDetailsArray['displayName'],
            'profileUrl' => isset($ownerDetailsArray['url']) ? $ownerDetailsArray['url'] : null,
            'photoUrl'   => $photoUrl,
            'email'      => $email,
            'gender'     => isset($ownerDetailsArray['gender']) ? $ownerDetailsArray['gender'] : null,
            'language'   => $ownerDetailsArray['language'],
            'location'   => $location,
            'birthday'   => $birthday
        ]);
    }
1261479
protected function getRoute($options)
    {
        if (is_array($options)) {
            return URL::route($options[0], array_slice($options, 1));
        }

        return URL::route($options);
    }