Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

SmallOverloadController.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace PhpBenchmarksSymfony\SmallOverloadBundle\Controller;
  3. use PhpBenchmarksSymfony\SmallOverloadBundle\Entity\SmallOverload1;
  4. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  5. use Symfony\Component\EventDispatcher\Event;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  8. use Symfony\Component\HttpKernel\Exception\HttpException;
  9. class SmallOverloadController extends Controller
  10. {
  11. /** @return Response */
  12. public function smallOverloadAction(SessionInterface $session): Response
  13. {
  14. $entities = $this->get('doctrine')->getRepository(SmallOverload1::class)->findAll();
  15. $this
  16. ->writeSession($session)
  17. ->readSession($session)
  18. ->log()
  19. ->fireEvent()
  20. ->validate($entities);
  21. return $this->render(
  22. '@SmallOverload/SmallOverload/smallOverload.html.twig',
  23. ['smallOverloads' => $entities]
  24. );
  25. }
  26. /** @return $this */
  27. protected function writeSession(SessionInterface $session)
  28. {
  29. for ($x = 1; $x <= 10; $x++) {
  30. $session->set('overload-' . $x, 'overload-' . $x . '-value');
  31. }
  32. return $this;
  33. }
  34. /** @return $this */
  35. protected function readSession(SessionInterface $session)
  36. {
  37. for ($x = 1; $x <= 20; $x++) {
  38. $session->get('overload-' . $x, 'overload-' . $x . '-value-not-found');
  39. }
  40. return $this;
  41. }
  42. /** @return $this */
  43. protected function log()
  44. {
  45. for ($x = 1; $x <= 10; $x++) {
  46. // $logger->notice('[Session ' . $session->getId() . '] Small overload message ' . $x);
  47. }
  48. return $this;
  49. }
  50. /** @return $this */
  51. protected function fireEvent()
  52. {
  53. $event = new Event();
  54. $this->get('event_dispatcher')->dispatch('phpbenchmarks.smallOverload', $event);
  55. return $this;
  56. }
  57. /** @return $this */
  58. protected function validate(array $entities)
  59. {
  60. $validator = $this->get('validator');
  61. for ($x = 0; $x < 10; $x++) {
  62. $violations = $validator->validate($entities[$x], null, 'smallOverload');
  63. if (count($violations) > 0) {
  64. throw new HttpException(500, 'Validation error');
  65. }
  66. }
  67. return $this;
  68. }
  69. }