Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 * This file is part of the Symfony CMF package.
|
Chris@0
|
5 *
|
Chris@0
|
6 * (c) 2011-2015 Symfony CMF
|
Chris@0
|
7 *
|
Chris@0
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
9 * file that was distributed with this source code.
|
Chris@0
|
10 */
|
Chris@0
|
11
|
Chris@0
|
12 namespace Symfony\Cmf\Component\Routing\Event;
|
Chris@0
|
13
|
Chris@0
|
14 use Symfony\Component\EventDispatcher\Event;
|
Chris@0
|
15 use Symfony\Component\Routing\Route;
|
Chris@0
|
16
|
Chris@0
|
17 /**
|
Chris@0
|
18 * Event fired before the dynamic router generates a url for a route.
|
Chris@0
|
19 *
|
Chris@0
|
20 * The name, parameters and absolute properties have the semantics of
|
Chris@0
|
21 * UrlGeneratorInterface::generate()
|
Chris@0
|
22 *
|
Chris@0
|
23 * @author Ben Glassman
|
Chris@0
|
24 *
|
Chris@0
|
25 * @see \Symfony\Component\Routing\Generator\UrlGeneratorInterface::generate()
|
Chris@0
|
26 */
|
Chris@0
|
27 class RouterGenerateEvent extends Event
|
Chris@0
|
28 {
|
Chris@0
|
29 /**
|
Chris@0
|
30 * The name of the route or the Route instance to generate.
|
Chris@0
|
31 *
|
Chris@0
|
32 * @var string|Route
|
Chris@0
|
33 */
|
Chris@0
|
34 private $route;
|
Chris@0
|
35
|
Chris@0
|
36 /**
|
Chris@0
|
37 * The parameters to use when generating the url.
|
Chris@0
|
38 *
|
Chris@0
|
39 * @var array
|
Chris@0
|
40 */
|
Chris@0
|
41 private $parameters;
|
Chris@0
|
42
|
Chris@0
|
43 /**
|
Chris@0
|
44 * The type of reference to be generated (one of the constants in UrlGeneratorInterface).
|
Chris@0
|
45 *
|
Chris@0
|
46 * @var bool|string
|
Chris@0
|
47 */
|
Chris@0
|
48 private $referenceType;
|
Chris@0
|
49
|
Chris@0
|
50 /**
|
Chris@0
|
51 * @param string|Route $route The route name or object
|
Chris@0
|
52 * @param array $parameters The parameters to use
|
Chris@0
|
53 * @param bool|string $referenceType The type of reference to be generated
|
Chris@0
|
54 */
|
Chris@0
|
55 public function __construct($route, $parameters, $referenceType)
|
Chris@0
|
56 {
|
Chris@0
|
57 $this->route = $route;
|
Chris@0
|
58 $this->parameters = $parameters;
|
Chris@0
|
59 $this->referenceType = $referenceType;
|
Chris@0
|
60 }
|
Chris@0
|
61
|
Chris@0
|
62 /**
|
Chris@0
|
63 * Get route name or object.
|
Chris@0
|
64 *
|
Chris@0
|
65 * @return string|Route
|
Chris@0
|
66 */
|
Chris@0
|
67 public function getRoute()
|
Chris@0
|
68 {
|
Chris@0
|
69 return $this->route;
|
Chris@0
|
70 }
|
Chris@0
|
71
|
Chris@0
|
72 /**
|
Chris@0
|
73 * Set route name or object.
|
Chris@0
|
74 *
|
Chris@0
|
75 * @param string|Route $route
|
Chris@0
|
76 */
|
Chris@0
|
77 public function setRoute($route)
|
Chris@0
|
78 {
|
Chris@0
|
79 $this->route = $route;
|
Chris@0
|
80 }
|
Chris@0
|
81
|
Chris@0
|
82 /**
|
Chris@0
|
83 * Get route parameters.
|
Chris@0
|
84 *
|
Chris@0
|
85 * @return array
|
Chris@0
|
86 */
|
Chris@0
|
87 public function getParameters()
|
Chris@0
|
88 {
|
Chris@0
|
89 return $this->parameters;
|
Chris@0
|
90 }
|
Chris@0
|
91
|
Chris@0
|
92 /**
|
Chris@0
|
93 * Set the route parameters.
|
Chris@0
|
94 *
|
Chris@0
|
95 * @param array $parameters
|
Chris@0
|
96 */
|
Chris@0
|
97 public function setParameters(array $parameters)
|
Chris@0
|
98 {
|
Chris@0
|
99 $this->parameters = $parameters;
|
Chris@0
|
100 }
|
Chris@0
|
101
|
Chris@0
|
102 /**
|
Chris@0
|
103 * Set a route parameter.
|
Chris@0
|
104 *
|
Chris@0
|
105 * @param string $key
|
Chris@0
|
106 * @param mixed $value
|
Chris@0
|
107 */
|
Chris@0
|
108 public function setParameter($key, $value)
|
Chris@0
|
109 {
|
Chris@0
|
110 $this->parameters[$key] = $value;
|
Chris@0
|
111 }
|
Chris@0
|
112
|
Chris@0
|
113 /**
|
Chris@0
|
114 * Remove a route parameter by key.
|
Chris@0
|
115 *
|
Chris@0
|
116 * @param string $key
|
Chris@0
|
117 */
|
Chris@0
|
118 public function removeParameter($key)
|
Chris@0
|
119 {
|
Chris@0
|
120 unset($this->parameters[$key]);
|
Chris@0
|
121 }
|
Chris@0
|
122
|
Chris@0
|
123 /**
|
Chris@0
|
124 * The type of reference to be generated (one of the constants in UrlGeneratorInterface).
|
Chris@0
|
125 *
|
Chris@0
|
126 * @return bool|string
|
Chris@0
|
127 */
|
Chris@0
|
128 public function getReferenceType()
|
Chris@0
|
129 {
|
Chris@0
|
130 return $this->referenceType;
|
Chris@0
|
131 }
|
Chris@0
|
132
|
Chris@0
|
133 /**
|
Chris@0
|
134 * The type of reference to be generated (one of the constants in UrlGeneratorInterface).
|
Chris@0
|
135 *
|
Chris@0
|
136 * @param bool|string $referenceType
|
Chris@0
|
137 */
|
Chris@0
|
138 public function setReferenceType($referenceType)
|
Chris@0
|
139 {
|
Chris@0
|
140 $this->referenceType = $referenceType;
|
Chris@0
|
141 }
|
Chris@0
|
142 }
|