当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::getEventDispatcher方法代码示例

本文整理汇总了PHP中Guzzle\Http\Message\Request::getEventDispatcher方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getEventDispatcher方法的具体用法?PHP Request::getEventDispatcher怎么用?PHP Request::getEventDispatcher使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Guzzle\Http\Message\Request的用法示例。


在下文中一共展示了Request::getEventDispatcher方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSignsRequestsProperly

 /**
  * @covers Aws\Common\Signature\SignatureListener
  */
 public function testSignsRequestsProperly()
 {
     $request = new Request('GET', 'http://www.example.com');
     $request->getEventDispatcher();
     $credentials = new Credentials('a', 'b');
     $signature = $this->getMock('Aws\\Common\\Signature\\SignatureV4');
     // Ensure that signing the request occurred once with the correct args
     $signature->expects($this->once())->method('signRequest')->with($this->equalTo($request), $this->equalTo($credentials));
     $listener = new SignatureListener($credentials, $signature);
     // Create a mock event
     $event = new Event(array('request' => $request));
     $listener->onRequestBeforeSend($event);
 }
开发者ID:cstuder,项目名称:nagios-plugins,代码行数:16,代码来源:SignatureListenerTest.php

示例2: addErrorHandler

 /**
  * Function to add an error handler to the request.  This could be used
  *
  * @param int     $httpStatus      HTTP status to error handle (-1 matches all)
  * @param Closure $func            Function to call on error
  * @param boolean $stopPropagation Boolean as to wether to stop event propagation
  */
 public function addErrorHandler($httpStatus, \Closure $func, $stopPropagation = true)
 {
     $request = $this->request;
     $this->request->getEventDispatcher()->addListener('request.error', function (\Guzzle\Common\Event $event) use($httpStatus, $stopPropagation, $func, $request) {
         if ($httpStatus == -1 || $event['response']->getStatusCode() == $httpStatus) {
             // Stop other events from firing if needed
             if ($stopPropagation) {
                 $event->stopPropagation();
             }
             //execute the callback
             $func($event, $request);
         }
     });
 }
开发者ID:summer11123,项目名称:trucker,代码行数:21,代码来源:RestRequest.php

示例3: testClonedRequestsUseNewInternalState

 /**
  * @covers Guzzle\Http\Message\Request::__clone
  */
 public function testClonedRequestsUseNewInternalState()
 {
     $p = new AsyncPlugin();
     $this->request->getEventDispatcher()->addSubscriber($p);
     $h = $this->request->getHeader('Host');
     $r = clone $this->request;
     $this->assertEquals(RequestInterface::STATE_NEW, $r->getState());
     $this->assertNotSame($r->getQuery(), $this->request->getQuery());
     $this->assertNotSame($r->getCurlOptions(), $this->request->getCurlOptions());
     $this->assertNotSame($r->getEventDispatcher(), $this->request->getEventDispatcher());
     $this->assertEquals($r->getHeaders(), $this->request->getHeaders());
     $this->assertNotSame($h, $r->getHeader('Host'));
     $this->assertNotSame($r->getParams(), $this->request->getParams());
     $this->assertTrue($this->request->getEventDispatcher()->hasListeners('request.sent'));
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:18,代码来源:RequestTest.php

示例4: testRequestBeforeSendIncludesContentLengthHeaderIfEmptyBody

 public function testRequestBeforeSendIncludesContentLengthHeaderIfEmptyBody()
 {
     $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
     $request = new Request('PUT', $this->getServer()->getUrl());
     $that = $this;
     $request->getEventDispatcher()->addListener('request.before_send', function ($event) use($that) {
         $that->assertEquals(0, $event['request']->getHeader('Content-Length'));
     });
     $this->multi->add($request);
     $this->multi->send();
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:11,代码来源:CurlMultiTest.php

示例5: onError

 public function onError($callable, $priority = 0)
 {
     $this->_request->getEventDispatcher()->addListener('request.error', $callable, $priority);
     return $this;
 }
开发者ID:sokil,项目名称:php-rest,代码行数:5,代码来源:Request.php

示例6: testAddsCookiesToRequests

 /**
  * @covers Guzzle\Http\Plugin\CookiePlugin
  */
 public function testAddsCookiesToRequests()
 {
     ArrayCookieJarTest::addCookies($this->storage);
     $this->storage->save(array('domain' => '.y.example.com', 'path' => '/acme/', 'cookie' => array('secure', 'sec'), 'expires' => Guzzle::getHttpDate('+1 day'), 'secure' => true));
     // Add a cookie that is only set on a specific port, so it wont be
     // added to the following requests
     $this->storage->save(array('domain' => '.y.example.com', 'path' => '/acme/', 'cookie' => array('test', 'port'), 'expires' => Guzzle::getHttpDate('+1 day'), 'secure' => false, 'port' => array(8192)));
     $request1 = new Request('GET', 'https://a.y.example.com/acme/');
     $request1->setClient(new Client());
     $request2 = new Request('GET', 'https://a.y.example.com/acme/');
     $request2->setClient(new Client());
     $request3 = new Request('GET', 'http://a.y.example.com/acme/');
     $request3->setClient(new Client());
     $request4 = new Request('GET', 'http://a.y.example.com/acme/');
     $request4->setClient(new Client());
     $request1->getEventDispatcher()->addSubscriber($this->plugin);
     $request2->getEventDispatcher()->addSubscriber($this->plugin);
     $request3->getEventDispatcher()->addSubscriber($this->plugin);
     $request4->getEventDispatcher()->addSubscriber($this->plugin);
     // Set a secure cookie
     $response1 = Response::fromMessage("HTTP/1.1 200 OK\r\nSet-Cookie: a=b; c=d; Max-Age=86400; domain=.example.com; secure;\r\n\r\n");
     // Set a regular cookie
     $response2 = Response::fromMessage("HTTP/1.1 200 OK\r\nSet-Cookie: e=f h; discard; domain=.example.com;\r\n\r\n");
     $response3 = Response::fromMessage("HTTP/1.1 200 OK\r\n\r\n");
     $request1->setResponse($response1, true);
     $request2->setResponse($response2, true);
     $request3->setResponse($response3, true);
     $request1->send();
     $request2->send();
     $request3->send();
     $this->assertEquals('muppet=cookie_monster;secure=sec', (string) $request1->getCookie());
     $this->assertEquals('muppet=cookie_monster;secure=sec;a=b;c=d', (string) $request2->getCookie());
     $this->assertEquals('muppet=cookie_monster;e=f h', (string) $request3->getCookie());
     // Clear the e=f h temporary cookie
     $this->plugin->clearTemporaryCookies();
     $request4->setResponse($response3, true);
     $request4->send();
     $this->assertEquals('muppet=cookie_monster', (string) $request4->getCookie());
 }
开发者ID:MicroSDHC,项目名称:justinribeiro.com-examples,代码行数:42,代码来源:CookiePluginTest.php


注:本文中的Guzzle\Http\Message\Request::getEventDispatcher方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。