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.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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()
  13. {
  14. $session = $this->get('session');
  15. $entities = $this->get('doctrine')->getRepository(SmallOverload1::class)->findAll();
  16. $this
  17. ->writeSession($session)
  18. ->readSession($session)
  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 fireEvent()
  44. {
  45. $event = new Event();
  46. $this->get('event_dispatcher')->dispatch('phpbenchmarks.smallOverload', $event);
  47. return $this;
  48. }
  49. /** @return $this */
  50. protected function validate(array $entities)
  51. {
  52. $validator = $this->get('validator');
  53. for ($x = 0; $x < 10; $x++) {
  54. $violations = $validator->validate($entities[$x], null, 'smallOverload');
  55. if (count($violations) > 0) {
  56. throw new HttpException(500, 'Validation error');
  57. }
  58. }
  59. return $this;
  60. }
  61. }