public function isCached(RequestEvent $event) { $response = new Response(301); $event->setResponse($response); $event->stopPropagation(); return $response; }
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'); } }
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()); } }
/** * 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; }
/** * @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()); }
public function onBeforeSend(RequestEvent $event) { $event->getRequest()->getParameters()->set('include_adult', $this->includeAdult === true ? 'true' : 'false'); }
public function onBeforeSend(RequestEvent $event) { $event->getRequest()->getParameters()->set('language', $this->language); }
public function onBeforeSend(RequestEvent $event) { $event->getRequest()->getParameters()->set('api_key', $this->token->getToken()); }
public function onBeforeSend(RequestEvent $event) { $event->getRequest()->getHeaders()->set('Accept', 'application/json'); }
public function onBeforeSend(RequestEvent $event) { $event->getRequest()->getHeaders()->set('User-Agent', sprintf('wtfzdotnet/php-tmdb-api (v%s)', Client::VERSION)); }