選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

SmallOverloadController.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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)
  13. {
  14. $entities = $this->get('doctrine')->getRepository(SmallOverload1::class)->findAll();
  15. $this
  16. ->writeSession($session)
  17. ->readSession($session)
  18. ->fireEvent()
  19. ->validate($entities);
  20. return $this->render(
  21. '@SmallOverload/SmallOverload/smallOverload.html.twig',
  22. ['smallOverloads' => $entities]
  23. );
  24. }
  25. /** @return $this */
  26. protected function writeSession(SessionInterface $session)
  27. {
  28. for ($x = 1; $x <= 10; $x++) {
  29. $session->set('overload-' . $x, 'overload-' . $x . '-value');
  30. }
  31. return $this;
  32. }
  33. /** @return $this */
  34. protected function readSession(SessionInterface $session)
  35. {
  36. for ($x = 1; $x <= 20; $x++) {
  37. $session->get('overload-' . $x, 'overload-' . $x . '-value-not-found');
  38. }
  39. return $this;
  40. }
  41. /** @return $this */
  42. protected function fireEvent()
  43. {
  44. $event = new Event();
  45. $this->get('event_dispatcher')->dispatch('phpbenchmarks.smallOverload', $event);
  46. return $this;
  47. }
  48. /** @return $this */
  49. protected function validate(array $entities)
  50. {
  51. $validator = $this->get('validator');
  52. for ($x = 0; $x < 10; $x++) {
  53. $violations = $validator->validate($entities[$x], null, 'smallOverload');
  54. if (count($violations) > 0) {
  55. throw new HttpException(500, 'Validation error');
  56. }
  57. }
  58. return $this;
  59. }
  60. }