@@ -81,6 +81,72 @@ public function redirect($url, $status = 302)
81
81
return new RedirectResponse ($ url , $ status );
82
82
}
83
83
84
+ /**
85
+ * Returns a RedirectResponse to the given route with the given parameters.
86
+ *
87
+ * @param string $route The name of the route
88
+ * @param array $parameters An array of parameters
89
+ * @param int $status The status code to use for the Response
90
+ *
91
+ * @return RedirectResponse
92
+ */
93
+ protected function redirectToRoute ($ route , array $ parameters = array (), $ status = 302 )
94
+ {
95
+ return $ this ->redirect ($ this ->generateUrl ($ route , $ parameters ), $ status );
96
+ }
97
+
98
+ /**
99
+ * Adds a flash message to the current session for type.
100
+ *
101
+ * @param string $type The type
102
+ * @param string $message The message
103
+ *
104
+ * @throws \LogicException
105
+ */
106
+ protected function addFlash ($ type , $ message )
107
+ {
108
+ if (!$ this ->container ->has ('session ' )) {
109
+ throw new \LogicException ('You can not use the addFlash method if sessions are disabled. ' );
110
+ }
111
+
112
+ $ this ->get ('session ' )->getFlashBag ()->add ($ type , $ message );
113
+ }
114
+
115
+ /**
116
+ * Checks if the attributes are granted against the current authentication token and optionally supplied object.
117
+ *
118
+ * @param mixed $attributes The attributes
119
+ * @param mixed $object The object
120
+ *
121
+ * @throws \LogicException
122
+ * @return bool
123
+ */
124
+ protected function isGranted ($ attributes , $ object = null )
125
+ {
126
+ if (!$ this ->container ->has ('security.context ' )) {
127
+ throw new \LogicException ('The SecurityBundle is not registered in your application. ' );
128
+ }
129
+
130
+ return $ this ->get ('security.context ' )->isGranted ($ attributes , $ object );
131
+ }
132
+
133
+ /**
134
+ * Throws an exception unless the attributes are granted against the current authentication token and optionally
135
+ * supplied object.
136
+ *
137
+ * @param mixed $attributes The attributes
138
+ * @param mixed $object The object
139
+ * @param string $message The message passed to the exception
140
+ *
141
+ * @throws AccessDeniedException
142
+ */
143
+ protected function denyAccessUnlessGranted ($ attributes , $ object = null , $ message = 'Access Denied. ' )
144
+ {
145
+ if (!$ this ->isGranted ($ attributes , $ object )) {
146
+ throw $ this ->createAccessDeniedException ($ message );
147
+ }
148
+ }
149
+
84
150
/**
85
151
* Returns a rendered view.
86
152
*
0 commit comments