/** * @dataProvider getQueryStrings */ public function testGetRawUriDecodesUri($queryString, $expectedQueryString) { $request = new Request([], [], [], [], [], ['SERVER_NAME' => 'imbo', 'SERVER_PORT' => 80, 'QUERY_STRING' => $queryString]); $uri = $request->getRawUri(); $this->assertSame($expectedQueryString, substr($uri, strpos($uri, '?') + 1)); }
/** * Construct a message body with the data we need * * @param string $eventName Event that was triggered * @param Request $request Request that triggered this event * @param Response $response Response for this request * @param Imbo\EventManager\EventInterface $eventName Current event * @return array */ public function constructMessageBody($eventName, Request $request, Response $response, EventInterface $event) { if ($response->getModel() instanceof ErrorModel) { trigger_error($response->getModel()->getErrorMessage()); return; } // Construct the basics $message = ['eventName' => $eventName, 'request' => ['date' => date('c'), 'user' => $request->getUser(), 'publicKey' => $request->getPublicKey(), 'extension' => $request->getExtension(), 'url' => $request->getRawUri(), 'clientIp' => $request->getClientIp()], 'response' => ['statusCode' => $response->getStatusCode()]]; // Include any JSON request body in the message if ($request->getContentType() === 'application/json') { $message['request']['body'] = $request->getContent(); } // See if we've got an image identifier for this request $imageIdentifier = $request->getImageIdentifier(); // The imageIdentifier was not part of the URL, see if we have it in the response model if (!$imageIdentifier) { $responseData = $response->getModel()->getData(); if (isset($responseData['imageIdentifier'])) { $imageIdentifier = $responseData['imageIdentifier']; } else { return $message; } } // Get image information $image = $this->getImageData($event, $imageIdentifier); // Construct an array of all the image information we have $message['image'] = ['identifier' => $imageIdentifier, 'user' => $image->getUser() ?: $request->getUser(), 'size' => $image->getFilesize(), 'extension' => $image->getExtension(), 'mime' => $image->getMimeType(), 'added' => $image->getAddedDate()->format(DateTime::ATOM), 'updated' => $image->getUpdatedDate()->format(DateTime::ATOM), 'width' => $image->getWidth(), 'height' => $image->getHeight(), 'metadata' => $image->getMetadata()]; return $message; }