Skip to content

Commit

Permalink
Merge branch '2.13.x' into 2.14.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Repository/ServiceEntityRepositoryProxy.php
  • Loading branch information
ostrolucky committed Jan 16, 2025
2 parents 24411a4 + 2363c43 commit 4af905c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 14 deletions.
13 changes: 12 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
parameters:
level: 1
level: 3
paths:
- src
- tests

excludePaths:
- src/Command/Proxy/ConvertMappingDoctrineCommand.php
- src/Command/Proxy/EnsureProductionSettingsDoctrineCommand.php
ignoreErrors:
# Available in ORM < 3 only
- '#Doctrine\\ORM\\Tools\\EntityGenerator.#'
- '#Doctrine\\ORM\\Tools\\DisconnectedClassMetadataFactory.#'
- '#Doctrine\\ORM\\Tools\\Export\\ClassMetadataExporter.#'
# phpstan has no array shape intersection support https://github.com/phpstan/phpstan/issues/12414
- message: '#unresolvable type.#'
path: src/DataCollector/DoctrineDataCollector.php
# Probably needs Symfony plugin
- message: '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\Node#'
path: src/DependencyInjection/Configuration.php
11 changes: 6 additions & 5 deletions src/Command/DoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace Doctrine\Bundle\DoctrineBundle\Command;

use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\EntityGenerator;
use Doctrine\Persistence\ManagerRegistry;
use InvalidArgumentException;
use Symfony\Component\Console\Command\Command;

use function assert;

