Ejemplo n.º 1
0
 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();
             }
         }
     }
 }
Ejemplo n.º 2
0
 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();
         }
     }
 }
 public function interceptResponse(BeforeEvent $event)
 {
     $response = MockResponse::getResponse($event->getRequest());
     $event->intercept($response);
     $event->stopPropagation();
 }