vendor/sensio/framework-extra-bundle/src/Configuration/Security.php line 21

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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 Sensio\Bundle\FrameworkExtraBundle\Configuration;
  11. /**
  12. * The Security class handles the Security annotation.
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. * @Annotation
  16. */
  17. #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
  18. class Security extends ConfigurationAnnotation
  19. {
  20. /**
  21. * The expression evaluated to allow or deny access.
  22. *
  23. * @var string
  24. */
  25. private $expression;
  26. /**
  27. * If set, will throw Symfony\Component\HttpKernel\Exception\HttpException
  28. * with the given $statusCode.
  29. * If null, Symfony\Component\Security\Core\Exception\AccessDeniedException.
  30. * will be used.
  31. *
  32. * @var int|null
  33. */
  34. protected $statusCode;
  35. /**
  36. * The message of the exception.
  37. *
  38. * @var string
  39. */
  40. protected $message = 'Access denied.';
  41. /**
  42. * @param array|string $data
  43. */
  44. public function __construct(
  45. $data = [],
  46. string $message = null,
  47. ?int $statusCode = null
  48. ) {
  49. $values = [];
  50. if (\is_string($data)) {
  51. $values['expression'] = $data;
  52. } else {
  53. $values = $data;
  54. }
  55. $values['message'] = $values['message'] ?? $message ?? $this->message;
  56. $values['statusCode'] = $values['statusCode'] ?? $statusCode;
  57. parent::__construct($values);
  58. }
  59. public function getExpression()
  60. {
  61. return $this->expression;
  62. }
  63. public function setExpression($expression)
  64. {
  65. $this->expression = $expression;
  66. }
  67. public function getStatusCode()
  68. {
  69. return $this->statusCode;
  70. }
  71. public function setStatusCode($statusCode)
  72. {
  73. $this->statusCode = $statusCode;
  74. }
  75. public function getMessage()
  76. {
  77. return $this->message;
  78. }
  79. public function setMessage($message)
  80. {
  81. $this->message = $message;
  82. }
  83. public function setValue($expression)
  84. {
  85. $this->setExpression($expression);
  86. }
  87. public function getAliasName()
  88. {
  89. return 'security';
  90. }
  91. public function allowArray()
  92. {
  93. return true;
  94. }
  95. }