本文整理汇总了PHP中rest::url方法的典型用法代码示例。如果您正苦于以下问题:PHP rest::url方法的具体用法?PHP rest::url怎么用?PHP rest::url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest
的用法示例。
在下文中一共展示了rest::url方法的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_test
public function get_test()
{
$t1 = tag::add(item::root(), "t1");
$t2 = tag::add(item::root(), "t2");
$request = new stdClass();
$this->assert_equal_array(array("url" => rest::url("tags"), "members" => array(rest::url("tag", $t1), rest::url("tag", $t2))), tags_rest::get($request));
}
示例3: 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);
}
示例4: relationships
static function relationships($resource_type, $resource)
{
switch ($resource_type) {
case "item":
return array("comments" => array("url" => rest::url("item_comments", $resource)));
}
}
示例5: 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());
}
示例6: post
static function post($request)
{
$tag = rest::resolve($request->params->entity->tag);
$item = rest::resolve($request->params->entity->item);
access::required("view", $item);
tag::add($item, $tag->name);
return array("url" => rest::url("tag_item", $tag, $item), "members" => array(rest::url("tag", $tag), rest::url("item", $item)));
}
示例7: 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);
}
示例8: post
static function post($request)
{
$tag = rest::resolve($request->params->entity->tag);
$item = rest::resolve($request->params->entity->item);
access::required("view", $item);
if (!$tag->loaded()) {
throw new Kohana_404_Exception();
}
tag::add($item, $tag->name);
return array("url" => rest::url("tag_item", $tag, $item), "members" => array("tag" => rest::url("tag", $tag), "item" => rest::url("item", $item)));
}
示例9: relationships
static function relationships($resource_type, $resource)
{
switch ($resource_type) {
case "item":
$tags = array();
foreach (tag::item_tags($resource) as $tag) {
$tags[] = rest::url("tag_item", $tag, $resource);
}
return array("tags" => array("url" => rest::url("item_tags", $resource), "members" => $tags));
}
}
示例10: 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));
}
示例11: missing_file_test
public function missing_file_test()
{
$photo = test::random_photo();
$request = new stdClass();
$request->url = rest::url("data", $photo, "thumb");
$request->params = new stdClass();
$request->params->size = "thumb";
unlink($photo->thumb_path());
// oops!
try {
data_rest::get($request);
$this->assert_true(false);
} catch (Kohana_404_Exception $e) {
// pass
}
}
示例12: post
static function post($request)
{
// @todo: what permission should be required to create a tag here?
// for now, require edit at the top level. Perhaps later, just require any edit perms,
// anywhere in the gallery?
access::required("edit", item::root());
if (empty($request->params->name)) {
throw new Rest_Exception("Bad Request", 400);
}
$tag = ORM::factory("tag")->where("name", "=", $request->params->name)->find();
if (!$tag->loaded()) {
$tag->name = $request->params->name;
$tag->count = 0;
$tag->save();
}
return array("url" => rest::url("tag", $tag));
}
示例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: post
static function post($request)
{
// The user must have some edit permission somewhere to create a tag.
if (!identity::active_user()->admin) {
$query = db::build()->from("access_caches")->and_open();
foreach (identity::active_user()->groups() as $group) {
$query->or_where("edit_{$group->id}", "=", access::ALLOW);
}
$has_any_edit_perm = $query->close()->count_records();
if (!$has_any_edit_perm) {
access::forbidden();
}
}
if (empty($request->params->entity->name)) {
throw new Rest_Exception("Bad Request", 400);
}
$tag = ORM::factory("tag")->where("name", "=", $request->params->entity->name)->find();
if (!$tag->loaded()) {
$tag->name = $request->params->entity->name;
$tag->count = 0;
$tag->save();
}
return array("url" => rest::url("tag", $tag));
}
示例15: _format_restful_item
private static function _format_restful_item($item, $types)
{
$item_rest = array("url" => rest::url("item", $item), "entity" => $item->as_restful_array(), "relationships" => rest::relationships("item", $item));
if ($item->type == "album") {
$members = array();
foreach ($item->viewable()->children() as $child) {
if (empty($types) || in_array($child->type, $types)) {
$members[] = rest::url("item", $child);
}
}
$item_rest["members"] = $members;
}
return $item_rest;
}