1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace App\Controller;
- use Psr\Log\LoggerInterface;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Session\SessionInterface;
- class LuckyController extends Controller {
- /**
- * @Route(
- * name="lucky-number",
- * path="/lucky/number"
- * )
- *
- * @see config/services.yaml
- *
- * Notice how we overrode auto-wiring to receive an instance of App\Logger.
- */
- public function number(LoggerInterface $logger, Request $request) {
- $number = $request->query->has('value')
- ? (int) $request->query->get('value')
- : mt_rand(0, 100);
- $logger->notice("We sent $number");
- return $this->render("lucky/number.html.twig", [
- "number" => $number,
- ]);
- }
- /**
- * @\Symfony\Component\Routing\Annotation\Route(
- * name = "lucky-not-found",
- * path = "/lucky/not-found"
- * )
- */
- public function notFound() {
- $notFound = $this->createNotFoundException();
- throw $this->createAccessDeniedException("Denied because it was not found", $notFound);
- }
- /**
- * @\Symfony\Component\Routing\Annotation\Route(
- * name = "lucky-denied",
- * path = "/lucky/denied"
- * )
- */
- public function denied() {
- $denied = $this->createAccessDeniedException();
- throw $this->createNotFoundException("Not found because it was denied", $denied);
- }
- }
|