本文整理汇总了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!');
}
示例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);
}
}
}