本文整理汇总了PHP中rest::resolve方法的典型用法代码示例。如果您正苦于以下问题:PHP rest::resolve方法的具体用法?PHP rest::resolve怎么用?PHP rest::resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest
的用法示例。
在下文中一共展示了rest::resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* The tree is rooted in a single item and can have modifiers which adjust what data is shown
* for items inside the given tree, up to the depth that you want. The entity for this resource
* is a series of items.
*
* depth=<number>
* Only traverse this far down into the tree. If there are more albums
* below this depth, provide RESTful urls to other tree resources in
* the members section. Default is infinite.
*
* type=<album|photo|movie>
* Restrict the items displayed to the given type. Default is all types.
*
* fields=<comma separated list of field names>
* In the entity section only return these fields for each item.
* Default is all fields.
*/
static function get($request)
{
$item = rest::resolve($request->url);
access::required("view", $item);
$query_params = array();
$p = $request->params;
$where = array();
if (isset($p->type)) {
$where[] = array("type", "=", $p->type);
$query_params[] = "type={$p->type}";
}
if (isset($p->depth)) {
$lowest_depth = $item->level + $p->depth;
$where[] = array("level", "<=", $lowest_depth);
$query_params[] = "depth={$p->depth}";
}
$fields = array();
if (isset($p->fields)) {
$fields = explode(",", $p->fields);
$query_params[] = "fields={$p->fields}";
}
$entity = array(array("url" => rest::url("item", $item), "entity" => $item->as_restful_array($fields)));
$members = array();
foreach ($item->viewable()->descendants(null, null, $where) as $child) {
$entity[] = array("url" => rest::url("item", $child), "entity" => $child->as_restful_array($fields));
if (isset($lowest_depth) && $child->level == $lowest_depth) {
$members[] = url::merge_querystring(rest::url("tree", $child), $query_params);
}
}
$result = array("url" => $request->url, "entity" => $entity, "members" => $members, "relationships" => rest::relationships("tree", $item));
return $result;
}
示例2: get
static function get($request)
{
$item = rest::resolve($request->url);
access::required("view", $item);
$checksums = array(rest::url("itemchecksum_md5", $item), rest::url("itemchecksum_sha1", $item));
return array("url" => $request->url, "members" => $checksums);
}
示例3: delete
static function delete($request)
{
$item = rest::resolve($request->url);
access::required("edit", $item);
// Deleting this collection means removing all tags associated with the item.
tag::clear_all($item);
}
示例4: delete
static function delete($request)
{
list($tag, $item) = rest::resolve($request->url);
access::required("edit", $item);
$tag->remove($item);
$tag->save();
}
示例5: get
/**
* To retrieve a collection of items, you can specify the following query parameters to specify
* the type of the collection. If both are specified, then the url parameter is used and the
* ancestors_for is ignored. Specifying the "type" parameter with the urls parameter, will
* filter the results based on the specified type. Using the type parameter with the
* ancestors_for parameter makes no sense and will be ignored.
*
* urls=["url1","url2","url3"]
* Return items that match the specified urls. Typically used to return the member detail
*
* ancestors_for=url
* Return the ancestors of the specified item
*
* type=<comma separate list of photo, movie or album>
* Limit the type to types in this list, eg: "type=photo,movie".
* Also limits the types returned in the member collections (same behaviour as item_rest).
* Ignored if ancestors_for is set.
*/
static function get($request)
{
$items = array();
$types = array();
if (isset($request->params->urls)) {
if (isset($request->params->type)) {
$types = explode(",", $request->params->type);
}
foreach (json_decode($request->params->urls) as $url) {
$item = rest::resolve($url);
if (!access::can("view", $item)) {
continue;
}
if (empty($types) || in_array($item->type, $types)) {
$items[] = items_rest::_format_restful_item($item, $types);
}
}
} else {
if (isset($request->params->ancestors_for)) {
$item = rest::resolve($request->params->ancestors_for);
if (!access::can("view", $item)) {
throw new Kohana_404_Exception();
}
$items[] = items_rest::_format_restful_item($item, $types);
while (($item = $item->parent()) != null) {
array_unshift($items, items_rest::_format_restful_item($item, $types));
}
}
}
return $items;
}
示例6: resolve_test
public function resolve_test()
{
$album = test::random_album();
$tag = tag::add($album, "tag1")->reload();
$tuple = rest::resolve(rest::url("tag_item", $tag, $album));
$this->assert_equal_array($tag->as_array(), $tuple[0]->as_array());
$this->assert_equal_array($album->as_array(), $tuple[1]->as_array());
}
示例7: delete
static function delete($request)
{
if (!identity::active_user()->admin) {
access::forbidden();
}
$comment = rest::resolve($request->url);
access::required("edit", $comment->item());
$comment->delete();
}
示例8: get
static function get($request)
{
$item = rest::resolve($request->url);
$p = $request->params;
if (!isset($p->size) || !in_array($p->size, array("thumb", "resize", "full"))) {
throw new Rest_Exception("Bad Request", 400, array("errors" => array("size" => "invalid")));
}
// Note: this code is roughly duplicated in file_proxy, so if you modify this, please look to
// see if you should make the same change there as well.
if ($p->size == "full") {
if ($item->is_album()) {
throw new Kohana_404_Exception();
}
access::required("view_full", $item);
$file = $item->file_path();
} else {
if ($p->size == "resize") {
access::required("view", $item);
$file = $item->resize_path();
} else {
access::required("view", $item);
$file = $item->thumb_path();
}
}
if (!file_exists($file)) {
throw new Kohana_404_Exception();
}
header("Content-Length: " . filesize($file));
if (isset($p->m)) {
header("Pragma:");
// Check that the content hasn't expired or it wasn't changed since cached
expires::check(2592000, $item->updated);
expires::set(2592000, $item->updated);
// 30 days
}
// We don't need to save the session for this request
Session::instance()->abort_save();
// Dump out the image. If the item is a movie or album, then its thumbnail will be a JPG.
if (($item->is_movie() || $item->is_album()) && $p->size == "thumb") {
header("Content-Type: image/jpeg");
} else {
header("Content-Type: {$item->mime_type}");
}
if (TEST_MODE) {
return $file;
} else {
Kohana::close_buffers(false);
if (isset($p->encoding) && $p->encoding == "base64") {
print base64_encode(file_get_contents($file));
} else {
readfile($file);
}
}
// We must exit here to keep the regular REST framework reply code from adding more bytes on
// at the end or tinkering with headers.
exit;
}
示例9: get
static function get($request)
{
$item = rest::resolve($request->url);
access::required("view", $item);
$comments = array();
foreach (ORM::factory("comment")->viewable()->where("item_id", "=", $item->id)->order_by("created", "DESC")->find_all() as $comment) {
$comments[] = rest::url("comment", $comment);
}
return array("url" => $request->url, "members" => $comments);
}
示例10: delete
static function delete($request)
{
// Restrict deleting tags to admins. Otherwise, a logged in user can do great harm to an
// install.
if (!identity::active_user()->admin) {
access::forbidden();
}
$tag = rest::resolve($request->url);
$tag->delete();
}
示例11: get
static function get($request)
{
$item = rest::resolve($request->url);
access::required("view", $item);
$p = $request->params;
if (!isset($p->size) || !in_array($p->size, array("thumb", "resize", "full"))) {
throw new Rest_Exception("Bad Request", 400, array("errors" => array("size" => "invalid")));
}
switch ($p->size) {
case "thumb":
$file = $item->thumb_path();
break;
case "resize":
$file = $item->resize_path();
break;
case "full":
$file = $item->file_path();
break;
}
if (!file_exists($file)) {
throw new Kohana_404_Exception();
}
// Note: this code is roughly duplicated in data_rest, so if you modify this, please look to
// see if you should make the same change there as well.
//
// We don't have a cache buster in the url, so don't set cache headers here.
// We don't need to save the session for this request
Session::instance()->abort_save();
if ($item->is_album() && !$item->album_cover_item_id) {
// No thumbnail. Return nothing.
// @todo: what should we do here?
return;
}
// Dump out the image. If the item is a movie, then its thumbnail will be a JPG.
if ($item->is_movie() && $p->size == "thumb") {
header("Content-Type: image/jpeg");
} else {
if ($item->is_album()) {
header("Content-Type: " . $item->album_cover()->mime_type);
} else {
header("Content-Type: {$item->mime_type}");
}
}
Kohana::close_buffers(false);
if (isset($p->encoding) && $p->encoding == "base64") {
print base64_encode(file_get_contents($file));
} else {
readfile($file);
}
// We must exit here to keep the regular REST framework reply code from adding more bytes on
// at the end or tinkering with headers.
exit;
}
示例12: post
static function post($request)
{
$entity = $request->params->entity;
$item = rest::resolve($entity->item);
access::required("edit", $item);
$comment = ORM::factory("comment");
$comment->author_id = identity::active_user()->id;
$comment->item_id = $item->id;
$comment->text = $entity->text;
$comment->save();
return array("url" => rest::url("comment", $comment));
}
示例13: get
static function get($request)
{
$items = array();
if (isset($request->params->url)) {
foreach ($request->params->url as $url) {
$item = rest::resolve($url);
if (access::can("view", $item)) {
$members = array();
if ($item->type == "album") {
foreach ($item->children() as $child) {
$members[] = rest::url("item", $child);
}
}
$items[] = array("url" => $url, "entity" => $item->as_restful_array(), "members" => $members, "relationship" => rest::relationships("item", $item));
}
}
}
return $items;
}
示例14: get
static function get($request)
{
$item = rest::resolve($request->url);
access::required("view", $item);
$checksum = "0";
// If the KeepOriginal module is active, check for/use the
// original image instead of the gallery edited version.
if (module::is_active("keeporiginal")) {
$original_image = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path());
if ($item->is_photo() && file_exists($original_image)) {
$checksum = md5_file($original_image);
} else {
$checksum = md5_file($item->file_path());
}
} else {
$checksum = md5_file($item->file_path());
}
$data = array("checksum" => $checksum);
return array("url" => $request->url, "entity" => $data);
}
示例15: delete
static function delete($request)
{
$tag = rest::resolve($request->url);
$tag->delete();
}