|
@@ -14,7 +14,8 @@ class LuckyController extends Controller {
|
|
|
/**
|
|
|
* @Route(
|
|
|
* name="lucky-number",
|
|
|
- * path="/lucky/number"
|
|
|
+ * path="/lucky/number",
|
|
|
+ * methods={"GET", "POST", "PUT", "PATCH"}
|
|
|
* )
|
|
|
*
|
|
|
* @see config/services.yaml
|
|
@@ -26,9 +27,20 @@ class LuckyController extends Controller {
|
|
|
? (int) $request->query->get('value')
|
|
|
: mt_rand(0, 100);
|
|
|
|
|
|
- $logger->notice("We sent $number");
|
|
|
+ /* Example features of the Request */
|
|
|
+ assert(false === $request->isXmlHttpRequest());
|
|
|
+
|
|
|
+ // Uses Accept-Language header.
|
|
|
+ $preferred = $request->getPreferredLanguage(['en', 'fr']);
|
|
|
+
|
|
|
+ // Empty on GET, valid on PATH, POST, PUT.
|
|
|
+ $requestValue = $request->request->get('value');
|
|
|
+
|
|
|
+ $logger->notice("We sent $number on GET, $requestValue on POST/PUT/PATCH");
|
|
|
return $this->render("lucky/number.html.twig", [
|
|
|
"number" => $number,
|
|
|
+ // No need for cookies->all(): Twig can use {% for %} on iterators.
|
|
|
+ "cookies" => $request->cookies,
|
|
|
]);
|
|
|
}
|
|
|
|