当前位置: 首页>>代码示例>>PHP>>正文


PHP Slim::raise方法代码示例

本文整理汇总了PHP中Slim::raise方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::raise方法的具体用法?PHP Slim::raise怎么用?PHP Slim::raise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slim的用法示例。


在下文中一共展示了Slim::raise方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSlimRaiseSetsResponse

 /**
  * Test SlimException sets Response
  *
  * Pre-conditions:
  * You have initialized a Slim app with an accessible route 
  * and raise a SlimException in that route.
  *
  * Post-conditions:
  * The response status will match the code and message of the SlimException
  */
 public function testSlimRaiseSetsResponse()
 {
     Slim::init();
     Slim::get('/', function () {
         Slim::raise(501, 'Error!');
     });
     Slim::run();
     $this->assertEquals(Slim::response()->status(), 501);
     $this->assertEquals(Slim::response()->body(), 'Error!');
 }
开发者ID:kolanos,项目名称:Slim,代码行数:20,代码来源:SlimTest.php

示例2: etag

 /**
  * Set ETag HTTP Response Header
  *
  * Set the etag header and stop if the conditional GET request matches. 
  * The `value` argument is a unique identifier for the current resource. 
  * The `type` argument indicates whether the etag should be used as a strong or
  * weak cache validator.
  *
  * When the current request includes an 'If-None-Match' header with
  * a matching etag, execution is immediately stopped. If the request
  * method is GET or HEAD, a '304 Not Modified' response is sent.
  *
  * @param 	string 						$value 	The etag value
  * @param 	string 						$type 	The type of etag to create; either "strong" or "weak"
  * @throws 	InvalidArgumentException 			If provided type is invalid
  */
 public static function etag($value, $type = 'strong')
 {
     //Ensure type is correct
     if (!in_array($type, array('strong', 'weak'))) {
         throw new InvalidArgumentException('Invalid Slim::etag type. Expected "strong" or "weak".');
     }
     //Set etag value
     $value = '"' . $value . '"';
     if ($type === 'weak') {
         $value = 'W/' . $value;
     }
     Slim::response()->header('ETag', $value);
     //Check conditional GET
     if ($etagsHeader = Slim::request()->header('IF_NONE_MATCH')) {
         $etags = preg_split('@\\s*,\\s*@', $etagsHeader);
         if (in_array($value, $etags) || in_array('*', $etags)) {
             Slim::raise(304);
         }
     }
 }
开发者ID:kolanos,项目名称:Slim,代码行数:36,代码来源:Slim.php


注:本文中的Slim::raise方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。