/**
* Base class for Doctrine console commands to extend from.
*
Expand All @@ -26,12 +28,9 @@ public function __construct(
* get a doctrine entity generator
*
* @return EntityGenerator
*
* @psalm-suppress UndefinedDocblockClass ORM < 3 specific
*/
protected function getEntityGenerator()
{
/** @phpstan-ignore class.notFound */
$entityGenerator = new EntityGenerator();
$entityGenerator->setGenerateAnnotations(false);
$entityGenerator->setGenerateStubMethods(true);
Expand All @@ -49,7 +48,7 @@ protected function getEntityGenerator()
* @param string $name
* @param int|null $shardId
*
* @return EntityManager
* @return EntityManagerInterface
*/
protected function getEntityManager($name, $shardId = null)
{
Expand All @@ -59,6 +58,8 @@ protected function getEntityManager($name, $shardId = null)
throw new InvalidArgumentException('Shards are not supported anymore using doctrine/dbal >= 3');
}

assert($manager instanceof EntityManagerInterface);

return $manager;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Command/ImportMappingDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Doctrine\Bundle\DoctrineBundle\Command;

use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\Driver\DatabaseDriver;
use Doctrine\ORM\Tools\Console\MetadataFilter;
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
Expand All @@ -13,6 +14,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function assert;
use function chmod;
use function dirname;
use function file_put_contents;
Expand Down Expand Up @@ -88,6 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$namespaceOrBundle = $input->getArgument('name');
if (isset($this->bundles[$namespaceOrBundle])) {
/** @phpstan-ignore method.notFound */
$bundle = $this->getApplication()->getKernel()->getBundle($namespaceOrBundle);
$namespace = $bundle->getNamespace() . '\Entity';

Expand Down Expand Up @@ -118,20 +121,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$em = $this->getEntityManager($input->getOption('em'));

/* @phpstan-ignore method.notFound (Available in DBAL < 4) */
$databaseDriver = new DatabaseDriver($em->getConnection()->getSchemaManager());
$em->getConfiguration()->setMetadataDriverImpl($databaseDriver);

$emName = $input->getOption('em');
$emName = $emName ? $emName : 'default';

/* @phpstan-ignore class.notFound */
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadata = $cmf->getAllMetadata();
$metadata = MetadataFilter::filter($metadata, $input->getOption('filter'));
if ($metadata) {
$output->writeln(sprintf('Importing mapping information from "<info>%s</info>" entity manager', $emName));
foreach ($metadata as $class) {
assert($class instanceof ClassMetadata);
$className = $class->name;
$class->name = $namespace . '\\' . $className;
if ($type === 'annotation') {
Expand Down
2 changes: 1 addition & 1 deletion src/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function createConnection(array $params, Configuration|null $config = nul
$connection = DriverManager::getConnection(...array_merge([$params, $config], $eventManager ? [$eventManager] : []));
$params = $this->addDatabaseSuffix(array_merge($connection->getParams(), $overriddenOptions));
$driver = $connection->getDriver();
/** @psalm-suppress InvalidScalarArgument Bogus error, StaticServerVersionProvider implements Doctrine\DBAL\ServerVersionProvider */
/** @phpstan-ignore arguments.count (DBAL < 4.x doesn't accept an argument) */
$platform = $driver->getDatabasePlatform(
...(class_exists(StaticServerVersionProvider::class)
? [new StaticServerVersionProvider($params['serverVersion'] ?? $params['primary']['serverVersion'] ?? '')]
Expand Down
6 changes: 6 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition
->prototype('array');
$this->configureDbalDriverNode($replicaNode);

assert($node instanceof ArrayNodeDefinition);

return $node;
}

Expand Down Expand Up @@ -802,6 +804,8 @@ private function getOrmEntityManagersNode(): ArrayNodeDefinition
->end()
->end();

assert($node instanceof ArrayNodeDefinition);

return $node;
}

Expand All @@ -828,6 +832,8 @@ private function getOrmCacheDriverNode(string $name): ArrayNodeDefinition
$node->addDefaultsIfNotSet();
}

assert($node instanceof ArrayNodeDefinition);

return $node;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Doctrine\ORM\ORMException;
use Doctrine\Persistence\Proxy;
use ProxyManager\Proxy\LazyLoadingInterface;
use Psr\Container\ContainerInterface;
use Symfony\Bridge\Doctrine\ManagerRegistry;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\VarExporter\LazyObjectInterface;
use Symfony\Contracts\Service\ResetInterface;

Expand All @@ -23,7 +23,7 @@ class Registry extends ManagerRegistry implements ResetInterface
* @param string[] $connections
* @param string[] $entityManagers
*/
public function __construct(ContainerInterface $container, array $connections, array $entityManagers, string $defaultConnection, string $defaultEntityManager)
public function __construct(Container $container, array $connections, array $entityManagers, string $defaultConnection, string $defaultEntityManager)
{
$this->container = $container;

Expand Down Expand Up @@ -51,7 +51,7 @@ public function getAliasNamespace($alias)
}

try {
/** @psalm-suppress UndefinedMethod ORM < 3 specific */
/** @phpstan-ignore method.notFound (ORM < 3 specific) */
return $objectManager->getConfiguration()->getEntityNamespace($alias);
/* @phpstan-ignore class.notFound */
} catch (ORMException) {
Expand Down
8 changes: 7 additions & 1 deletion src/Repository/ServiceEntityRepositoryProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
class ServiceEntityRepositoryProxy extends EntityRepository implements ServiceEntityRepositoryInterface
{
/** @var EntityRepository<T> */
private EntityRepository|null $repository = null;

/** @param class-string<T> $entityClass The class name of the entity this repository manages */
Expand Down Expand Up @@ -111,11 +112,13 @@ protected function getClassMetadata(): ClassMetadata
return ($this->repository ??= $this->resolveRepository())->getClassMetadata();
}

/** @phpstan-return AbstractLazyCollection<int, T>&Selectable<int, T> */
public function matching(Criteria $criteria): AbstractLazyCollection&Selectable
{
return ($this->repository ??= $this->resolveRepository())->matching($criteria);
}

/** @return EntityRepository<T> */
private function resolveRepository(): EntityRepository
{
$manager = $this->registry->getManagerForClass($this->entityClass);
Expand All @@ -127,6 +130,9 @@ private function resolveRepository(): EntityRepository
));
}

return new EntityRepository($manager, $manager->getClassMetadata($this->entityClass));
/** @var ClassMetadata<T> $classMetadata */
$classMetadata = $manager->getClassMetadata($this->entityClass);

return new EntityRepository($manager, $classMetadata);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Fixtures\Bundles\RepositoryServiceBundle\Repository;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;

/**
Expand All @@ -11,7 +11,7 @@
*/
class TestCustomClassRepoRepository extends EntityRepository
{
public function getEntityManager(): EntityManager
public function getEntityManager(): EntityManagerInterface
{
return parent::getEntityManager();
}
Expand Down

0 comments on commit 4af905c

Please sign in to comment.