当前位置: 首页>>代码示例>>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;未经允许,请勿转载。