Skip to content
Merged
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
10 changes: 10 additions & 0 deletions src/Query/Exec/SingleSelectExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Result;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\Query\AST\SelectStatement;
use Doctrine\ORM\Query\SqlWalker;

/**
* Executor that executes the SQL statement for simple DQL SELECT statements.
*
* @deprecated This class is no longer needed by the ORM and will be removed in 4.0.
*
* @link www.doctrine-project.org
*/
class SingleSelectExecutor extends AbstractSqlExecutor
{
public function __construct(SelectStatement $AST, SqlWalker $sqlWalker)
{
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/11188/',
'The %s is no longer needed by the ORM and will be removed in 4.0',
self::class,
);

$this->sqlStatements = $sqlWalker->walkSelectStatement($AST);
}

Expand Down
21 changes: 19 additions & 2 deletions src/Query/ParserResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\ORM\Query;

use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Exec\AbstractSqlExecutor;
use Doctrine\ORM\Query\Exec\SqlFinalizer;
Expand Down Expand Up @@ -71,20 +72,36 @@ public function setResultSetMapping(ResultSetMapping $rsm): void
/**
* Sets the SQL executor that should be used for this ParserResult.
*
* @deprecated
* @deprecated The SqlExecutor will be removed from ParserResult in 4.0. Provide a SqlFinalizer instead that can create the executor.
*/
public function setSqlExecutor(AbstractSqlExecutor $executor): void
{
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/11188',
'The SqlExecutor will be removed from %s in 4.0. Provide a %s instead that can create the executor.',
self::class,
SqlFinalizer::class,
);

$this->sqlExecutor = $executor;
}

/**
* Gets the SQL executor used by this ParserResult.
*
* @deprecated
* @deprecated The SqlExecutor will be removed from ParserResult in 4.0. Provide a SqlFinalizer instead that can create the executor.
*/
public function getSqlExecutor(): AbstractSqlExecutor
{
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/11188',
'The SqlExecutor will be removed from %s in 4.0. Provide a %s instead that can create the executor.',
self::class,
SqlFinalizer::class,
);

if ($this->sqlExecutor === null) {
throw new LogicException(sprintf(
'Executor not set yet. Call %s::setSqlExecutor() first.',
Expand Down
9 changes: 9 additions & 0 deletions src/Query/SqlWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\LockMode;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\QuoteStrategy;
Expand Down Expand Up @@ -230,6 +231,14 @@ public function setQueryComponent(string $dqlAlias, array $queryComponent): void
*/
public function getExecutor(AST\SelectStatement|AST\UpdateStatement|AST\DeleteStatement $statement): Exec\AbstractSqlExecutor
{
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/11188/',
'Output walkers should implement %s. That way, the %s method is no longer needed and will be removed in 4.0',
OutputWalker::class,
__METHOD__,
);

return match (true) {
$statement instanceof AST\UpdateStatement => $this->createUpdateStatementExecutor($statement),
$statement instanceof AST\DeleteStatement => $this->createDeleteStatementExecutor($statement),
Expand Down
5 changes: 5 additions & 0 deletions tests/Tests/ORM/Functional/ParserResultSerializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\Tests\ORM\Functional;

use Closure;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Exec\FinalizedSelectExecutor;
use Doctrine\ORM\Query\Exec\PreparedExecutorFinalizer;
Expand All @@ -26,6 +27,8 @@

class ParserResultSerializationTest extends OrmFunctionalTestCase
{
use VerifyDeprecations;

protected function setUp(): void
{
$this->useModelSet('company');
Expand Down Expand Up @@ -98,6 +101,8 @@ public function testUnserializeSingleSelectResult(string $serialized): void
$this->assertInstanceOf(ParserResult::class, $unserialized);
$this->assertInstanceOf(ResultSetMapping::class, $unserialized->getResultSetMapping());
$this->assertEquals(['name' => [0]], $unserialized->getParameterMappings());

$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/11188');
$this->assertInstanceOf(SingleSelectExecutor::class, $unserialized->getSqlExecutor());
$this->assertIsString($unserialized->getSqlExecutor()->getSqlStatements());
}
Expand Down
6 changes: 5 additions & 1 deletion tests/Tests/ORM/Functional/QueryCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Exec\AbstractSqlExecutor;
use Doctrine\ORM\Query\Exec\SqlFinalizer;
use Doctrine\ORM\Query\ParserResult;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Depends;
Expand Down Expand Up @@ -130,8 +131,11 @@ public function execute(Connection $conn, array $params, array $types): int
}
};

$sqlFinalizerMock = $this->createMock(SqlFinalizer::class);
$sqlFinalizerMock->method('createExecutor')->with($query)->willReturn($sqlExecutorStub);

$parserResultMock = new ParserResult();
$parserResultMock->setSqlExecutor($sqlExecutorStub);
$parserResultMock->setSqlFinalizer($sqlFinalizerMock);

$cache = $this->createMock(CacheItemPoolInterface::class);

Expand Down
5 changes: 5 additions & 0 deletions tests/Tests/ORM/Query/ParserResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\Tests\ORM\Query;

use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\Query\Exec\AbstractSqlExecutor;
use Doctrine\ORM\Query\ParserResult;
use Doctrine\ORM\Query\ResultSetMapping;
Expand All @@ -12,6 +13,8 @@

class ParserResultTest extends TestCase
{
use VerifyDeprecations;

/** @var ParserResult */
public $parserResult;

Expand All @@ -37,6 +40,8 @@ public function testItThrowsWhenAttemptingToAccessTheExecutorBeforeItIsSet(): vo

public function testSetGetSqlExecutor(): void
{
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/11188');

$executor = $this->createMock(AbstractSqlExecutor::class);
$this->parserResult->setSqlExecutor($executor);
self::assertSame($executor, $this->parserResult->getSqlExecutor());
Expand Down
Loading