コード例 #1
0
 public function isCached(RequestEvent $event)
 {
     $response = new Response(301);
     $event->setResponse($response);
     $event->stopPropagation();
     return $response;
 }
コード例 #2
0
 public function onBeforeSend(RequestEvent $event)
 {
     $method = $event->getRequest()->getMethod();
     if ($method == 'POST' || $method == 'PUT' || $method == 'PATCH' || $method == 'DELETE') {
         $event->getRequest()->getHeaders()->set('Content-Type', 'application/json');
     }
 }
コード例 #3
0
 public function onBeforeSend(RequestEvent $event)
 {
     if ($this->token instanceof GuestSessionToken) {
         $event->getRequest()->getParameters()->set('guest_session_id', $this->token->getToken());
     } else {
         $event->getRequest()->getParameters()->set('session_id', $this->token->getToken());
     }
 }
コード例 #4
0
 /**
  * Call upon the adapter to create an response object
  *
  * @param  RequestEvent $event
  * @throws \Exception
  * @return Response
  */
 public function sendRequest(RequestEvent $event)
 {
     switch ($event->getMethod()) {
         case 'GET':
             $response = $this->getHttpClient()->getAdapter()->get($event->getRequest());
             break;
         case 'HEAD':
             $response = $this->getHttpClient()->getAdapter()->head($event->getRequest());
             break;
         case 'POST':
             $response = $this->getHttpClient()->getAdapter()->post($event->getRequest());
             break;
         case 'PUT':
             $response = $this->getHttpClient()->getAdapter()->put($event->getRequest());
             break;
         case 'PATCH':
             $response = $this->getHttpClient()->getAdapter()->patch($event->getRequest());
             break;
         case 'DELETE':
             $response = $this->getHttpClient()->getAdapter()->delete($event->getRequest());
             break;
         default:
             throw new RuntimeException(sprintf('Unkown request method "%s".', $event->getMethod()));
     }
     return $response;
 }
コード例 #5
0
 /**
  * @test
  */
 public function isFunctional()
 {
     $requestEvent = new RequestEvent(new Request('/', 'POST', new ParameterBag(['query' => 'parameter']), new ParameterBag(['X-Monkey' => true]), new ParameterBag(['key' => 'value'])));
     $this->assertEquals('/', $requestEvent->getPath());
     $this->assertEquals('parameter', $requestEvent->getParameters()->get('query'));
     $this->assertEquals(true, $requestEvent->getHeaders()->get('X-Monkey'));
     $this->assertEquals('value', $requestEvent->getBody()->get('key'));
     $request = new Request('/foo/bar');
     $requestEvent->setRequest($request);
     $this->assertEquals('/foo/bar', $requestEvent->getPath());
 }
コード例 #6
0
 public function onBeforeSend(RequestEvent $event)
 {
     $event->getRequest()->getParameters()->set('include_adult', $this->includeAdult === true ? 'true' : 'false');
 }
コード例 #7
0
 public function onBeforeSend(RequestEvent $event)
 {
     $event->getRequest()->getParameters()->set('language', $this->language);
 }
コード例 #8
0
 public function onBeforeSend(RequestEvent $event)
 {
     $event->getRequest()->getParameters()->set('api_key', $this->token->getToken());
 }
コード例 #9
0
 public function onBeforeSend(RequestEvent $event)
 {
     $event->getRequest()->getHeaders()->set('Accept', 'application/json');
 }
コード例 #10
0
 public function onBeforeSend(RequestEvent $event)
 {
     $event->getRequest()->getHeaders()->set('User-Agent', sprintf('wtfzdotnet/php-tmdb-api (v%s)', Client::VERSION));
 }