本文整理汇总了PHP中Resource::process方法的典型用法代码示例。如果您正苦于以下问题:PHP Resource::process方法的具体用法?PHP Resource::process怎么用?PHP Resource::process使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Resource
的用法示例。
在下文中一共展示了Resource::process方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($client, $resource_type, $path, $hash = null)
{
Helper::__construct();
$that =& $this;
// fix exceptional resource types
if (array_key_exists($singular = self::get_singular($resource_type), $this->INCONSISTENT_RESOURCE_TYPES)) {
$resource_type = $this->INCONSISTENT_RESOURCE_TYPES[$singular];
}
$this->client = $client;
$this->resource_type = $resource_type;
$this->path = $path;
$this->resources = array();
$this->methods->index = function ($params = null) use(&$that, &$client, $resource_type, $path) {
if ($resource_type == "session") {
list($resource_type, $path, $hash) = $client->do_get($path, $params);
return new ResourceDetail($client, $resource_type, $path, $hash);
}
list($resource_type, $path, $hash) = $client->do_get($path, $params);
$that->resources = Resource::process($client, $resource_type, $path, $hash);
return $that;
};
$this->methods->create = function ($params = null) use(&$client, $path) {
return $client->do_post($path, $params);
};
if (isset($this->RESOURCE_SPECIAL_ACTIONS[$resource_type])) {
foreach ($this->RESOURCE_SPECIAL_ACTIONS[$resource_type] as $meth => $action) {
$action_path = Helper::insert_in_path($path, $meth);
$this->methods->{$meth} = function ($params = null) use(&$client, $action, $action_path) {
return $client->{$action}($action_path, $params);
};
}
}
}
示例2: __construct
public function __construct($client, $resource_type, $href, $hash)
{
Helper::__construct();
$that =& $this;
$this->client = $client;
$this->resource_type = $resource_type;
$this->href = $href;
if (!is_null($hash) && isset($hash->links)) {
$links = $hash->links;
unset($hash->links);
} else {
$links = array();
}
if (!is_null($hash) && isset($hash->actions)) {
$raw_actions = $hash->actions;
unset($hash->actions);
} else {
$raw_actions = array();
}
if (is_null($hash)) {
$hash = new \StdClass();
}
$hash->href = Helper::get_and_delete_href_from_links($links);
// Add links to attributes set and create a method that returns the links
$this->attributes = new Set();
$this->attributes[] = "links";
$this->links = $links;
foreach ($raw_actions as $a) {
$action_name = $a->rel;
$this->methods->{$action_name} = function ($params = null) use(&$client, $hash, $action_name) {
return $client->do_post("{$hash->href}/{$action_name}", $params);
};
}
$associations = new Set();
$this->get_associated_resources($client, $links, $associations);
switch ($resource_type) {
case "instance":
$this->methods->live_tasks = function ($params = null) use(&$client, $href) {
if (Helper::has_id($params)) {
$path = "{$href}/live/tasks";
$path = Helper::add_id_and_params_to_path($path, $params);
return Resource::process($client, "live_task", $path);
}
};
}
foreach ($hash as $k => $v) {
if ($associations[$k]) {
// has links...?
} else {
// add to attributes and create a getter method
$this->attributes[] = $k;
$this->{$k} = $v;
}
}
$this->methods->destroy = function ($params = null) use(&$client, $href) {
return $client->do_delete($href, $params);
};
$this->methods->update = function ($params = null) use(&$client, $href, $resource_type) {
if ($resource_type == "account") {
// HACK: handle child_account update specially
$href = strstr("account", "child_account");
}
return $client->do_put($href, $params);
};
$this->methods->show = function ($params = null) use(&$that) {
return $that;
};
}
示例3: get_associated_resources
/**
* creates instance methods out of the associated resources from links
*/
protected function get_associated_resources($client, $links, Set &$associations = null)
{
$rels = array();
foreach ($links as $l) {
if (array_key_exists($l->rel, $rels)) {
$rels[$l->rel][] = $l->href;
} else {
$rels[$l->rel] = array($l->href);
}
}
foreach ($rels as $rel => $hrefs) {
if (!is_null($associations)) {
$associations[] = $rel;
}
$that =& $this;
$this->methods->{$rel} = function ($params = null) use(&$that, &$client, $rel, $hrefs) {
if (count($hrefs) == 1) {
if (Helper::has_id($params) || Helper::is_singular($rel)) {
// user wants a single resource
// calling data() you don't want a resource object back
if ($rel == "data") {
return new ResourceDetail($hrefs[0], $params);
}
if (Helper::is_singular($rel)) {
$resource_type = Helper::get_resource_type($hrefs[0], -2);
} else {
$resource_type = Helper::get_resource_type($hrefs[0], -1);
}
$path = Helper::add_id_and_params_to_path($hrefs[0], $params);
Helper::get_resource_type($hrefs[0], -1);
return Resource::Process($client, $resource_type, $path);
} else {
$resource_type = Helper::get_resource_type($hrefs[0], -1);
$path = Helper::add_id_and_params_to_path($hrefs[0], $params);
return new Resources($client, $resource_type, $path);
}
} else {
$resources = array();
if (Helper::has_id($params) || Helper::is_singular($rel)) {
foreach ($hrefs as $href) {
// user wants a single resource. Doing show, update, delete, etc
if (Helper::is_singular($rel)) {
$resource_type = Helper::get_resource_type($href, -2);
} else {
$resource_type = Helper::get_resource_type($href, -1);
}
$path = Helper::add_id_and_params_to_path($href, $params);
$resources[] = Resource::process($client, $resource_type, $path);
}
} else {
foreach ($hrefs as $href) {
$resource_type = Helper::get_resource_type($href, -1);
$path = Helper::add_id_and_params_to_path($href, $params);
$resources[] = new Resources($client, $resource_type, $path);
}
}
return $resources;
}
};
}
}