diff options
author | Fabien Potencier <fabien.potencier@gmail.com> | 2015-03-24 18:09:17 +0100 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2015-03-24 18:09:17 +0100 |
commit | 2e43dea46f12839ed7131d459390c5bcf9f4cb77 (patch) | |
tree | 515067365b0483bc2bb6b90f082e87604fea7bc4 /Acl/Permission | |
parent | 4ba88d7477d5158c294d160c5660e8219a3485c0 (diff) | |
parent | 48526dc543e7776f2f4ac3f22d65a27cc3b7d911 (diff) | |
download | symfony-security-2e43dea46f12839ed7131d459390c5bcf9f4cb77.zip symfony-security-2e43dea46f12839ed7131d459390c5bcf9f4cb77.tar.gz symfony-security-2e43dea46f12839ed7131d459390c5bcf9f4cb77.tar.bz2 |
Merge branch '2.7'
* 2.7: (55 commits)
CS: fix some license headers
CS: Ensure there is no code on the same line as the PHP open tag and it is followed by a blankline
Improve triggering of the deprecation error
[SecurityBundle] Fix typos in LogoutUrlHelper
[VarDumper] add caster for MongoCursor objects
make it possible to dump inlined services to XML
[VarDumper] Fixed notice when Exchange is mocked
[Translation] keep old array structure of resourcesFiles to avoid BC.
removed deprecated notices that make the tests fail
use visited lookup with reference to gain performance
[VarDumper] with-er interface for Cloner\Data
Replace GET parameters when changed
tweaked phpdocs
[Process] Fix outdated Process->start() docblock
prevent inlining service configurators
Improve entropy of generated salt
Complete the removal of API versions in the validator component
[Validator] deprecated API version
Removed 2.5 bc layer
[SecurityBundle] UserPasswordEncoderCommand: fix help arguments order.
...
Conflicts:
CHANGELOG-2.3.md
CHANGELOG-2.6.md
src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php
src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperTableLayoutTest.php
src/Symfony/Bundle/FrameworkBundle/composer.json
src/Symfony/Bundle/SecurityBundle/composer.json
src/Symfony/Component/Console/Helper/DialogHelper.php
src/Symfony/Component/Console/Tests/Helper/LegacyTableHelperTest.php
src/Symfony/Component/Form/ResolvedFormType.php
src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php
Diffstat (limited to 'Acl/Permission')
-rw-r--r-- | Acl/Permission/AbstractMaskBuilder.php | 85 | ||||
-rw-r--r-- | Acl/Permission/BasicPermissionMap.php | 10 | ||||
-rw-r--r-- | Acl/Permission/MaskBuilder.php | 76 | ||||
-rw-r--r-- | Acl/Permission/MaskBuilderInterface.php | 75 | ||||
-rw-r--r-- | Acl/Permission/MaskBuilderRetrievalInterface.php | 25 |
5 files changed, 196 insertions, 75 deletions
diff --git a/Acl/Permission/AbstractMaskBuilder.php b/Acl/Permission/AbstractMaskBuilder.php new file mode 100644 index 0000000..867d2e2 --- /dev/null +++ b/Acl/Permission/AbstractMaskBuilder.php @@ -0,0 +1,85 @@ +<?php + +/* + * This file is part of the Symfony package. + * + * (c) Fabien Potencier <fabien@symfony.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Security\Acl\Permission; + +/** + * This abstract class implements nearly all the MaskBuilderInterface methods + */ +abstract class AbstractMaskBuilder implements MaskBuilderInterface +{ + /** + * @var int + */ + protected $mask; + + /** + * Constructor. + * + * @param int $mask optional; defaults to 0 + */ + public function __construct($mask = 0) + { + $this->set($mask); + } + + /** + * {@inheritdoc} + */ + public function set($mask) + { + if (!is_int($mask)) { + throw new \InvalidArgumentException('$mask must be an integer.'); + } + + $this->mask = $mask; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function get() + { + return $this->mask; + } + + /** + * {@inheritdoc} + */ + public function add($mask) + { + $this->mask |= $this->resolveMask($mask); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function remove($mask) + { + $this->mask &= ~$this->resolveMask($mask); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function reset() + { + $this->mask = 0; + + return $this; + } +} diff --git a/Acl/Permission/BasicPermissionMap.php b/Acl/Permission/BasicPermissionMap.php index 4e26c02..fa5437d 100644 --- a/Acl/Permission/BasicPermissionMap.php +++ b/Acl/Permission/BasicPermissionMap.php @@ -17,7 +17,7 @@ namespace Symfony\Component\Security\Acl\Permission; * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ -class BasicPermissionMap implements PermissionMapInterface +class BasicPermissionMap implements PermissionMapInterface, MaskBuilderRetrievalInterface { const PERMISSION_VIEW = 'VIEW'; const PERMISSION_EDIT = 'EDIT'; @@ -105,4 +105,12 @@ class BasicPermissionMap implements PermissionMapInterface { return isset($this->map[$permission]); } + + /** + * {@inheritdoc} + */ + public function getMaskBuilder() + { + return new MaskBuilder(); + } } diff --git a/Acl/Permission/MaskBuilder.php b/Acl/Permission/MaskBuilder.php index 5364c9b..3079800 100644 --- a/Acl/Permission/MaskBuilder.php +++ b/Acl/Permission/MaskBuilder.php @@ -42,7 +42,7 @@ namespace Symfony\Component\Security\Acl\Permission; * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ -class MaskBuilder +class MaskBuilder extends AbstractMaskBuilder { const MASK_VIEW = 1; // 1 << 0 const MASK_CREATE = 2; // 1 << 1 @@ -67,50 +67,6 @@ class MaskBuilder const OFF = '.'; const ON = '*'; - private $mask; - - /** - * Constructor. - * - * @param int $mask optional; defaults to 0 - * - * @throws \InvalidArgumentException - */ - public function __construct($mask = 0) - { - if (!is_int($mask)) { - throw new \InvalidArgumentException('$mask must be an integer.'); - } - - $this->mask = $mask; - } - - /** - * Adds a mask to the permission. - * - * @param mixed $mask - * - * @return MaskBuilder - * - * @throws \InvalidArgumentException - */ - public function add($mask) - { - $this->mask |= $this->getMask($mask); - - return $this; - } - - /** - * Returns the mask of this permission. - * - * @return int - */ - public function get() - { - return $this->mask; - } - /** * Returns a human-readable representation of the permission. * @@ -136,34 +92,6 @@ class MaskBuilder } /** - * Removes a mask from the permission. - * - * @param mixed $mask - * - * @return MaskBuilder - * - * @throws \InvalidArgumentException - */ - public function remove($mask) - { - $this->mask &= ~$this->getMask($mask); - - return $this; - } - - /** - * Resets the PermissionBuilder. - * - * @return MaskBuilder - */ - public function reset() - { - $this->mask = 0; - - return $this; - } - - /** * Returns the code for the passed mask. * * @param int $mask @@ -204,7 +132,7 @@ class MaskBuilder * * @throws \InvalidArgumentException */ - private function getMask($code) + public function resolveMask($code) { if (is_string($code)) { if (!defined($name = sprintf('static::MASK_%s', strtoupper($code)))) { diff --git a/Acl/Permission/MaskBuilderInterface.php b/Acl/Permission/MaskBuilderInterface.php new file mode 100644 index 0000000..ba41830 --- /dev/null +++ b/Acl/Permission/MaskBuilderInterface.php @@ -0,0 +1,75 @@ +<?php + +/* + * This file is part of the Symfony package. + * + * (c) Fabien Potencier <fabien@symfony.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Security\Acl\Permission; + +/** + * This is the interface that must be implemented by mask builders. + */ +interface MaskBuilderInterface +{ + /** + * Set the mask of this permission + * + * @param int $mask + * + * @return MaskBuilderInterface + * @throws \InvalidArgumentException if $mask is not an integer + */ + public function set($mask); + + /** + * Returns the mask of this permission. + * + * @return int + */ + public function get(); + + /** + * Adds a mask to the permission. + * + * @param mixed $mask + * + * @return MaskBuilderInterface + * + * @throws \InvalidArgumentException + */ + public function add($mask); + + /** + * Removes a mask from the permission. + * + * @param mixed $mask + * + * @return MaskBuilderInterface + * + * @throws \InvalidArgumentException + */ + public function remove($mask); + + /** + * Resets the PermissionBuilder. + * + * @return MaskBuilderInterface + */ + public function reset(); + + /** + * Returns the mask for the passed code + * + * @param mixed $code + * + * @return int + * + * @throws \InvalidArgumentException + */ + public function resolveMask($code); +} diff --git a/Acl/Permission/MaskBuilderRetrievalInterface.php b/Acl/Permission/MaskBuilderRetrievalInterface.php new file mode 100644 index 0000000..7a99bca --- /dev/null +++ b/Acl/Permission/MaskBuilderRetrievalInterface.php @@ -0,0 +1,25 @@ +<?php + +/* + * This file is part of the Symfony package. + * + * (c) Fabien Potencier <fabien@symfony.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Security\Acl\Permission; + +/** + * Retrieves the MaskBuilder + */ +interface MaskBuilderRetrievalInterface +{ + /** + * Returns a new instance of the MaskBuilder used in the permissionMap + * + * @return MaskBuilderInterface + */ + public function getMaskBuilder(); +} |