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


PHP BeforeEvent::intercept方法代码示例

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


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

示例1: onBefore

 public function onBefore(BeforeEvent $event)
 {
     $request = $event->getRequest();
     if (file_exists($this->getFullFilePath($request))) {
         $responsedata = file_get_contents($this->getFullFilePath($request));
         $mf = new MessageFactory();
         $event->intercept($mf->fromMessage($responsedata));
     }
 }
开发者ID:callcolor,项目名称:GuzzleRecorder,代码行数:9,代码来源:GuzzleRecorder.php

示例2: onBefore

 /**
  * @throws \OutOfBoundsException|\Exception
  */
 public function onBefore(BeforeEvent $event)
 {
     if (!($item = array_shift($this->queue))) {
         throw new \OutOfBoundsException('Mock queue is empty');
     } elseif ($item instanceof RequestException) {
         throw $item;
     }
     // Emulate reading a response body
     $request = $event->getRequest();
     if ($this->readBodies && $request->getBody()) {
         while (!$request->getBody()->eof()) {
             $request->getBody()->read(8096);
         }
     }
     $saveTo = $event->getRequest()->getConfig()->get('save_to');
     if (null !== $saveTo) {
         $body = $item->getBody();
         if (is_resource($saveTo)) {
             fwrite($saveTo, $body);
         } elseif (is_string($saveTo)) {
             file_put_contents($saveTo, $body);
         } elseif ($saveTo instanceof StreamInterface) {
             $saveTo->write($body);
         }
     }
     $event->intercept($item);
 }
开发者ID:453111208,项目名称:bbc,代码行数:30,代码来源:Mock.php

示例3: onBefore

 public function onBefore(BeforeEvent $event)
 {
     $request = $event->getRequest();
     if (!($response = $this->cache->fetch($request->__toString()))) {
         return;
     }
     $event->intercept($response);
 }
开发者ID:v4sp1,项目名称:LolApiBundle,代码行数:8,代码来源:CacheSubscriber.php

示例4: onBefore

 public function onBefore(BeforeEvent $event)
 {
     $request = $event->getRequest();
     if (isset(self::$purgeMethods[$request->getMethod()])) {
         $this->storage->purge($request->getUrl());
         if ('PURGE' === $request->getMethod()) {
             $event->intercept(new Response(204));
         }
     }
 }
开发者ID:thomaschaaf,项目名称:cache-subscriber,代码行数:10,代码来源:PurgeSubscriber.php

示例5: testInterceptsWithEvent

 public function testInterceptsWithEvent()
 {
     $t = new Transaction(new Client(), new Request('GET', '/'));
     $t->exception = new \Exception('foo');
     $e = new BeforeEvent($t);
     $response = new Response(200);
     $e->intercept($response);
     $this->assertTrue($e->isPropagationStopped());
     $this->assertSame($t->response, $response);
     $this->assertNull($t->exception);
 }
开发者ID:453111208,项目名称:bbc,代码行数:11,代码来源:BeforeEventTest.php

