Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ jobs:
matrix:
php:
- '7.4'
- '8.0'
- '8.1'

steps:
Expand Down Expand Up @@ -88,8 +87,9 @@ jobs:
matrix:
php:
- '7.4'
- '8.0'
- '8.1'
doctrine-persistence:
- 'doctrine/persistence:^2.0'
- 'doctrine/persistence:^3.0'
image:
- 'postgres:14'
- 'postgres:18'
Expand All @@ -103,6 +103,7 @@ jobs:
gh-client-secret: ${{ secrets.AUTOMATION_CLIENT_SECRET }}
satis-network-key: ${{ secrets.SATIS_NETWORK_KEY }}
satis-network-token: ${{ secrets.SATIS_NETWORK_TOKEN }}
composer-options: "--with ${{ matrix.doctrine-persistence }}"

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
Expand Down Expand Up @@ -141,8 +142,9 @@ jobs:
matrix:
php:
- '7.4'
- '8.0'
- '8.1'
doctrine-persistence:
- 'doctrine/persistence:^2.0'
- 'doctrine/persistence:^3.0'
image:
- 'mysql:8.0'
- 'mysql:8.4'
Expand All @@ -156,6 +158,7 @@ jobs:
gh-client-secret: ${{ secrets.AUTOMATION_CLIENT_SECRET }}
satis-network-key: ${{ secrets.SATIS_NETWORK_KEY }}
satis-network-token: ${{ secrets.SATIS_NETWORK_TOKEN }}
composer-options: "--with ${{ matrix.doctrine-persistence }}"

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
Expand Down Expand Up @@ -194,8 +197,7 @@ jobs:
matrix:
php:
- '7.4'
- '8.0'
- '8.1'
- '8.2'
steps:
- uses: actions/checkout@v5
with:
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"doctrine/dbal": "^2.13.0",
"doctrine/orm": "^2.7",
"doctrine/doctrine-bundle": "^2.0",
"doctrine/persistence": "^2.0 || ^3.0",
"liip/imagine-bundle": "^2.3",
"oneup/flysystem-bundle": "^4.4.2",
"league/flysystem-memory": "^2.0.6",
Expand All @@ -62,6 +63,7 @@
},
"require-dev": {
"behat/behat": "^3.6.1",
"composer-runtime-api": "^2.0",
"jenner/simple_fork": "^1.2",
"friends-of-behat/mink-extension": "^2.4",
"ibexa/ci-scripts": "^0.2@dev",
Expand Down
7 changes: 7 additions & 0 deletions phpstan-baseline-doctrine-persistence-v2.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
ignoreErrors:
-
message: '#^Call to function method_exists\(\) with Doctrine\\ORM\\EntityManagerInterface and ''merge'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: src/lib/Persistence/Doctrine/SiteAccessAwareEntityManager.php
13 changes: 13 additions & 0 deletions phpstan-baseline-doctrine-persistence-v3.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
parameters:
ignoreErrors:
-
message: '#^Call to function method_exists\(\) with Doctrine\\ORM\\EntityManagerInterface and ''isUninitializedObje…'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: src/lib/Persistence/Doctrine/SiteAccessAwareEntityManager.php

-
message: '#^Method Doctrine\\Persistence\\ObjectManager\:\:clear\(\) invoked with 1 parameter, 0 required\.$#'
identifier: arguments.count
count: 1
path: src/lib/Persistence/Doctrine/SiteAccessAwareEntityManager.php
10 changes: 10 additions & 0 deletions phpstan-baseline.neon.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
declare(strict_types=1);

use Composer\InstalledVersions;
use Composer\Semver\VersionParser;

$includes = [];
if (PHP_VERSION_ID < 80000) {
$includes[] = __DIR__ . '/phpstan-baseline-7.4.neon';
Expand All @@ -27,6 +30,13 @@
$includes[] = __DIR__ . '/phpstan-baseline-lte-8.2.neon';
}

$versionParser = new VersionParser();
if (InstalledVersions::satisfies($versionParser, 'doctrine/persistence', '2.*')) {
$includes[] = __DIR__ . '/phpstan-baseline-doctrine-persistence-v2.neon';
} elseif (InstalledVersions::satisfies($versionParser, 'doctrine/persistence', '3.*')) {
$includes[] = __DIR__ . '/phpstan-baseline-doctrine-persistence-v3.neon';
}

$config = [];
$config['includes'] = $includes;

Expand Down
51 changes: 28 additions & 23 deletions src/lib/Persistence/Doctrine/SiteAccessAwareEntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

/**
* @internal
*
* SiteAccessAwareEntityManager is a cross-compatible class supporting doctrine/persistence v2 and v3.
*/
final class SiteAccessAwareEntityManager implements EntityManagerInterface, ConfigScopeChangeSubscriber, ResetInterface
{
Expand Down Expand Up @@ -237,17 +239,17 @@ public function persist($object): void
$this->getWrapped()->persist($object);
}

/**
* @param object $object
*/
public function remove($object): void
{
$this->getWrapped()->remove($object);
}

public function clear(): void
/**
* @param string|null $objectName
*/
public function clear($objectName = null): void
{
$this->getWrapped()->clear();
$this->getWrapped()->clear($objectName);
}

/**
Expand All @@ -258,9 +260,6 @@ public function detach($object): void
$this->getWrapped()->detach($object);
}

/**
* @param object $object
*/
public function refresh($object, ?int $lockMode = null): void
{
$this->getWrapped()->refresh($object, $lockMode);
Expand All @@ -271,25 +270,11 @@ public function flush(): void
$this->getWrapped()->flush();
}

/**
* @template T of object
*
* @param class-string<T> $className
*
* @return EntityRepository<T>
*/
public function getRepository($className): EntityRepository
{
return $this->getWrapped()->getRepository($className);
}

/**
* @template T of object
*
* @param class-string<T> $className
*
* @return ClassMetadata<T>
*/
public function getClassMetadata($className): ClassMetadata
{
return $this->getWrapped()->getClassMetadata($className);
Expand All @@ -313,7 +298,12 @@ public function initializeObject($obj): void
*/
public function isUninitializedObject($value): bool
{
return $this->getWrapped()->isUninitializedObject($value);
$entityManager = $this->getWrapped();

// workaround for doctrine/persistence v2 and v3 cross-compatibility
return method_exists($entityManager, 'isUninitializedObject')
? $entityManager->isUninitializedObject($value)
: false;
}

/**
Expand All @@ -323,4 +313,19 @@ public function contains($object): bool
{
return $this->getWrapped()->contains($object);
}

/**
* @param object $object
*
* @return object|null
*/
public function merge($object)
{
$entityManager = $this->getWrapped();

// workaround for doctrine/persistence v2 and v3 cross-compatibility
return method_exists($entityManager, 'merge')
? $entityManager->merge($object)
: null;
}
}
Loading