Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Routing / RedirectDestination.php
1 <?php
2
3 namespace Drupal\Core\Routing;
4
5 use Drupal\Component\Utility\UrlHelper;
6 use Symfony\Component\HttpFoundation\RequestStack;
7
8 /**
9  * Provides helpers for redirect destinations.
10  */
11 class RedirectDestination implements RedirectDestinationInterface {
12
13   /**
14    * The request stack.
15    *
16    * @var \Symfony\Component\HttpFoundation\RequestStack
17    */
18   protected $requestStack;
19
20   /**
21    * The URL generator.
22    *
23    * @var \Drupal\Core\Routing\UrlGeneratorInterface
24    */
25   protected $urlGenerator;
26
27   /**
28    * The destination used by the current request.
29    *
30    * @var string
31    */
32   protected $destination;
33
34   /**
35    * Constructs a new RedirectDestination instance.
36    *
37    * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
38    *   The request stack.
39    * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
40    *   The URL generator.
41    */
42   public function __construct(RequestStack $request_stack, UrlGeneratorInterface $url_generator) {
43     $this->requestStack = $request_stack;
44     $this->urlGenerator = $url_generator;
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function getAsArray() {
51     return ['destination' => $this->get()];
52   }
53
54   /**
55    * {@inheritdoc}
56    */
57   public function get() {
58     if (!isset($this->destination)) {
59       $query = $this->requestStack->getCurrentRequest()->query;
60       if (UrlHelper::isExternal($query->get('destination'))) {
61         $this->destination = '/';
62       }
63       elseif ($query->has('destination')) {
64         $this->destination = $query->get('destination');
65       }
66       else {
67         $this->destination = $this->urlGenerator->generateFromRoute('<current>', [], ['query' => UrlHelper::filterQueryParameters($query->all())]);
68       }
69     }
70
71     return $this->destination;
72   }
73
74   /**
75    * {@inheritdoc}
76    */
77   public function set($new_destination) {
78     $this->destination = $new_destination;
79     return $this;
80   }
81
82 }