Skip to content

Commit

Permalink
Merge pull request #9885 from greg0ire/fix-build
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire authored Jul 13, 2022
2 parents 9e0c7de + 1ac9d52 commit 990a1fe
Show file tree
Hide file tree
Showing 134 changed files with 695 additions and 860 deletions.
11 changes: 11 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,17 @@ Calling `AbstractQuery::setFetchMode()` with anything else than
`Doctrine\ORM\Mapping::FETCH_LAZY` being used. Relying on that behavior is
deprecated and will result in an exception in 3.0.

## Deprecated `getEntityManager()` in `Doctrine\ORM\Event\OnClearEventArgs` and `Doctrine\ORM\Event\*FlushEventArgs`

This method has been deprecated in:

* `Doctrine\ORM\Event\OnClearEventArgs`
* `Doctrine\ORM\Event\OnFlushEventArgs`
* `Doctrine\ORM\Event\PostFlushEventArgs`
* `Doctrine\ORM\Event\PreFlushEventArgs`

It will be removed in 3.0. Use `getObjectManager()` instead.

## Prepare split of output walkers and tree walkers

In 3.0, `SqlWalker` and its child classes won't implement the `TreeWalker`
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"doctrine/annotations": "^1.13",
"doctrine/coding-standard": "^9.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "1.7.15",
"phpstan/phpstan": "1.8.0",
"phpunit/phpunit": "^9.5",
"psr/log": "^1 || ^2 || ^3",
"squizlabs/php_codesniffer": "3.7.1",
Expand Down
3 changes: 3 additions & 0 deletions docs/en/reference/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,9 @@ A simple example for this event looks like:
if ($eventArgs->getEntity() instanceof User) {
if ($eventArgs->hasChangedField('name') && $eventArgs->getNewValue('name') == 'Alice') {
$eventArgs->setNewValue('name', 'Bob');
// The following will only work if `status` is already present in the computed changeset.
// Otherwise it will throw an InvalidArgumentException:
$eventArgs->setNewValue('status', 'active');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function setCacheable(bool $cacheable): static
}

/**
* @return bool TRUE if the query results are enable for second level cache, FALSE otherwise.
* @return bool TRUE if the query results are enabled for second level cache, FALSE otherwise.
*/
public function isCacheable(): bool
{
Expand Down
23 changes: 15 additions & 8 deletions lib/Doctrine/ORM/Event/OnClearEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@

namespace Doctrine\ORM\Event;

use Doctrine\Common\EventArgs;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\OnClearEventArgs as BaseOnClearEventArgs;

/**
* Provides event arguments for the onClear event.
*
* @link www.doctrine-project.org
*
* @extends BaseOnClearEventArgs<EntityManagerInterface>
*/
class OnClearEventArgs extends EventArgs
class OnClearEventArgs extends BaseOnClearEventArgs
{
public function __construct(
private EntityManagerInterface $em
) {
}

/**
* Retrieves associated EntityManager.
*
* @deprecated 2.13. Use {@see getObjectManager} instead.
*/
public function getEntityManager(): EntityManagerInterface
{
return $this->em;
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9875',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.',
__METHOD__
);

return $this->getObjectManager();
}
}
26 changes: 15 additions & 11 deletions lib/Doctrine/ORM/Event/OnFlushEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@

namespace Doctrine\ORM\Event;

use Doctrine\Common\EventArgs;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\ManagerEventArgs;

/**
* Provides event arguments for the preFlush event.
*
* @link www.doctrine-project.org
*
* @extends ManagerEventArgs<EntityManagerInterface>
*/
class OnFlushEventArgs extends EventArgs
class OnFlushEventArgs extends ManagerEventArgs
{
/** @var EntityManagerInterface */
private $em;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}

/**
* Retrieve associated EntityManager.
*
* @deprecated 2.13. Use {@see getObjectManager} instead.
*
* @return EntityManagerInterface
*/
public function getEntityManager()
{
return $this->em;
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9875',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.',
__METHOD__
);

return $this->getObjectManager();
}
}
26 changes: 15 additions & 11 deletions lib/Doctrine/ORM/Event/PostFlushEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@

namespace Doctrine\ORM\Event;

use Doctrine\Common\EventArgs;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\ManagerEventArgs;

/**
* Provides event arguments for the postFlush event.
*
* @link www.doctrine-project.org
*
* @extends ManagerEventArgs<EntityManagerInterface>
*/
class PostFlushEventArgs extends EventArgs
class PostFlushEventArgs extends ManagerEventArgs
{
/** @var EntityManagerInterface */
private $em;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}

/**
* Retrieves associated EntityManager.
*
* @deprecated 2.13. Use {@see getObjectManager} instead.
*
* @return EntityManagerInterface
*/
public function getEntityManager()
{
return $this->em;
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9875',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.',
__METHOD__
);

return $this->getObjectManager();
}
}
26 changes: 15 additions & 11 deletions lib/Doctrine/ORM/Event/PreFlushEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,33 @@

namespace Doctrine\ORM\Event;

use Doctrine\Common\EventArgs;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\ManagerEventArgs;

/**
* Provides event arguments for the preFlush event.
*
* @link www.doctrine-project.com
*
* @extends ManagerEventArgs<EntityManagerInterface>
*/
class PreFlushEventArgs extends EventArgs
class PreFlushEventArgs extends ManagerEventArgs
{
/** @var EntityManagerInterface */
private $em;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}

/**
* @deprecated 2.13. Use {@see getObjectManager} instead.
*
* @return EntityManagerInterface
*/
public function getEntityManager()
{
return $this->em;
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9875',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.',
__METHOD__
);

return $this->getObjectManager();
}
}
31 changes: 21 additions & 10 deletions lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class ObjectHydrator extends AbstractHydrator
/** @var mixed[] */
private array $initializedCollections = [];

