AbstractMaskBuilder.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 Symfony\Component\Security\Acl\Permission;
  11. /**
  12. * This abstract class implements nearly all the MaskBuilderInterface methods.
  13. */
  14. abstract class AbstractMaskBuilder implements MaskBuilderInterface
  15. {
  16. /**
  17. * @var int
  18. */
  19. protected $mask;
  20. /**
  21. * Constructor.
  22. *
  23. * @param int $mask optional; defaults to 0
  24. */
  25. public function __construct($mask = 0)
  26. {
  27. $this->set($mask);
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function set($mask)
  33. {
  34. if (!is_int($mask)) {
  35. throw new \InvalidArgumentException('$mask must be an integer.');
  36. }
  37. $this->mask = $mask;
  38. return $this;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function get()
  44. {
  45. return $this->mask;
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function add($mask)
  51. {
  52. $this->mask |= $this->resolveMask($mask);
  53. return $this;
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function remove($mask)
  59. {
  60. $this->mask &= ~$this->resolveMask($mask);
  61. return $this;
  62. }
  63. /**
  64. * {@inheritdoc}
  65. */
  66. public function reset()
  67. {
  68. $this->mask = 0;
  69. return $this;
  70. }
  71. }