Fix PHP 8.5 compatibility

This commit is contained in:
Irene Pérez
2026-02-23 14:35:17 +01:00
committed by Alexander M. Turek
parent 4baa5372d2
commit 38c563264e
7 changed files with 77 additions and 78 deletions

View File

@@ -18,12 +18,12 @@ jobs:
- php: '7.4'
deps: lowest
deprecations: max[self]=0
- php: '8.4'
- php: '8.5'
deps: highest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v5
- name: Setup PHP
uses: shivammathur/setup-php@v2
@@ -36,7 +36,7 @@ jobs:
run: composer config minimum-stability dev
- name: Composer install
uses: ramsey/composer-install@v1
uses: ramsey/composer-install@v3
with:
dependency-versions: '${{ matrix.deps }}'
@@ -54,7 +54,7 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v5
- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga:3.11.0
with:

View File

@@ -16,17 +16,17 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.2'
ini-values: "memory_limit=-1"
coverage: none
- name: Checkout target branch
uses: actions/checkout@v2
uses: actions/checkout@v5
with:
ref: ${{ github.base_ref }}
- name: Checkout PR
uses: actions/checkout@v2
uses: actions/checkout@v5
- name: Install dependencies
run: |

View File

@@ -104,7 +104,7 @@ class AclProvider implements AclProviderInterface
$aclFound = false;
// check if result already contains an ACL
if ($result->contains($oid)) {
if ($result->offsetExists($oid)) {
$aclFound = true;
}
@@ -118,7 +118,7 @@ class AclProvider implements AclProviderInterface
// filter by SID
throw new \RuntimeException('This is not supported by the default implementation.');
} else {
$result->attach($oid, $acl);
$result->offsetSet($oid, $acl);
$aclFound = true;
}
}
@@ -148,7 +148,7 @@ class AclProvider implements AclProviderInterface
$this->loadedAcls[$oid->getType()][$oid->getIdentifier()] = $acl;
$this->updateAceIdentityMap($acl);
$result->attach($oid, $acl);
$result->offsetSet($oid, $acl);
$aclFound = true;
} else {
$this->cache->evictFromCacheByIdentity($oid);
@@ -187,7 +187,7 @@ class AclProvider implements AclProviderInterface
}
if (isset($oidLookup[$loadedOid->getIdentifier().$loadedOid->getType()])) {
$result->attach($loadedOid, $loadedAcl);
$result->offsetSet($loadedOid, $loadedAcl);
}
}
@@ -197,7 +197,7 @@ class AclProvider implements AclProviderInterface
// check that we got ACLs for all the identities
foreach ($oids as $oid) {
if (!$result->contains($oid)) {
if (!$result->offsetExists($oid)) {
if (1 === \count($oids)) {
$objectName = method_exists($oid, '__toString') ? $oid : \get_class($oid);
throw new AclNotFoundException(sprintf('No ACL found for %s.', $objectName));
@@ -390,7 +390,9 @@ QUERY;
{
foreach (['classAces', 'classFieldAces', 'objectAces', 'objectFieldAces'] as $property) {
$reflection = new \ReflectionProperty($acl, $property);
$reflection->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$reflection->setAccessible(true);
}
$value = $reflection->getValue($acl);
if ('classAces' === $property || 'objectAces' === $property) {
@@ -402,7 +404,6 @@ QUERY;
}
$reflection->setValue($acl, $value);
$reflection->setAccessible(false);
}
}
@@ -490,15 +491,18 @@ QUERY;
// we need these to set protected properties on hydrated objects
$aclReflection = new \ReflectionClass(Acl::class);
$aclClassAcesProperty = $aclReflection->getProperty('classAces');
$aclClassAcesProperty->setAccessible(true);
$aclClassFieldAcesProperty = $aclReflection->getProperty('classFieldAces');
$aclClassFieldAcesProperty->setAccessible(true);
$aclObjectAcesProperty = $aclReflection->getProperty('objectAces');
$aclObjectAcesProperty->setAccessible(true);
$aclObjectFieldAcesProperty = $aclReflection->getProperty('objectFieldAces');
$aclObjectFieldAcesProperty->setAccessible(true);
$aclParentAclProperty = $aclReflection->getProperty('parentAcl');
$aclParentAclProperty->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$aclClassAcesProperty->setAccessible(true);
$aclClassFieldAcesProperty->setAccessible(true);
$aclObjectAcesProperty->setAccessible(true);
$aclObjectFieldAcesProperty->setAccessible(true);
$aclParentAclProperty->setAccessible(true);
}
// fetchAll() consumes more memory than consecutive calls to fetch(),
// but it is faster
@@ -541,7 +545,7 @@ QUERY;
if (!isset($oidCache[$oidCacheKey])) {
$oidCache[$oidCacheKey] = $acl->getObjectIdentity();
}
$result->attach($oidCache[$oidCacheKey], $acl);
$result->offsetSet($oidCache[$oidCacheKey], $acl);
// so, this hasn't been hydrated yet
} else {
// create object identity if we haven't done so yet
@@ -561,11 +565,11 @@ QUERY;
if (isset($acls[$parentObjectIdentityId])) {
$aclParentAclProperty->setValue($acl, $acls[$parentObjectIdentityId]);
} else {
$parentIdToFill->attach($acl, $parentObjectIdentityId);
$parentIdToFill->offsetSet($acl, $parentObjectIdentityId);
}
}
$result->attach($oidCache[$oidLookupKey], $acl);
$result->offsetSet($oidCache[$oidLookupKey], $acl);
}
// check if this row contains an ACE record
@@ -655,13 +659,6 @@ QUERY;
}
}
// reset reflection changes
$aclClassAcesProperty->setAccessible(false);
$aclClassFieldAcesProperty->setAccessible(false);
$aclObjectAcesProperty->setAccessible(false);
$aclObjectFieldAcesProperty->setAccessible(false);
$aclParentAclProperty->setAccessible(false);
// this should never be true if the database integrity hasn't been compromised
if ($processed < \count($parentIdToFill)) {
throw new \RuntimeException('Not all parent ids were populated. This implies an integrity problem.');

View File

@@ -132,16 +132,16 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
foreach ($result as $oid) {
$acl = $result->offsetGet($oid);
if (false === $this->propertyChanges->contains($acl) && $acl instanceof MutableAclInterface) {
if (false === $this->propertyChanges->offsetExists($acl) && $acl instanceof MutableAclInterface) {
$acl->addPropertyChangedListener($this);
$this->propertyChanges->attach($acl, []);
$this->propertyChanges->offsetSet($acl, []);
}
$parentAcl = $acl->getParentAcl();
while (null !== $parentAcl) {
if (false === $this->propertyChanges->contains($parentAcl) && $acl instanceof MutableAclInterface) {
if (false === $this->propertyChanges->offsetExists($parentAcl) && $acl instanceof MutableAclInterface) {
$parentAcl->addPropertyChangedListener($this);
$this->propertyChanges->attach($parentAcl, []);
$this->propertyChanges->offsetSet($parentAcl, []);
}
$parentAcl = $parentAcl->getParentAcl();
@@ -183,7 +183,7 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
$ace = null;
}
if (false === $this->propertyChanges->contains($sender)) {
if (false === $this->propertyChanges->offsetExists($sender)) {
throw new \InvalidArgumentException('$sender is not being tracked by this provider.');
}
@@ -204,7 +204,7 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
$propertyChanges['aces'] = new \SplObjectStorage();
}
$acePropertyChanges = $propertyChanges['aces']->contains($ace) ? $propertyChanges['aces']->offsetGet($ace) : [];
$acePropertyChanges = $propertyChanges['aces']->offsetExists($ace) ? $propertyChanges['aces']->offsetGet($ace) : [];
if (isset($acePropertyChanges[$propertyName])) {
$oldValue = $acePropertyChanges[$propertyName][0];
@@ -236,7 +236,7 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
*/
public function updateAcl(MutableAclInterface $acl)
{
if (!$this->propertyChanges->contains($acl)) {
if (!$this->propertyChanges->offsetExists($acl)) {
throw new \InvalidArgumentException('$acl is not tracked by this provider.');
}
@@ -311,9 +311,12 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
// ACL instances for object identities of the same type that are already in-memory
if (\count($sharedPropertyChanges) > 0) {
$classAcesProperty = new \ReflectionProperty(Acl::class, 'classAces');
$classAcesProperty->setAccessible(true);
$classFieldAcesProperty = new \ReflectionProperty(Acl::class, 'classFieldAces');
$classFieldAcesProperty->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$classAcesProperty->setAccessible(true);
$classFieldAcesProperty->setAccessible(true);
}
foreach ($this->loadedAcls[$acl->getObjectIdentity()->getType()] as $sameTypeAcl) {
if (isset($sharedPropertyChanges['classAces'])) {
@@ -843,14 +846,14 @@ QUERY;
$ace = $new[$i];
if (null === $ace->getId()) {
if ($sids->contains($ace->getSecurityIdentity())) {
if ($sids->offsetExists($ace->getSecurityIdentity())) {
$sid = $sids->offsetGet($ace->getSecurityIdentity());
} else {
$sid = $this->createOrRetrieveSecurityIdentityId($ace->getSecurityIdentity());
}
$oid = $ace->getAcl()->getObjectIdentity();
if ($classIds->contains($oid)) {
if ($classIds->offsetExists($oid)) {
$classId = $classIds->offsetGet($oid);
} else {
$classId = $this->createOrRetrieveClassId($oid->getType());
@@ -863,7 +866,9 @@ QUERY;
$this->loadedAces[$aceId] = $ace;
$aceIdProperty = new \ReflectionProperty(Entry::class, 'id');
$aceIdProperty->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$aceIdProperty->setAccessible(true);
}
$aceIdProperty->setValue($ace, (int) $aceId);
}
}
@@ -915,14 +920,14 @@ QUERY;
$ace = $new[$i];
if (null === $ace->getId()) {
if ($sids->contains($ace->getSecurityIdentity())) {
if ($sids->offsetExists($ace->getSecurityIdentity())) {
$sid = $sids->offsetGet($ace->getSecurityIdentity());
} else {
$sid = $this->createOrRetrieveSecurityIdentityId($ace->getSecurityIdentity());
}
$oid = $ace->getAcl()->getObjectIdentity();
if ($classIds->contains($oid)) {
if ($classIds->offsetExists($oid)) {
$classId = $classIds->offsetGet($oid);
} else {
$classId = $this->createOrRetrieveClassId($oid->getType());
@@ -935,7 +940,9 @@ QUERY;
$this->loadedAces[$aceId] = $ace;
$aceIdProperty = new \ReflectionProperty($ace, 'id');
$aceIdProperty->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$aceIdProperty->setAccessible(true);
}
$aceIdProperty->setValue($ace, (int) $aceId);
}
}

View File

@@ -42,12 +42,17 @@ trait AclCacheTrait
}
$reflectionProperty = new \ReflectionProperty($acl, 'permissionGrantingStrategy');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($acl, $this->permissionGrantingStrategy);
$reflectionProperty->setAccessible(false);
$aceAclProperty = new \ReflectionProperty(Entry::class, 'acl');
$aceAclProperty->setAccessible(true);
$aceClassFieldProperty = new \ReflectionProperty($acl, 'classFieldAces');
$aceObjectFieldProperty = new \ReflectionProperty($acl, 'objectFieldAces');
if (\PHP_VERSION_ID < 80100) {
$reflectionProperty->setAccessible(true);
$aceAclProperty->setAccessible(true);
$aceClassFieldProperty->setAccessible(true);
$aceObjectFieldProperty->setAccessible(true);
}
$reflectionProperty->setValue($acl, $this->permissionGrantingStrategy);
foreach ($acl->getObjectAces() as $ace) {
$aceAclProperty->setValue($ace, $acl);
@@ -56,25 +61,17 @@ trait AclCacheTrait
$aceAclProperty->setValue($ace, $acl);
}
$aceClassFieldProperty = new \ReflectionProperty($acl, 'classFieldAces');
$aceClassFieldProperty->setAccessible(true);
foreach ($aceClassFieldProperty->getValue($acl) as $aces) {
foreach ($aces as $ace) {
$aceAclProperty->setValue($ace, $acl);
}
}
$aceClassFieldProperty->setAccessible(false);
$aceObjectFieldProperty = new \ReflectionProperty($acl, 'objectFieldAces');
$aceObjectFieldProperty->setAccessible(true);
foreach ($aceObjectFieldProperty->getValue($acl) as $aces) {
foreach ($aces as $ace) {
$aceAclProperty->setValue($ace, $acl);
}
}
$aceObjectFieldProperty->setAccessible(false);
$aceAclProperty->setAccessible(false);
return $acl;
}

View File

@@ -57,8 +57,8 @@ class AclProviderTest extends TestCase
$this->assertInstanceOf(NotAllAclsFoundException::class, $e);
$partialResult = $e->getPartialResult();
$this->assertTrue($partialResult->contains($oids[0]));
$this->assertFalse($partialResult->contains($oids[1]));
$this->assertTrue($partialResult->offsetExists($oids[0]));
$this->assertFalse($partialResult->offsetExists($oids[1]));
}
}
@@ -229,7 +229,9 @@ class AclProviderTest extends TestCase
protected function getField($object, $field)
{
$reflection = new \ReflectionProperty($object, $field);
$reflection->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$reflection->setAccessible(true);
}
return $reflection->getValue($object);
}

View File

@@ -120,7 +120,7 @@ class MutableAclProviderTest extends TestCase
$propertyChanges = $this->getField($provider, 'propertyChanges');
$this->assertCount(1, $propertyChanges);
$this->assertTrue($propertyChanges->contains($acl));
$this->assertTrue($propertyChanges->offsetExists($acl));
$this->assertEquals([], $propertyChanges->offsetGet($acl));
$listeners = $this->getField($acl, 'listeners');
@@ -135,7 +135,7 @@ class MutableAclProviderTest extends TestCase
$propertyChanges = $this->getField($provider, 'propertyChanges');
$this->assertCount(1, $propertyChanges);
$this->assertTrue($propertyChanges->contains($acl));
$this->assertTrue($propertyChanges->offsetExists($acl));
$this->assertEquals([], $propertyChanges->offsetGet($acl));
$listeners = $this->getField($acl, 'listeners');
@@ -163,8 +163,8 @@ class MutableAclProviderTest extends TestCase
$acl = $provider->findAcl(new ObjectIdentity('1', 'foo'));
$this->assertCount(2, $propertyChanges);
$this->assertTrue($propertyChanges->contains($acl));
$this->assertTrue($propertyChanges->contains($acl->getParentAcl()));
$this->assertTrue($propertyChanges->offsetExists($acl));
$this->assertTrue($propertyChanges->offsetExists($acl->getParentAcl()));
}
public function testPropertyChangedDoesNotTrackUnmanagedAcls()
@@ -208,7 +208,7 @@ class MutableAclProviderTest extends TestCase
$changes = $propertyChanges->offsetGet($acl);
$this->assertTrue(isset($changes['aces']));
$this->assertInstanceOf('\SplObjectStorage', $changes['aces']);
$this->assertTrue($changes['aces']->contains($ace));
$this->assertTrue($changes['aces']->offsetExists($ace));
$aceChanges = $changes['aces']->offsetGet($ace);
$this->assertTrue(isset($aceChanges['mask']));
$this->assertEquals(1, $aceChanges['mask'][0]);
@@ -218,7 +218,7 @@ class MutableAclProviderTest extends TestCase
$changes = $propertyChanges->offsetGet($acl);
$this->assertTrue(isset($changes['aces']));
$this->assertInstanceOf('\SplObjectStorage', $changes['aces']);
$this->assertTrue($changes['aces']->contains($ace));
$this->assertTrue($changes['aces']->offsetExists($ace));
$aceChanges = $changes['aces']->offsetGet($ace);
$this->assertTrue(isset($aceChanges['mask']));
$this->assertTrue(isset($aceChanges['strategy']));
@@ -235,8 +235,8 @@ class MutableAclProviderTest extends TestCase
$provider->propertyChanged($ace, 'strategy', 'any', 'all');
$changes = $propertyChanges->offsetGet($acl);
$this->assertTrue(isset($changes['aces']));
$this->assertFalse($changes['aces']->contains($ace));
$this->assertTrue($changes['aces']->contains($ace2));
$this->assertFalse($changes['aces']->offsetExists($ace));
$this->assertTrue($changes['aces']->offsetExists($ace2));
$provider->propertyChanged($ace2, 'mask', 3, 4);
$provider->propertyChanged($ace2, 'mask', 4, 1);
@@ -513,7 +513,9 @@ class MutableAclProviderTest extends TestCase
protected function callMethod($object, $method, array $args)
{
$method = new \ReflectionMethod($object, $method);
$method->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$method->setAccessible(true);
}
return $method->invokeArgs($object, $args);
}
@@ -553,19 +555,13 @@ class MutableAclProviderTest extends TestCase
protected function getField($object, $field)
{
$reflection = new \ReflectionProperty($object, $field);
$reflection->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$reflection->setAccessible(true);
}
return $reflection->getValue($object);
}
public function setField($object, $field, $value)
{
$reflection = new \ReflectionProperty($object, $field);
$reflection->setAccessible(true);
$reflection->setValue($object, $value);
$reflection->setAccessible(false);
}
protected function getOptions()
{
return [