vendor/drosalys/api-bundle/src/Action/Action.php line 25

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the drosalys/api-bundle package.
  4. *
  5. * (c) Benjamin Georgeault
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Drosalys\Bundle\ApiBundle\Action;
  11. use Drosalys\Bundle\ApiBundle\Action\Info\DeserializeInfo;
  12. use Drosalys\Bundle\ApiBundle\Action\Info\EventInfo;
  13. use Drosalys\Bundle\ApiBundle\Action\Info\FilterInfo;
  14. use Drosalys\Bundle\ApiBundle\Action\Info\PaginationInfo;
  15. use Drosalys\Bundle\ApiBundle\Action\Info\SerializeInfo;
  16. /**
  17. * Class Action
  18. *
  19. * @author Benjamin Georgeault
  20. */
  21. final class Action
  22. {
  23. private string $method;
  24. public function __construct(
  25. string $method = 'GET',
  26. private string $path = '/',
  27. private SerializeInfo|null $serializeInfo = null,
  28. private DeserializeInfo|null $deserializeInfo = null,
  29. private ?PaginationInfo $paginationInfo = null,
  30. private ?FilterInfo $filterInfo = null,
  31. private bool $hasSecurity = false,
  32. private ?EventInfo $persistInfo = null,
  33. private ?EventInfo $buildResponseInfo = null,
  34. ) {
  35. $this->method = strtoupper($method);
  36. }
  37. public function getMethod(): string
  38. {
  39. return $this->method;
  40. }
  41. public function isMethod(string $method): bool
  42. {
  43. return strtoupper($method) === $this->method;
  44. }
  45. public function getPath(): string
  46. {
  47. return $this->path;
  48. }
  49. public function getSerializeInfo(): SerializeInfo|null
  50. {
  51. return $this->serializeInfo;
  52. }
  53. public function getDeserializeInfo(): DeserializeInfo|null
  54. {
  55. return $this->deserializeInfo;
  56. }
  57. public function getPaginationInfo(): ?PaginationInfo
  58. {
  59. return $this->paginationInfo;
  60. }
  61. public function getFilterInfo(): ?FilterInfo
  62. {
  63. return $this->filterInfo;
  64. }
  65. public function hasSecurity(): bool
  66. {
  67. return $this->hasSecurity;
  68. }
  69. public function getPersistInfo(): ?EventInfo
  70. {
  71. return $this->persistInfo;
  72. }
  73. public function getBuildResponseInfo(): ?EventInfo
  74. {
  75. return $this->buildResponseInfo;
  76. }
  77. public function setController(object $controller): static
  78. {
  79. $this->getPersistInfo()?->setController($controller);
  80. $this->getBuildResponseInfo()?->setController($controller);
  81. $this->getDeserializeInfo()?->getEventInfo()?->setController($controller);
  82. return $this;
  83. }
  84. public function needController(): bool
  85. {
  86. return (null !== $this->getPersistInfo())
  87. || (null !== $this->getBuildResponseInfo())
  88. || (null !== $this->getDeserializeInfo() && null !== $this->getDeserializeInfo()->getEventInfo())
  89. ;
  90. }
  91. }