本文整理汇总了PHP中rest类的典型用法代码示例。如果您正苦于以下问题:PHP rest类的具体用法?PHP rest怎么用?PHP rest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了rest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:HarriLu,项目名称:gallery3,代码行数:49,代码来源:tree_rest.php
示例2: relationships
static function relationships($resource_type, $resource)
{
switch ($resource_type) {
case "item":
return array("comments" => array("url" => rest::url("item_comments", $resource)));
}
}
开发者ID:kandsten,项目名称:gallery3,代码行数:7,代码来源:comment_rest.php
示例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);
}
开发者ID:assad2012,项目名称:gallery3-appfog,代码行数:7,代码来源:item_tags_rest.php
示例4: 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));
}
开发者ID:assad2012,项目名称:gallery3-appfog,代码行数:7,代码来源:Tags_Rest_Helper_Test.php
示例5: __call
/**
* Handle dispatching for all REST controllers.
*/
public function __call($function, $args)
{
// If no parameter was provided after the controller name (eg "/albums") then $function will
// be set to "index". Otherwise, $function is the first parameter, and $args are all
// subsequent parameters.
$request_method = rest::request_method();
if ($function == "index" && $request_method == "get") {
return $this->_index();
}
$resource = ORM::factory($this->resource_type, $function);
if (!$resource->loaded && $request_method != "post") {
return Kohana::show_404();
}
if ($request_method != "get") {
access::verify_csrf();
}
switch ($request_method) {
case "get":
return $this->_show($resource);
case "put":
return $this->_update($resource);
case "delete":
return $this->_delete($resource);
case "post":
return $this->_create($resource);
}
}
开发者ID:Juuro,项目名称:Dreamapp-Website,代码行数:30,代码来源:rest.php
示例6: feed
public function feed($module_id, $feed_id, $id = null)
{
$page = $this->input->get("page", 1);
if ($page < 1) {
url::redirect(url::merge(array("page" => 1)));
}
// Configurable page size between 1 and 100, default 20
$page_size = max(1, min(100, $this->input->get("page_size", self::$page_size)));
// Run the appropriate feed callback
if (module::is_active($module_id)) {
$class_name = "{$module_id}_rss";
if (method_exists($class_name, "feed")) {
$feed = call_user_func(array($class_name, "feed"), $feed_id, ($page - 1) * $page_size, $page_size, $id);
}
}
if (empty($feed)) {
Kohana::show_404();
}
if ($feed->max_pages && $page > $feed->max_pages) {
url::redirect(url::merge(array("page" => $feed->max_pages)));
}
$view = new View(empty($feed->view) ? "feed.mrss" : $feed->view);
unset($feed->view);
$view->feed = $feed;
$view->pub_date = date("D, d M Y H:i:s T");
$feed->uri = url::abs_site(Router::$current_uri);
if ($page > 1) {
$feed->previous_page_uri = url::abs_site(url::merge(array("page" => $page - 1)));
}
if ($page < $feed->max_pages) {
$feed->next_page_uri = url::abs_site(url::merge(array("page" => $page + 1)));
}
rest::http_content_type(rest::RSS);
print $view;
}
开发者ID:Okat,项目名称:gallery3,代码行数:35,代码来源:rss.php
示例7: delete
static function delete($request)
{
list($tag, $item) = rest::resolve($request->url);
access::required("edit", $item);
$tag->remove($item);
$tag->save();
}
开发者ID:JasonWiki,项目名称:docs,代码行数:7,代码来源:tag_items_rest.php
示例8: 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);
}
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:7,代码来源:item_itemchecksums_rest.php
示例9: __call
public function __call($function, $args)
{
$input = Input::instance();
$request = new stdClass();
switch ($method = strtolower($input->server("REQUEST_METHOD"))) {
case "get":
$request->params = (object) $input->get();
break;
case "post":
$request->params = (object) $input->post();
if (isset($_FILES["file"])) {
$request->file = upload::save("file");
}
break;
}
$request->method = strtolower($input->server("HTTP_X_GALLERY_REQUEST_METHOD", $method));
$request->access_token = $input->server("HTTP_X_GALLERY_REQUEST_KEY");
$request->url = url::abs_current(true);
rest::set_active_user($request->access_token);
$handler_class = "{$function}_rest";
$handler_method = $request->method;
if (!method_exists($handler_class, $handler_method)) {
throw new Rest_Exception("Bad Request", 400);
}
try {
rest::reply(call_user_func(array($handler_class, $handler_method), $request));
} catch (ORM_Validation_Exception $e) {
foreach ($e->validation->errors() as $key => $value) {
$msgs[] = "{$key}: {$value}";
}
throw new Rest_Exception("Bad Request: " . join(", ", $msgs), 400);
}
}
开发者ID:andyst,项目名称:gallery3,代码行数:33,代码来源:rest.php
示例10: 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());
}
开发者ID:andyst,项目名称:gallery3,代码行数:8,代码来源:Tag_Item_Rest_Helper_Test.php
示例11: 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;
}
开发者ID:HarriLu,项目名称:gallery3,代码行数:57,代码来源:data_rest.php
示例12: get_with_access_key_test
public function get_with_access_key_test()
{
$key = rest::get_access_token(1);
// admin user
$_SERVER["REQUEST_METHOD"] = "GET";
$_SERVER["HTTP_X_GALLERY_REQUEST_KEY"] = $key->access_key;
$_GET["key"] = "value";
$this->assert_array_equal_to_json(array("params" => array("key" => "value"), "method" => "get", "access_token" => $key->access_key, "url" => "http://./index.php/gallery_unit_test"), test::call_and_capture(array(new Rest_Controller(), "mock")));
}
开发者ID:andyst,项目名称:gallery3,代码行数:9,代码来源:Rest_Controller_Test.php
示例13: 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);
}
开发者ID:Joe7,项目名称:gallery3,代码行数:10,代码来源:item_comments_rest.php
示例14: 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));
}
}
开发者ID:andyst,项目名称:gallery3,代码行数:11,代码来源:tag_rest.php
示例15: 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;
}
开发者ID:kandsten,项目名称:gallery3,代码行数:53,代码来源:data_rest.php
示例16: 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));
}
开发者ID:HarriLu,项目名称:gallery3,代码行数:12,代码来源:comments_rest.php
示例17: get_usuario_huella
function get_usuario_huella($usuario)
{
// $usuarios_ini = toba_modelo_rest::get_ini_usuarios($this->modelo_proyecto);
foreach ($this->validador_ssl->get_passwords() as $key => $u) {
if ($key === $usuario) {
if (isset($u['fingerprint'])) {
return $u['fingerprint'];
} else {
rest::app()->logger->info('Se encontro al usuario "' . $usuario . '", pero no tiene una entrada fingerprint en rest_usuario.ini');
}
}
}
return NULL;
}
开发者ID:siu-toba,项目名称:rest,代码行数:14,代码来源:autenticacion_ssl.php
示例18: request_method_test
public function request_method_test()
{
foreach (array("GET", "POST") as $method) {
foreach (array("", "PUT", "DELETE") as $tunnel) {
if ($method == "GET") {
$expected = "GET";
} else {
$expected = $tunnel == "" ? $method : $tunnel;
}
$_SERVER["REQUEST_METHOD"] = $method;
$_POST["_method"] = $tunnel;
$this->assert_equal(strtolower(rest::request_method()), strtolower($expected), "Request method: {$method}, tunneled: {$tunnel}");
}
}
}
开发者ID:xafr,项目名称:gallery3,代码行数:15,代码来源:REST_Helper_Test.php
示例19: 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
}
}
开发者ID:HarriLu,项目名称:gallery3,代码行数:16,代码来源:Data_Rest_Helper_Test.php
示例20: 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));
}
开发者ID:joericochuyt,项目名称:gallery3,代码行数:17,代码来源:tags_rest.php
注:本文中的rest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论