/** @var array<string, PersistentCollection> */
private $uninitializedCollections = [];

/** @var mixed[] */
private array $existingCollections = [];

Expand Down Expand Up @@ -105,10 +108,11 @@ protected function cleanup(): void

parent::cleanup();

$this->identifierMap =
$this->initializedCollections =
$this->existingCollections =
$this->resultPointers = [];
$this->identifierMap =
$this->initializedCollections =
$this->uninitializedCollections =
$this->existingCollections =
$this->resultPointers = [];

if ($eagerLoad) {
$this->_uow->triggerEagerLoads();
Expand All @@ -119,10 +123,11 @@ protected function cleanup(): void

protected function cleanupAfterRowIteration(): void
{
$this->identifierMap =
$this->initializedCollections =
$this->existingCollections =
$this->resultPointers = [];
$this->identifierMap =
$this->initializedCollections =
$this->uninitializedCollections =
$this->existingCollections =
$this->resultPointers = [];
}

/**
Expand All @@ -141,6 +146,12 @@ protected function hydrateAllData(): array
$coll->takeSnapshot();
}

foreach ($this->uninitializedCollections as $coll) {
if (! $coll->isInitialized()) {
$coll->setInitialized(true);
}
}

return $result;
}

Expand Down Expand Up @@ -397,8 +408,8 @@ protected function hydrateRowData(array $row, array &$result): void
}
} elseif (! $reflFieldValue) {
$this->initRelatedCollection($parentObject, $parentClass, $relationField, $parentAlias);
} elseif ($reflFieldValue instanceof PersistentCollection && $reflFieldValue->isInitialized() === false) {
$reflFieldValue->setInitialized(true);
} elseif ($reflFieldValue instanceof PersistentCollection && $reflFieldValue->isInitialized() === false && ! isset($this->uninitializedCollections[$oid . $relationField])) {
$this->uninitializedCollections[$oid . $relationField] = $reflFieldValue;
}
} else {
// PATH B: Single-valued association
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct($file = 'php://output', $context = '')
*/
public function onFlush(OnFlushEventArgs $args)
{
$this->dumpIdentityMap($args->getEntityManager());
$this->dumpIdentityMap($args->getObjectManager());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,8 @@ private function gatherColumnOptions(array $mapping): array
return [];
}

$options = array_intersect_key($mappingOptions, array_flip(self::KNOWN_COLUMN_OPTIONS));
$options['customSchemaOptions'] = array_diff_key($mappingOptions, $options);
$options = array_intersect_key($mappingOptions, array_flip(self::KNOWN_COLUMN_OPTIONS));
$options['platformOptions'] = array_diff_key($mappingOptions, $options);

return $options;
}
Expand Down
4 changes: 4 additions & 0 deletions phpstan-dbal4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ parameters:
-
message: '~^Parameter #1 \$command of method Symfony\\Component\\Console\\Application::add\(\) expects Symfony\\Component\\Console\\Command\\Command, Doctrine\\DBAL\\Tools\\Console\\Command\\ReservedWordsCommand given\.$~'
path: lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php

-
message: '~Strict comparison using \=\=\= between callable\(\)\: mixed and null will always evaluate to false\.~'
path: lib/Doctrine/ORM/Tools/SchemaTool.php
11 changes: 11 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
</ignoreFiles>
</projectFiles>
<issueHandlers>
<DeprecatedConstant>
<errorLevel type="suppress">
<file name="lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php" />
</errorLevel>
</DeprecatedConstant>
<DeprecatedClass>
<errorLevel type="suppress">
<!-- Remove on 3.0.x -->
Expand Down Expand Up @@ -111,6 +116,12 @@
<referencedFunction name="Doctrine\DBAL\Connection::lastInsertId"/>
</errorLevel>
</TooManyArguments>
<TypeDoesNotContainNull>
<errorLevel type="suppress">
<!-- DBAL 3 compatibility -->
<file name="lib/Doctrine/ORM/Tools/SchemaTool.php"/>
</errorLevel>
</TypeDoesNotContainNull>
<TypeDoesNotContainType>
<errorLevel type="suppress">
<file name="lib/Doctrine/ORM/Internal/SQLResultCasing.php"/>
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function onFlush(OnFlushEventArgs $args): void
{
//echo "---preFlush".PHP_EOL;

$em = $args->getEntityManager();
$em = $args->getObjectManager();
$uow = $em->getUnitOfWork();

foreach ($uow->getScheduledEntityInsertions() as $entity) {
Expand Down
11 changes: 1 addition & 10 deletions tests/Doctrine/Tests/ORM/Functional/InsertableUpdatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\Tests\ORM\Functional;

use Doctrine\ORM\Tools\ToolsException;
use Doctrine\Tests\Models\Upsertable\Insertable;
use Doctrine\Tests\Models\Upsertable\Updatable;
use Doctrine\Tests\OrmFunctionalTestCase;
Expand All @@ -15,15 +14,7 @@ protected function setUp(): void
{
parent::setUp();

try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(Updatable::class),
$this->_em->getClassMetadata(Insertable::class),
]
);
} catch (ToolsException) {
}
$this->createSchemaForModels(Updatable::class, Insertable::class);
}

public function testNotInsertableIsFetchedFromDatabase(): void
Expand Down
5 changes: 1 addition & 4 deletions tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ protected function setUp(): void

$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8383');

$this->_schemaTool->createSchema([
$this->_em->getClassMetadata(NotifyUser::class),
$this->_em->getClassMetadata(NotifyGroup::class),
]);
$this->createSchemaForModels(NotifyUser::class, NotifyGroup::class);
}

public function testChangeTracking(): void
Expand Down
Loading

0 comments on commit 990a1fe

Please sign in to comment.