本文整理汇总了PHP中Cake\Network\Response::httpCodes方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::httpCodes方法的具体用法?PHP Response::httpCodes怎么用?PHP Response::httpCodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Network\Response
的用法示例。
在下文中一共展示了Response::httpCodes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeDispatch
public function beforeDispatch(Event $event)
{
$event->stopPropagation();
$response = new Response(['body' => $this->config('message')]);
$response->httpCodes([429 => 'Too Many Requests']);
$response->statusCode(429);
return $response;
}
示例2: beforeDispatch
/**
* beforeDispatch.
*
* @param Cake\Event\Event $event Event instance
* @return mixed Cake\Network\Response when limit is reached, void otherwise
*/
public function beforeDispatch(Event $event)
{
$this->_setIdentifier($event->data['request']);
$this->_initCache();
$this->_count = $this->_touch($event->data['request']);
// client has not exceeded rate limit
if ($this->_count <= $this->config('limit')) {
$this->_setHeaders($event->data['response']);
return;
}
// client has reached rate limit
$event->stopPropagation();
$response = new Response(['body' => $this->config('message')]);
$response->httpCodes([429 => 'Too Many Requests']);
$response->statusCode(429);
return $response;
}
示例3: testHttpCodes
/**
* Tests the httpCodes method
*
* @expectedException \InvalidArgumentException
* @return void
*/
public function testHttpCodes()
{
$response = new Response();
$result = $response->httpCodes();
$this->assertEquals(42, count($result));
$result = $response->httpCodes(100);
$expected = [100 => 'Continue'];
$this->assertEquals($expected, $result);
$codes = [381 => 'Unicorn Moved', 555 => 'Unexpected Minotaur'];
$result = $response->httpCodes($codes);
$this->assertTrue($result);
$this->assertEquals(44, count($response->httpCodes()));
$result = $response->httpCodes(381);
$expected = [381 => 'Unicorn Moved'];
$this->assertEquals($expected, $result);
$codes = [404 => 'Sorry Bro'];
$result = $response->httpCodes($codes);
$this->assertTrue($result);
$this->assertEquals(44, count($response->httpCodes()));
$result = $response->httpCodes(404);
$expected = [404 => 'Sorry Bro'];
$this->assertEquals($expected, $result);
//Throws exception
$response->httpCodes([0 => 'Nothing Here', -1 => 'Reverse Infinity', 12345 => 'Universal Password', 'Hello' => 'World']);
}