當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Response::httpCodes方法代碼示例

本文整理匯總了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;
 }
開發者ID:Adnan0703,項目名稱:Throttle,代碼行數:8,代碼來源:ThrottleFilter.php

示例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;
 }
開發者ID:nielin,項目名稱:Throttle,代碼行數:23,代碼來源:ThrottleFilter.php

示例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']);
 }
開發者ID:rashmi,項目名稱:newrepo,代碼行數:31,代碼來源:ResponseTest.php


注:本文中的Cake\Network\Response::httpCodes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。