本文整理匯總了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);
}
}
}