]> Raphaël G. Git Repositories - packbundle/blob - Context/RequestStackContext.php
Rename routes config to match new bundle alias
[packbundle] / Context / RequestStackContext.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys PackBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\PackBundle\Context;
13
14 use Symfony\Component\Asset\Context\RequestStackContext as BaseRequestStackContext;
15 use Symfony\Component\HttpFoundation\RequestStack;
16
17 /**
18 * {@inheritdoc}
19 */
20 class RequestStackContext extends BaseRequestStackContext {
21 /**
22 * {@inheritdoc}
23 */
24 public function __construct(protected RequestStack $requestStack, protected string $basePath = '', protected bool $secure = false) {
25 //Call parent constructor
26 parent::__construct($requestStack, $basePath, $secure);
27 }
28
29 /**
30 * Returns the base url
31 *
32 * @return string The base url
33 */
34 public function getBaseUrl(): string {
35 //Without request
36 if (!$request = $this->requestStack->getMainRequest()) {
37 //Return base path
38 return $this->basePath;
39 }
40
41 //Return base uri
42 return $request->getSchemeAndHttpHost().$request->getBaseUrl();
43 }
44 }