本文整理汇总了PHP中Utilities::get_by_key方法的典型用法代码示例。如果您正苦于以下问题:PHP Utilities::get_by_key方法的具体用法?PHP Utilities::get_by_key怎么用?PHP Utilities::get_by_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utilities
的用法示例。
在下文中一共展示了Utilities::get_by_key方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: go
//.........这里部分代码省略.........
}
$paging_type = empty($paging->type) ? "page_number" : $paging->type;
$endpoint_params = $this->config->get_endpoint_setting('parameters');
$page_size_param = empty($paging->parameters->page_size->name) ? "page_size" : $paging->parameters->page_size->name;
$page_size = empty($endpoint_params->{$page_size_param}) ? null : $endpoint_params->{$page_size_param};
$paging_base = isset($paging->parameters->{$paging_type}->base) ? $paging->parameters->{$paging_type}->base : 1;
switch ($paging_type) {
case 'page_number':
if (empty($paging->parameters->{$paging_type}->name)) {
throw new SDKlessException("paging {$paging_type} name required");
}
$paging_counter_param = $paging->parameters->{$paging_type}->name;
if (!isset($paging_counter)) {
$paging_counter = $paging_base;
}
$paging_counter++;
$keys = array('parameters', $paging_counter_param);
$this->config->set_endpoint_setting($keys, $paging_counter);
// response count is less than page size; break
if (!empty($page_size) && $response_count < $page_size) {
break 2;
}
break;
case 'record_offset':
if (empty($paging->parameters->{$paging_type}->name)) {
throw new SDKlessException("paging {$paging_type} name required");
}
$paging_counter_param = $paging->parameters->{$paging_type}->name;
if (!isset($paging_counter)) {
$paging_counter = $paging_base;
}
if (empty($page_size)) {
throw new SDKlessException("endpoint page size parameter required for offset paging");
}
$paging_counter += $page_size;
$keys = array('parameters', $paging_counter_param);
$this->config->set_endpoint_setting($keys, $paging_counter);
// response count is less than page size; break
if (!empty($page_size) && $response_count < $page_size) {
break 2;
}
break;
case 'cursor':
if (empty($paging->parameters->{$paging_type}->location) || !is_array($paging->parameters->{$paging_type}->location)) {
throw new SDKlessException("paging {$paging_type} location array required");
}
$data = json_decode(json_encode($response));
// make copy of response (can't be output; may no longer contain paging info)
foreach ($paging->parameters->{$paging_type}->location as $location_key) {
$data = Utilities::get_by_key($data, $location_key);
}
if (empty($data)) {
break 2;
}
$this->config->set_endpoint_setting('uri', $data);
break;
}
}
$output_config = $this->config->get_endpoint_setting('output');
// filter output
if (Utilities::is_structure($output) && !empty($output_config->filter)) {
$unfiltered_output = json_decode(json_encode($output));
$output = array();
if (!Utilities::is_structure($output_config->filter)) {
throw new SDKlessException("config endpoint output filter must be a structure");
}
foreach ($output_config->filter as $filter) {
$match_found = false;
if (empty($filter->search_key) || !isset($filter->search_value)) {
throw new SDKlessException("search_key and search_value are required for output filtering");
}
foreach ($unfiltered_output as $item) {
$item_value = Utilities::get_by_key($item, $filter->search_key);
if (is_null($item_value)) {
continue;
}
if ($item_value == $filter->search_value) {
$match_found = true;
if (!empty($filter->return_key)) {
$return_key = $filter->return_key;
return Utilities::get_by_key($item, $return_key);
}
$output[] = $item;
}
}
if (!empty($filter->return_type)) {
switch ($filter->return_type) {
case 'boolean':
return $match_found;
break;
case '!boolean':
return !$match_found;
break;
}
}
}
}
$this->config->reset_to_unmerged();
return $output;
}
示例2: get_item
private function get_item($data)
{
$output_config = $this->config->get_endpoint_setting('output');
$output_item = array();
foreach ($output_config->data->items->locations as $location_key => $location) {
if (is_scalar($location)) {
if (isset($data[$location])) {
$output_item[$location_key] = $data[$location];
} else {
$output_item[$location_key] = null;
}
} else {
// locations entry is an array like: ["email_addresses", 0, "email_address"],
$data_copy = $data;
foreach ($location as $location_item) {
if (is_scalar($location_item)) {
$data_copy = Utilities::get_by_key($data_copy, $location_item);
if (is_null($data_copy)) {
throw new SDKlessException("specified key not found in response: {$location_item}");
}
$output_item[$location_key] = $data_copy;
} else {
// if location item is a structure, this indicates a search; data must be a structure
$this->set_item_by_search($data_copy, $location_item, $location_key, $output_item);
}
}
}
}
return $output_item;
}
示例3: error_check
private function error_check($output)
{
$output_config = $this->config->get_endpoint_setting('output');
if (!empty($output_config->error->location)) {
$error_location = $output_config->error->location;
}
if (empty($error_location)) {
return;
}
if (!is_array($error_location)) {
$this->responses[$this->config->actual_endpoint_name][] = $output;
throw new SDKlessException("config error location must be an array");
}
// drill down to desired data
foreach ($error_location as $location_key) {
$output = Utilities::get_by_key($output, $location_key);
if (empty($output)) {
break;
}
}
if (!empty($output)) {
$this->responses[$this->config->actual_endpoint_name][] = $output;
throw new SDKlessException("API returned error: {$output}");
}
}