Bkwld\Croppa\Handler::handle PHP Method

handle() public method

Handles a Croppa style route
public handle ( string $request ) : Symfony\Component\HttpFoundation\StreamedResponse
$request string The `Request::path()`
return Symfony\Component\HttpFoundation\StreamedResponse
    public function handle($request)
    {
        // Validate the signing token
        if (($token = $this->url->signingToken($request)) && $token != $this->request->input('token')) {
            throw new NotFoundHttpException('Token mismatch');
        }
        // Create the image file
        $crop_path = $this->render($request);
        // Redirect to remote crops ...
        if ($this->storage->cropsAreRemote()) {
            return new RedirectResponse($this->url->pathToUrl($crop_path), 301);
            // ... or echo the image data to the browser
        } else {
            $absolute_path = $this->storage->getLocalCropsDirPath() . '/' . $crop_path;
            return new BinaryFileResponse($absolute_path, 200, ['Content-Type' => $this->getContentType($absolute_path)]);
        }
    }