forked from contao/contao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PageRedirect.php
66 lines (55 loc) · 1.27 KB
/
PageRedirect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/
namespace Contao;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Provide methods to handle a redirect page.
*/
class PageRedirect extends Frontend
{
/**
* Return a response object
*
* @param PageModel $objPage
*
* @return RedirectResponse
*/
public function getResponse($objPage)
{
$this->prepare($objPage);
$url = System::getContainer()->get('contao.insert_tag.parser')->replaceInline($objPage->url);
if (Validator::isRelativeUrl($url))
{
$url = Environment::get('path') . '/' . $url;
}
return new RedirectResponse($url, $this->getRedirectStatusCode($objPage));
}
/**
* Return the redirect status code
*
* @param PageModel $objPage
*
* @return integer
*/
protected function getRedirectStatusCode($objPage)
{
return ($objPage->redirect == 'temporary') ? 303 : 301;
}
/**
* @param PageModel $objPage
*/
private function prepare($objPage)
{
$GLOBALS['TL_LANGUAGE'] = $objPage->language;
$locale = str_replace('-', '_', $objPage->language);
$container = System::getContainer();
$container->get('request_stack')->getCurrentRequest()->setLocale($locale);
$container->get('translator')->setLocale($locale);
}
}