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
|
|||
35 | |||
36 | if (!$request instanceof Request) { |
||
37 | return null; |
||
38 | } |
||
39 | |||
40 | return $request->get('site'); |
||
41 | } |
||
42 | } |
||
43 |
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.