Get the current requested extension (if any)
public getExtension ( ) : string | null | ||
Résultat | string | null |
/** * @covers Imbo\Http\Request\Request::getExtension */ public function testSetGetExtension() { $extension = 'jpg'; $this->assertNull($this->request->getExtension()); $route = new Route(); $this->request->setRoute($route); $this->assertNull($this->request->getExtension()); $route->set('extension', $extension); $this->assertSame($extension, $this->request->getExtension()); }
/** * Generate a cache key * * @param Request $request The current request instance * @return string Returns a string that can be used as a cache key for the current image */ private function getCacheKey(Request $request) { $user = $request->getUser(); $imageIdentifier = $request->getImageIdentifier(); $accept = $request->headers->get('Accept', '*/*'); $accept = array_filter(explode(',', $accept), function (&$value) { // Trim whitespace $value = trim($value); // Remove optional params $pos = strpos($value, ';'); if ($pos !== false) { $value = substr($value, 0, $pos); } // Keep values starting with "*/" or "image/" return $value[0] === '*' && $value[1] === '/' || substr($value, 0, 6) === 'image/'; }); // Sort the remaining values sort($accept); $accept = implode(',', $accept); $extension = $request->getExtension(); $transformations = $request->query->get('t'); if (!empty($transformations)) { $transformations = implode('&', $transformations); } return md5($user . $imageIdentifier . $accept . $extension . $transformations); }
/** * 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; }