Issues (7)

Twig/CurrentSiteExtension.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace FH\Bundle\MultiSiteBundle\Twig;
6
7
use FH\Bundle\MultiSiteBundle\Site\SiteInterface;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\RequestStack;
10
use Twig\Extension\AbstractExtension;
11
use Twig\TwigFunction;
12
13
/**
14
 * @author Joris van de Sande <[email protected]>
15
 */
16
final class CurrentSiteExtension extends AbstractExtension
17
{
18
    private $requestStack;
19
20
    public function __construct(RequestStack $requestStack)
21
    {
22
        $this->requestStack = $requestStack;
23
    }
24
25
    public function getFunctions(): array
26
    {
27
        return [
28
            new TwigFunction('current_site', [$this, 'getCurrentSite']),
29
        ];
30
    }
31
32
    public function getCurrentSite(): ?SiteInterface
33
    {
34
        $request = method_exists($this->requestStack, 'getMainRequest') ? $this->requestStack->getMainRequest() : $this->requestStack->getMasterRequest();
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\HttpFo...ack::getMasterRequest() has been deprecated: since symfony/http-foundation 5.3, use getMainRequest() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

34
        $request = method_exists($this->requestStack, 'getMainRequest') ? $this->requestStack->getMainRequest() : /** @scrutinizer ignore-deprecated */ $this->requestStack->getMasterRequest();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
35
36
        if (!$request instanceof Request) {
37
            return null;
38
        }
39
40
        return $request->get('site');
41
    }
42
}
43