Symfony\Component\HttpFoundation\Request::getBasePath PHP Method

getBasePath() public method

Suppose that an index.php file instantiates this request object: * http://localhost/index.php returns an empty string * http://localhost/index.php/page returns an empty string * http://localhost/web/index.php returns '/web' * http://localhost/we%20b/index.php returns '/we%20b'
public getBasePath ( ) : string
return string The raw path (i.e. not urldecoded)
    public function getBasePath()
    {
        if (null === $this->basePath) {
            $this->basePath = $this->prepareBasePath();
        }

        return $this->basePath;
    }

Usage Example

Example #1
0
 public function thumbAction(Request $request, Application $app)
 {
     $source = $request->get('src', false);
     $width = $request->get('width', 250);
     // Do requested thumbnail in correct format already exists ?
     if ($app['flysystems']['thumbs']->has($width . "/" . $source)) {
         return $app->redirect($request->getBasePath() . '/thumbs/' . $width . '/' . $source, 301);
     }
     // Do requested file exists ?
     if (!$source || !$app['flysystems']['local']->has($source)) {
         return new Response("Source file not found.", 404);
     }
     try {
         $contents = $app['flysystems']['local']->read($source);
         $imageManager = new ImageManager();
         $image = $imageManager->make($contents);
         $image->resize($width, null, function ($constraint) {
             $constraint->aspectRatio();
         });
         $info = $app['flysystems']['local']->getWithMetadata($source, ['mimetype']);
         $image->encode($info['mimetype']);
         $app['flysystems']['thumbs']->put($width . "/" . $source, $image);
         return $app->redirect($request->getBasePath() . '/thumbs/' . $width . '/' . $source, 301);
     } catch (\Exception $e) {
         return new Response("Erreur !", 500);
     }
     // Should not happen, everything failed. Display not found image :(
     return $app->redirect($request->getBasePath() . '/assets/img/' . $width . '_not-found.png', 302);
 }
All Usage Examples Of Symfony\Component\HttpFoundation\Request::getBasePath