示例6: testInterceptsWithEvent

 public function testInterceptsWithEvent()
 {
     $response = new Response(200);
     $res = null;
     $t = new Transaction(new Client(), new Request('GET', '/'));
     $t->getRequest()->getEmitter()->on('complete', function ($e) use(&$res) {
         $res = $e;
     });
     $e = new BeforeEvent($t);
     $e->intercept($response);
     $this->assertTrue($e->isPropagationStopped());
     $this->assertSame($res->getClient(), $e->getClient());
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:13,代码来源:RequestBeforeSendEventTest.php

示例7: onBefore

 /**
  * @throws \OutOfBoundsException|\Exception
  */
 public function onBefore(BeforeEvent $event)
 {
     if (!($item = array_shift($this->queue))) {
         throw new \OutOfBoundsException('Mock queue is empty');
     } elseif ($item instanceof RequestException) {
         throw $item;
     }
     // Emulate reading a response body
     $request = $event->getRequest();
     if ($this->readBodies && $request->getBody()) {
         while (!$request->getBody()->eof()) {
             $request->getBody()->read(8096);
         }
     }
     $event->intercept($item);
 }
开发者ID:hexcode007,项目名称:yfcms,代码行数:19,代码来源:Mock.php

示例8: cacheCheck

 public function cacheCheck(BeforeEvent $event, $name)
 {
     $request = $event->getRequest();
     if ($request->getMethod() == 'GET') {
         $url = substr($request->getUrl(), 0, strpos($request->getUrl(), '?'));
         if (!preg_match('/token|oauth/', $url)) {
             $this->_cache_name = md5($request->getUrl() . (string) $request->getBody());
             if ($cache = $this->store->get($this->_cache_name, NULL)) {
                 \Log::info('getting response from cache');
                 $body = \GuzzleHttp\Stream\create(json_encode($cache));
                 $response = new \GuzzleHttp\Message\Response(200, array(), $body);
                 $event->intercept($response);
                 $event->stopPropagation();
             }
         }
     }
 }
开发者ID:onefasteuro,项目名称:oauth-app,代码行数:17,代码来源:RequestCache.php

示例9: cacheCheck

 public function cacheCheck(BeforeEvent $event, $name)
 {
     if (!$this->cache) {
         return;
     }
     $request = $event->getRequest();
     if ($request->getMethod() == 'GET') {
         $this->_cache_name = md5($request->getUrl() . (string) $request->getBody());
         if ($cache = $this->store->get($this->_cache_name, NULL)) {
             \Log::info('getting response from cache');
             $body = \GuzzleHttp\Stream\create($cache);
             $response = new \GuzzleHttp\Message\Response(200, array(), $body);
             $event->intercept($response);
             $event->stopPropagation();
         }
     }
 }
开发者ID:onefasteuro,项目名称:http-client,代码行数:17,代码来源:CacheSubscriber.php

示例10: onBefore

 public function onBefore(BeforeEvent $event)
 {
     $request = $event->getRequest();
     if (!$this->enabled) {
         $request->getConfig()->set('cache.disable', true);
     }
     if (!$this->canCacheRequest($request)) {
         $this->cacheMiss($request);
         return;
     }
     if (!($response = $this->storage->fetch($request))) {
         $this->cacheMiss($request);
         return;
     }
     $request->getConfig()->set('cache_lookup', 'HIT');
     $request->getConfig()->set('cache_hit', true);
     $event->intercept($response);
 }
开发者ID:QSimon,项目名称:CsaGuzzleBundle,代码行数:18,代码来源:CacheSubscriber.php

示例11: onBefore

 /**
  * @throws \OutOfBoundsException|\Exception
  */
 public function onBefore(BeforeEvent $event)
 {
     if (!($item = array_shift($this->queue))) {
         throw new \OutOfBoundsException('Mock queue is empty');
     } elseif ($item instanceof RequestException) {
         throw $item;
     }
     // Emulate the receiving of the response headers
     $request = $event->getRequest();
     $transaction = new Transaction($event->getClient(), $request);
     $transaction->setResponse($item);
     $request->getEmitter()->emit('headers', new HeadersEvent($transaction));
     // Emulate reading a response body
     if ($this->readBodies && $request->getBody()) {
         while (!$request->getBody()->eof()) {
             $request->getBody()->read(8096);
         }
     }
     $event->intercept($item);
 }
开发者ID:PodWhoo,项目名称:sitepoint_codes,代码行数:23,代码来源:Mock.php

示例12: fail

 protected function fail(\Exception $error, BeforeEvent $event)
 {
     $this->exceptions[] = $error;
     // Set a stub response.
     // The exception will actually be thrown in
     // `verify()`
     // If we threw the exception here,
     // it would be caught by Guzzle,
     // and wrapped into a RequestException
     $event->intercept(new Response(200));
 }
开发者ID:lezhnev74,项目名称:GuzzleHttpMock,代码行数:11,代码来源:Mock.php

示例13: onBefore

 /**
  * Checks if a request can be cached, and if so, intercepts with a cached
  * response is available.
  *
  * @param BeforeEvent $event
  */
 public function onBefore(BeforeEvent $event)
 {
     $request = $event->getRequest();
     if (!$this->canCacheRequest($request)) {
         $this->cacheMiss($request);
         return;
     }
     if (!($response = $this->storage->fetch($request))) {
         $this->cacheMiss($request);
         return;
     }
     $response->setHeader('Age', Utils::getResponseAge($response));
     $valid = $this->validate($request, $response);
     // Validate that the response satisfies the request
     if ($valid) {
         $request->getConfig()->set('cache_lookup', 'HIT');
         $request->getConfig()->set('cache_hit', true);
         $event->intercept($response);
     } else {
         $this->cacheMiss($request);
     }
 }
开发者ID:thomaschaaf,项目名称:cache-subscriber,代码行数:28,代码来源:CacheSubscriber.php

示例14: interceptResponse

 public function interceptResponse(BeforeEvent $event)
 {
     $response = MockResponse::getResponse($event->getRequest());
     $event->intercept($response);
     $event->stopPropagation();
 }
开发者ID:fillup,项目名称:walmart-partner-api-sdk-php,代码行数:6,代码来源:MockSubscriber.php

示例15: onBefore

 /**
  * Check if the request is cached and intercept it.
  *
  * @param BeforeEvent $event Guzzle 4/5 event.
  *
  * @return void
  */
 public function onBefore(BeforeEvent $event)
 {
     $request = $event->getRequest();
     $this->request = $request;
     if (!Utils::canCacheRequest($request)) {
         return;
     }
     $key = $request->getMethod() . ' ' . $request->getUrl();
     if (!$this->cache->contains($key)) {
         return;
     }
     $response = $this->cache->fetch($key);
     $event->intercept($response);
 }
开发者ID:emanueleminotto,项目名称:guzzle-cache-subscriber,代码行数:21,代码来源:CacheSubscriber.php


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