Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Routing / RedirectDestinationTrait.php
1 <?php
2
3 namespace Drupal\Core\Routing;
4
5 /**
6  * Wrapper methods for the Redirect Destination.
7  *
8  * This utility trait should only be used in application-level code, such as
9  * classes that would implement ContainerInjectionInterface. Services registered
10  * in the Container should not use this trait but inject the appropriate service
11  * directly for easier testing.
12  */
13 trait RedirectDestinationTrait {
14
15   /**
16    * The redirect destination service.
17    *
18    * @var \Drupal\Core\Routing\RedirectDestinationInterface
19    */
20   protected $redirectDestination;
21
22   /**
23    * Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
24    *
25    * @see \Drupal\Core\Routing\RedirectDestinationInterface::getAsArray()
26    *
27    * @return array
28    *   An associative array containing the key:
29    *   - destination: The value of the current request's 'destination' query
30    *     parameter, if present. This can be either a relative or absolute URL.
31    *     However, for security, redirection to external URLs is not performed.
32    *     If the query parameter isn't present, then the URL of the current
33    *     request is returned.
34    */
35   protected function getDestinationArray() {
36     return $this->getRedirectDestination()->getAsArray();
37   }
38
39   /**
40    * Returns the redirect destination service.
41    *
42    * @return \Drupal\Core\Routing\RedirectDestinationInterface
43    *   The redirect destination helper.
44    */
45   protected function getRedirectDestination() {
46     if (!isset($this->redirectDestination)) {
47       $this->redirectDestination = \Drupal::destination();
48     }
49
50     return $this->redirectDestination;
51   }
52
53   /**
54    * Sets the redirect destination service.
55    *
56    * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
57    *   The redirect destination service.
58    *
59    * @return $this
60    */
61   public function setRedirectDestination(RedirectDestinationInterface $redirect_destination) {
62     $this->redirectDestination = $redirect_destination;
63
64     return $this;
65   }
66
67 }