vendor/sensio/framework-extra-bundle/src/Configuration/IsGranted.php line 58

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 Ryan Weaver <ryan@knpuniversity.com>
  15. * @Annotation
  16. */
  17. #[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
  18. class IsGranted extends ConfigurationAnnotation
  19. {
  20. /**
  21. * Sets the first argument that will be passed to isGranted().
  22. *
  23. * @var mixed
  24. */
  25. private $attributes;
  26. /**
  27. * Sets the second argument passed to isGranted().
  28. *
  29. * @var mixed
  30. */
  31. private $subject;
  32. /**
  33. * The message of the exception - has a nice default if not set.
  34. *
  35. * @var string
  36. */
  37. private $message;
  38. /**
  39. * If set, will throw Symfony\Component\HttpKernel\Exception\HttpException
  40. * with the given $statusCode.
  41. * If null, Symfony\Component\Security\Core\Exception\AccessDeniedException.
  42. * will be used.
  43. *
  44. * @var int|null
  45. */
  46. private $statusCode;
  47. /**
  48. * @param mixed $subject
  49. * @param array|string $data
  50. */
  51. public function __construct(
  52. $data = [],
  53. $subject = null,
  54. string $message = null,
  55. ?int $statusCode = null
  56. ) {
  57. $values = [];
  58. if (\is_string($data)) {
  59. $values['attributes'] = $data;
  60. } else {
  61. $values = $data;
  62. }
  63. $values['subject'] = $values['subject'] ?? $subject;
  64. $values['message'] = $values['message'] ?? $message;
  65. $values['statusCode'] = $values['statusCode'] ?? $statusCode;
  66. parent::__construct($values);
  67. }
  68. public function setAttributes($attributes)
  69. {
  70. $this->attributes = $attributes;
  71. }
  72. public function getAttributes()
  73. {
  74. return $this->attributes;
  75. }
  76. public function setSubject($subject)
  77. {
  78. $this->subject = $subject;
  79. }
  80. public function getSubject()
  81. {
  82. return $this->subject;
  83. }
  84. public function getMessage()
  85. {
  86. return $this->message;
  87. }
  88. public function setMessage($message)
  89. {
  90. $this->message = $message;
  91. }
  92. public function getStatusCode()
  93. {
  94. return $this->statusCode;
  95. }
  96. public function setStatusCode($statusCode)
  97. {
  98. $this->statusCode = $statusCode;
  99. }
  100. public function setValue($value)
  101. {
  102. $this->setAttributes($value);
  103. }
  104. public function getAliasName()
  105. {
  106. return 'is_granted';
  107. }
  108. public function allowArray()
  109. {
  110. return true;
  111. }
  112. }