summaryrefslogtreecommitdiffstats
path: root/Acl
diff options
context:
space:
mode:
Diffstat (limited to 'Acl')
-rw-r--r--Acl/Dbal/AclProvider.php12
-rw-r--r--Acl/Dbal/MutableAclProvider.php16
-rw-r--r--Acl/Domain/Acl.php1
-rw-r--r--Acl/Exception/Exception.php2
-rw-r--r--Acl/Permission/AbstractMaskBuilder.php85
-rw-r--r--Acl/Permission/BasicPermissionMap.php10
-rw-r--r--Acl/Permission/MaskBuilder.php76
-rw-r--r--Acl/Permission/MaskBuilderInterface.php75
-rw-r--r--Acl/Permission/MaskBuilderRetrievalInterface.php25
-rw-r--r--Acl/Tests/Dbal/AclProviderBenchmarkTest.php14
-rw-r--r--Acl/Tests/Dbal/MutableAclProviderTest.php4
-rw-r--r--Acl/Tests/Voter/AclVoterTest.php12
-rw-r--r--Acl/composer.json1
-rw-r--r--Acl/phpunit.xml.dist4
14 files changed, 227 insertions, 110 deletions
diff --git a/Acl/Dbal/AclProvider.php b/Acl/Dbal/AclProvider.php
index 705b4ff..fd6f5ba 100644
--- a/Acl/Dbal/AclProvider.php
+++ b/Acl/Dbal/AclProvider.php
@@ -173,7 +173,8 @@ class AclProvider implements AclProviderInterface
}
// Is it time to load the current batch?
- if ((self::MAX_BATCH_SIZE === count($currentBatch) || ($i + 1) === $c) && count($currentBatch) > 0) {
+ $currentBatchesCount = count($currentBatch);
+ if ($currentBatchesCount > 0 && (self::MAX_BATCH_SIZE === $currentBatchesCount || ($i + 1) === $c)) {
try {
$loadedBatch = $this->lookupObjectIdentities($currentBatch, $sids, $oidLookup);
} catch (AclNotFoundException $aclNotFoundException) {
@@ -559,10 +560,11 @@ QUERY;
// attach ACL to the result set; even though we do not enforce that every
// object identity has only one instance, we must make sure to maintain
// referential equality with the oids passed to findAcls()
- if (!isset($oidCache[$objectIdentifier.$classType])) {
- $oidCache[$objectIdentifier.$classType] = $acl->getObjectIdentity();
+ $oidCacheKey = $objectIdentifier.$classType;
+ if (!isset($oidCache[$oidCacheKey])) {
+ $oidCache[$oidCacheKey] = $acl->getObjectIdentity();
}
- $result->attach($oidCache[$objectIdentifier.$classType], $acl);
+ $result->attach($oidCache[$oidCacheKey], $acl);
// so, this hasn't been hydrated yet
} else {
// create object identity if we haven't done so yet
@@ -670,7 +672,7 @@ QUERY;
// let's see if we have already hydrated this
if (isset($acls[$parentId])) {
$aclParentAclProperty->setValue($acl, $acls[$parentId]);
- $processed += 1;
+ ++$processed;
continue;
}
diff --git a/Acl/Dbal/MutableAclProvider.php b/Acl/Dbal/MutableAclProvider.php
index 8e6b536..023a22f 100644
--- a/Acl/Dbal/MutableAclProvider.php
+++ b/Acl/Dbal/MutableAclProvider.php
@@ -256,7 +256,7 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
if (null === $propertyChanges['parentAcl'][1]) {
$sets[] = 'parent_object_identity_id = NULL';
} else {
- $sets[] = 'parent_object_identity_id = '.intval($propertyChanges['parentAcl'][1]->getId());
+ $sets[] = 'parent_object_identity_id = '.(int) $propertyChanges['parentAcl'][1]->getId();
}
$this->regenerateAncestorRelations($acl);
@@ -478,7 +478,7 @@ QUERY;
$query,
$this->options['entry_table_name'],
$classId,
- null === $objectIdentityId ? 'NULL' : intval($objectIdentityId),
+ null === $objectIdentityId ? 'NULL' : (int) $objectIdentityId,
null === $field ? 'NULL' : $this->connection->quote($field),
$aceOrder,
$securityIdentityId,
@@ -596,7 +596,7 @@ QUERY;
$classId,
null === $oid ?
$this->connection->getDatabasePlatform()->getIsNullExpression('object_identity_id')
- : 'object_identity_id = '.intval($oid),
+ : 'object_identity_id = '.(int) $oid,
null === $field ?
$this->connection->getDatabasePlatform()->getIsNullExpression('field_name')
: 'field_name = '.$this->connection->quote($field),
@@ -853,7 +853,6 @@ QUERY;
{
$sids = new \SplObjectStorage();
$classIds = new \SplObjectStorage();
- $currentIds = array();
foreach ($changes[1] as $field => $new) {
for ($i = 0, $c = count($new); $i<$c; $i++) {
$ace = $new[$i];
@@ -880,9 +879,7 @@ QUERY;
$aceIdProperty = new \ReflectionProperty('Symfony\Component\Security\Acl\Domain\Entry', 'id');
$aceIdProperty->setAccessible(true);
- $aceIdProperty->setValue($ace, intval($aceId));
- } else {
- $currentIds[$ace->getId()] = true;
+ $aceIdProperty->setValue($ace, (int) $aceId);
}
}
}
@@ -931,7 +928,6 @@ QUERY;
$sids = new \SplObjectStorage();
$classIds = new \SplObjectStorage();
- $currentIds = array();
for ($i = 0, $c = count($new); $i<$c; $i++) {
$ace = $new[$i];
@@ -957,9 +953,7 @@ QUERY;
$aceIdProperty = new \ReflectionProperty($ace, 'id');
$aceIdProperty->setAccessible(true);
- $aceIdProperty->setValue($ace, intval($aceId));
- } else {
- $currentIds[$ace->getId()] = true;
+ $aceIdProperty->setValue($ace, (int) $aceId);
}
}
}
diff --git a/Acl/Domain/Acl.php b/Acl/Domain/Acl.php
index 328f754..5649719 100644
--- a/Acl/Domain/Acl.php
+++ b/Acl/Domain/Acl.php
@@ -1,4 +1,5 @@
<?php
+
/*
* This file is part of the Symfony package.
*
diff --git a/Acl/Exception/Exception.php b/Acl/Exception/Exception.php
index a38c8ee..f1e1001 100644
--- a/Acl/Exception/Exception.php
+++ b/Acl/Exception/Exception.php
@@ -16,6 +16,6 @@ namespace Symfony\Component\Security\Acl\Exception;
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
-class Exception extends \Exception
+class Exception extends \RuntimeException
{
}
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();
+}
diff --git a/Acl/Tests/Dbal/AclProviderBenchmarkTest.php b/Acl/Tests/Dbal/AclProviderBenchmarkTest.php
index dab90d4..599b9c4 100644
--- a/Acl/Tests/Dbal/AclProviderBenchmarkTest.php
+++ b/Acl/Tests/Dbal/AclProviderBenchmarkTest.php
@@ -56,7 +56,7 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
// get some random test object identities from the database
$oids = array();
- $stmt = $this->con->executeQuery("SELECT object_identifier, class_type FROM acl_object_identities o INNER JOIN acl_classes c ON c.id = o.class_id ORDER BY RAND() LIMIT 25");
+ $stmt = $this->con->executeQuery('SELECT object_identifier, class_type FROM acl_object_identities o INNER JOIN acl_classes c ON c.id = o.class_id ORDER BY RAND() LIMIT 25');
foreach ($stmt->fetchAll() as $oid) {
$oids[] = new ObjectIdentity($oid['object_identifier'], $oid['class_type']);
}
@@ -66,7 +66,7 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
$start = microtime(true);
$provider->findAcls($oids);
$time = microtime(true) - $start;
- echo "Total Time: ".$time."s\n";
+ echo 'Total Time: '.$time."s\n";
}
/**
@@ -77,7 +77,7 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
{
$sm = $this->con->getSchemaManager();
$sm->dropAndCreateDatabase('testdb');
- $this->con->exec("USE testdb");
+ $this->con->exec('USE testdb');
// import the schema
$schema = new Schema($options = $this->getOptions());
@@ -122,7 +122,7 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
if ($id === 1000 || ($id < 1500 && rand(0, 1))) {
$this->insertClassStmt->execute(array($id, $this->getRandomString(rand(20, 100), 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\\_')));
- $id += 1;
+ ++$id;
return $id-1;
} else {
@@ -148,7 +148,7 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
}
$this->generateAces($classId, $id);
- $id += 1;
+ ++$id;
return $id-1;
}
@@ -163,7 +163,7 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
$this->getRandomString(rand(5, 30)),
rand(0, 1),
));
- $id += 1;
+ ++$id;
return $id-1;
} else {
@@ -215,7 +215,7 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
rand(0, 1),
));
- $id += 1;
+ ++$id;
}
}
diff --git a/Acl/Tests/Dbal/MutableAclProviderTest.php b/Acl/Tests/Dbal/MutableAclProviderTest.php
index 5ec23d3..edf64ba 100644
--- a/Acl/Tests/Dbal/MutableAclProviderTest.php
+++ b/Acl/Tests/Dbal/MutableAclProviderTest.php
@@ -478,7 +478,7 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
if (isset($aclData['parent_acl'])) {
if (isset($aclIds[$aclData['parent_acl']])) {
- $con->executeQuery("UPDATE acl_object_identities SET parent_object_identity_id = ".$aclIds[$aclData['parent_acl']]." WHERE id = ".$aclId);
+ $con->executeQuery('UPDATE acl_object_identities SET parent_object_identity_id = '.$aclIds[$aclData['parent_acl']].' WHERE id = '.$aclId);
$con->executeQuery($this->callMethod($provider, 'getInsertObjectIdentityRelationSql', array($aclId, $aclIds[$aclData['parent_acl']])));
} else {
$parentAcls[$aclId] = $aclData['parent_acl'];
@@ -491,7 +491,7 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
throw new \InvalidArgumentException(sprintf('"%s" does not exist.', $name));
}
- $con->executeQuery(sprintf("UPDATE acl_object_identities SET parent_object_identity_id = %d WHERE id = %d", $aclIds[$name], $aclId));
+ $con->executeQuery(sprintf('UPDATE acl_object_identities SET parent_object_identity_id = %d WHERE id = %d', $aclIds[$name], $aclId));
$con->executeQuery($this->callMethod($provider, 'getInsertObjectIdentityRelationSql', array($aclId, $aclIds[$name])));
}
diff --git a/Acl/Tests/Voter/AclVoterTest.php b/Acl/Tests/Voter/AclVoterTest.php
index c4c0b4e..2148135 100644
--- a/Acl/Tests/Voter/AclVoterTest.php
+++ b/Acl/Tests/Voter/AclVoterTest.php
@@ -27,7 +27,7 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
*/
public function testSupportsAttribute($attribute, $supported)
{
- list($voter, , $permissionMap, ,) = $this->getVoter(true, false);
+ list($voter, , $permissionMap) = $this->getVoter(true, false);
$permissionMap
->expects($this->once())
@@ -44,7 +44,7 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
*/
public function testSupportsAttributeNonString($attribute)
{
- list($voter, , , , ,) = $this->getVoter(true, false);
+ list($voter) = $this->getVoter(true, false);
$this->assertFalse($voter->supportsAttribute($attribute));
}
@@ -72,7 +72,7 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
*/
public function testSupportsClass($class)
{
- list($voter, , , ,) = $this->getVoter();
+ list($voter) = $this->getVoter();
$this->assertTrue($voter->supportsClass($class));
}
@@ -88,7 +88,7 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
public function testVote()
{
- list($voter, , $permissionMap, ,) = $this->getVoter();
+ list($voter, , $permissionMap) = $this->getVoter();
$permissionMap
->expects($this->atLeastOnce())
->method('getMasks')
@@ -103,7 +103,7 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
*/
public function testVoteWhenNoObjectIsPassed($allowIfObjectIdentityUnavailable)
{
- list($voter, , $permissionMap, ,) = $this->getVoter($allowIfObjectIdentityUnavailable);
+ list($voter, , $permissionMap) = $this->getVoter($allowIfObjectIdentityUnavailable);
$permissionMap
->expects($this->once())
->method('getMasks')
@@ -124,7 +124,7 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
*/
public function testVoteWhenOidStrategyReturnsNull($allowIfUnavailable)
{
- list($voter, , $permissionMap, $oidStrategy,) = $this->getVoter($allowIfUnavailable);
+ list($voter, , $permissionMap, $oidStrategy) = $this->getVoter($allowIfUnavailable);
$permissionMap
->expects($this->once())
->method('getMasks')
diff --git a/Acl/composer.json b/Acl/composer.json
index 4325d8c..2c0401f 100644
--- a/Acl/composer.json
+++ b/Acl/composer.json
@@ -20,6 +20,7 @@
"symfony/security-core": "~2.4|~3.0.0"
},
"require-dev": {
+ "symfony/phpunit-bridge": "~2.7|~3.0.0",
"doctrine/common": "~2.2",
"doctrine/dbal": "~2.2",
"psr/log": "~1.0"
diff --git a/Acl/phpunit.xml.dist b/Acl/phpunit.xml.dist
index 20d1b80..7552339 100644
--- a/Acl/phpunit.xml.dist
+++ b/Acl/phpunit.xml.dist
@@ -12,9 +12,7 @@
bootstrap="vendor/autoload.php"
>
<php>
- <!-- Disable E_USER_DEPRECATED until 3.0 -->
- <!-- php -r 'echo -1 & ~E_USER_DEPRECATED;' -->
- <ini name="error_reporting" value="-16385"/>
+ <ini name="error_reporting" value="-1" />
</php>
<testsuites>