BasicPermissionMap.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 is basic permission map complements the masks which have been defined
  13. * on the standard implementation of the MaskBuilder.
  14. *
  15. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  16. */
  17. class BasicPermissionMap implements PermissionMapInterface, MaskBuilderRetrievalInterface
  18. {
  19. const PERMISSION_VIEW = 'VIEW';
  20. const PERMISSION_EDIT = 'EDIT';
  21. const PERMISSION_CREATE = 'CREATE';
  22. const PERMISSION_DELETE = 'DELETE';
  23. const PERMISSION_UNDELETE = 'UNDELETE';
  24. const PERMISSION_OPERATOR = 'OPERATOR';
  25. const PERMISSION_MASTER = 'MASTER';
  26. const PERMISSION_OWNER = 'OWNER';
  27. protected $map;
  28. public function __construct()
  29. {
  30. $this->map = array(
  31. self::PERMISSION_VIEW => array(
  32. MaskBuilder::MASK_VIEW,
  33. MaskBuilder::MASK_EDIT,
  34. MaskBuilder::MASK_OPERATOR,
  35. MaskBuilder::MASK_MASTER,
  36. MaskBuilder::MASK_OWNER,
  37. ),
  38. self::PERMISSION_EDIT => array(
  39. MaskBuilder::MASK_EDIT,
  40. MaskBuilder::MASK_OPERATOR,
  41. MaskBuilder::MASK_MASTER,
  42. MaskBuilder::MASK_OWNER,
  43. ),
  44. self::PERMISSION_CREATE => array(
  45. MaskBuilder::MASK_CREATE,
  46. MaskBuilder::MASK_OPERATOR,
  47. MaskBuilder::MASK_MASTER,
  48. MaskBuilder::MASK_OWNER,
  49. ),
  50. self::PERMISSION_DELETE => array(
  51. MaskBuilder::MASK_DELETE,
  52. MaskBuilder::MASK_OPERATOR,
  53. MaskBuilder::MASK_MASTER,
  54. MaskBuilder::MASK_OWNER,
  55. ),
  56. self::PERMISSION_UNDELETE => array(
  57. MaskBuilder::MASK_UNDELETE,
  58. MaskBuilder::MASK_OPERATOR,
  59. MaskBuilder::MASK_MASTER,
  60. MaskBuilder::MASK_OWNER,
  61. ),
  62. self::PERMISSION_OPERATOR => array(
  63. MaskBuilder::MASK_OPERATOR,
  64. MaskBuilder::MASK_MASTER,
  65. MaskBuilder::MASK_OWNER,
  66. ),
  67. self::PERMISSION_MASTER => array(
  68. MaskBuilder::MASK_MASTER,
  69. MaskBuilder::MASK_OWNER,
  70. ),
  71. self::PERMISSION_OWNER => array(
  72. MaskBuilder::MASK_OWNER,
  73. ),
  74. );
  75. }
  76. /**
  77. * {@inheritdoc}
  78. */
  79. public function getMasks($permission, $object)
  80. {
  81. if (!isset($this->map[$permission])) {
  82. return;
  83. }
  84. return $this->map[$permission];
  85. }
  86. /**
  87. * {@inheritdoc}
  88. */
  89. public function contains($permission)
  90. {
  91. return isset($this->map[$permission]);
  92. }
  93. /**
  94. * {@inheritdoc}
  95. */
  96. public function getMaskBuilder()
  97. {
  98. return new MaskBuilder();
  99. }
  100. }