1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys PackBundle package.
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Rapsys\PackBundle\Context
;
14 use Symfony\Component\Asset\Context\RequestStackContext
as BaseRequestStackContext
;
15 use Symfony\Component\HttpFoundation\RequestStack
;
20 class RequestStackContext
extends BaseRequestStackContext
{
21 //RequestStack instance
22 private $requestStack;
30 public function __construct(RequestStack
$requestStack, string $basePath = '', bool $secure = false) {
31 //Call parent constructor
32 parent
::__construct($requestStack, $basePath, $secure);
35 $this->requestStack
= $requestStack;
38 $this->basePath
= $basePath;
42 * Returns the base url
44 * @return string The base url
46 public function getBaseUrl(): string {
48 if (!$request = $this->requestStack
->getMainRequest()) {
50 return $this->basePath
;
54 return $request->getSchemeAndHttpHost().$request->getBaseUrl();