Skip to content

Commit

Permalink
Merge branch '2.11.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 2.11.x:
  Deprecate Setup::registerAutoloadDirectory() (doctrine#9249)
  PHPCS 3.6.2, Psalm 4.15.0 (doctrine#9247)
  Add SchemaIgnoreClasses property for doctrine#8195. (doctrine#9202)
  Remove fallbacks for old doctrine/annotations version (doctrine#9235)
  Update docs/en/reference/events.rst
  Added psalm param to abstract addFilterConstraint (doctrine#9229)
  Merge pull request doctrine#9210 from alexander-schranz/patch-2
  Fix typo assumptio--> assumption
  Update events.rst
  Completing links to `EventArgs` classes in overview table
  Using `const` for `type`
  [Documentation] Events Overview Table: Adding "Passed Argument" column
  • Loading branch information
derrabus committed Dec 13, 2021
2 parents 36160a8 + 003090b commit 414aae5
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 64 deletions.
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ Use `toIterable()` instead.

# Upgrade to 2.11

## Deprecated: `Setup::registerAutoloadDirectory()`

Use Composer's autoloader instead.

## Deprecated: `AbstractHydrator::hydrateRow()`

Following the deprecation of the method `AbstractHydrator::iterate()`, the
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "1.2.0",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "3.6.1",
"squizlabs/php_codesniffer": "3.6.2",
"symfony/cache": "^4.4 || ^5.2",
"vimeo/psalm": "4.13.1"
"vimeo/psalm": "4.15.0"
},
"conflict": {
"doctrine/annotations": "<1.13 || >= 2.0"
Expand Down
13 changes: 13 additions & 0 deletions docs/en/reference/advanced-configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,19 @@ That will be available for all entities without a custom repository class.
The default value is ``Doctrine\ORM\EntityRepository``.
Any repository class must be a subclass of EntityRepository otherwise you got an ORMException

Ignoring entities (***OPTIONAL***)
-----------------------------------

Specifies the Entity FQCNs to ignore.
SchemaTool will then skip these (e.g. when comparing schemas).

.. code-block:: php
<?php
$config->setSchemaIgnoreClasses([$fqcn]);
$config->getSchemaIgnoreClasses();
Setting up the Console
----------------------

Expand Down
98 changes: 56 additions & 42 deletions docs/en/reference/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,38 +136,38 @@ entity, see :ref:`Lifecycle Callbacks<lifecycle-callbacks>`.
Events Overview
---------------

+-----------------------------------------------------------------+-----------------------+-----------+
| Event | Dispatched by | Lifecycle |
| | | Callback |
+=================================================================+=======================+===========+
| :ref:`preRemove<reference-events-pre-remove>` | ``$em->remove()`` | Yes |
+-----------------------------------------------------------------+-----------------------+-----------+
| :ref:`postRemove<reference-events-post-update-remove-persist>` | ``$em->flush()`` | Yes |
+-----------------------------------------------------------------+-----------------------+-----------+
| :ref:`prePersist<reference-events-pre-persist>` | ``$em->persist()`` | Yes |
| | on *initial* persist | |
+-----------------------------------------------------------------+-----------------------+-----------+
| :ref:`postPersist<reference-events-post-update-remove-persist>` | ``$em->flush()`` | Yes |
+-----------------------------------------------------------------+-----------------------+-----------+
| :ref:`preUpdate<reference-events-pre-update>` | ``$em->flush()`` | Yes |
+-----------------------------------------------------------------+-----------------------+-----------+
| :ref:`postUpdate<reference-events-post-update-remove-persist>` | ``$em->flush()`` | Yes |
+-----------------------------------------------------------------+-----------------------+-----------+
| :ref:`postLoad<reference-events-post-load>` | Loading from database | Yes |
+-----------------------------------------------------------------+-----------------------+-----------+
| :ref:`loadClassMetadata<reference-events-load-class-metadata>` | Loading of mapping | No |
| | metadata | |
+-----------------------------------------------------------------+-----------------------+-----------+
| ``onClassMetadataNotFound`` | ``MappingException`` | No |
+-----------------------------------------------------------------+-----------------------+-----------+
| :ref:`preFlush<reference-events-pre-flush>` | ``$em->flush()`` | Yes |
+-----------------------------------------------------------------+-----------------------+-----------+
| :ref:`onFlush<reference-events-on-flush>` | ``$em->flush()`` | No |
+-----------------------------------------------------------------+-----------------------+-----------+
| :ref:`postFlush<reference-events-post-flush>` | ``$em->flush()`` | No |
+-----------------------------------------------------------------+-----------------------+-----------+
| ``onClear`` | ``$em->clear()`` | No |
+-----------------------------------------------------------------+-----------------------+-----------+
+-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+
| Event | Dispatched by | Lifecycle | Passed |
| | | Callback | Argument |
+=================================================================+=======================+===========+=====================================+
| :ref:`preRemove<reference-events-pre-remove>` | ``$em->remove()`` | Yes | `_LifecycleEventArgs`_ |
+-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+
| :ref:`postRemove<reference-events-post-update-remove-persist>` | ``$em->flush()`` | Yes | `_LifecycleEventArgs`_ |
+-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+
| :ref:`prePersist<reference-events-pre-persist>` | ``$em->persist()`` | Yes | `_LifecycleEventArgs`_ |
| | on *initial* persist | | |
+-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+
| :ref:`postPersist<reference-events-post-update-remove-persist>` | ``$em->flush()`` | Yes | `_LifecycleEventArgs`_ |
+-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+
| :ref:`preUpdate<reference-events-pre-update>` | ``$em->flush()`` | Yes | `_PreUpdateEventArgs`_ |
+-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+
| :ref:`postUpdate<reference-events-post-update-remove-persist>` | ``$em->flush()`` | Yes | `_LifecycleEventArgs`_ |
+-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+
| :ref:`postLoad<reference-events-post-load>` | Loading from database | Yes | `_LifecycleEventArgs`_ |
+-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+
| :ref:`loadClassMetadata<reference-events-load-class-metadata>` | Loading of mapping | No | `_LoadClassMetadataEventArgs` |
| | metadata | | |
+-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+
| ``onClassMetadataNotFound`` | ``MappingException`` | No | `_OnClassMetadataNotFoundEventArgs` |
+-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+
| :ref:`preFlush<reference-events-pre-flush>` | ``$em->flush()`` | Yes | `_PreFlushEventArgs`_ |
+-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+
| :ref:`onFlush<reference-events-on-flush>` | ``$em->flush()`` | No | `_OnFlushEventArgs` |
+-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+
| :ref:`postFlush<reference-events-post-flush>` | ``$em->flush()`` | No | `_PostFlushEventArgs` |
+-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+
| ``onClear`` | ``$em->clear()`` | No | `_OnClearEventArgs` |
+-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+

Naming convention
~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -295,6 +295,9 @@ specific to a particular entity class's lifecycle.
<?php
use Doctrine\DBAL\Types\Types;
use Doctrine\Persistence\Event\LifecycleEventArgs;
/**
* #[Entity]
* #[HasLifecycleCallbacks]
Expand All @@ -303,11 +306,11 @@ specific to a particular entity class's lifecycle.
{
// ...
#[Column(type: 'string', length: 255)]
#[Column(type: Types::STRING, length: 255)]
public $value;
#[PrePersist]
public function doStuffOnPrePersist()
public function doStuffOnPrePersist(LifecycleEventArgs $eventArgs)
{
$this->createdAt = date('Y-m-d H:i:s');
}
Expand All @@ -318,16 +321,18 @@ specific to a particular entity class's lifecycle.
$this->value = 'changed from prePersist callback!';
}
#[PostLoad]
public function doStuffOnPostLoad()
#[PreUpdate]
public function doStuffOnPreUpdate(PreUpdateEventArgs $eventArgs)
{
$this->value = 'changed from postLoad callback!';
$this->value = 'changed from preUpdate callback!';
}
}
.. code-block:: annotation
<?php
use Doctrine\Persistence\Event\LifecycleEventArgs;
/**
* @Entity
* @HasLifecycleCallbacks
Expand All @@ -340,7 +345,7 @@ specific to a particular entity class's lifecycle.
public $value;
/** @PrePersist */
public function doStuffOnPrePersist()
public function doStuffOnPrePersist(LifecycleEventArgs $eventArgs)
{
$this->createdAt = date('Y-m-d H:i:s');
}
Expand All @@ -351,10 +356,10 @@ specific to a particular entity class's lifecycle.
$this->value = 'changed from prePersist callback!';
}
/** @PostLoad */
public function doStuffOnPostLoad()
/** @PreUpdate */
public function doStuffOnPreUpdate(PreUpdateEventArgs $eventArgs)
{
$this->value = 'changed from postLoad callback!';
$this->value = 'changed from preUpdate callback!';
}
}
.. code-block:: xml
Expand All @@ -370,7 +375,7 @@ specific to a particular entity class's lifecycle.
<lifecycle-callbacks>
<lifecycle-callback type="prePersist" method="doStuffOnPrePersist"/>
<lifecycle-callback type="prePersist" method="doOtherStuffOnPrePersist"/>
<lifecycle-callback type="postLoad" method="doStuffOnPostLoad"/>
<lifecycle-callback type="preUpdate" method="doStuffOnPreUpdate"/>
</lifecycle-callbacks>
</entity>
</doctrine-mapping>
Expand Down Expand Up @@ -1047,3 +1052,12 @@ and the EntityManager.
$em = $eventArgs->getEntityManager();
}
}
.. _LifecycleEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/LifecycleEventArgs.php
.. _PreUpdateEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php
.. _PreFlushEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/PreFlushEventArgs.php
.. _PostFlushEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/PostFlushEventArgs.php
.. _OnFlushEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/OnFlushEventArgs.php
.. _OnClearEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/OnClearEventArgs.php
.. _LoadClassMetadataEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php
.. _OnClassMetadataNotFoundEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/OnClassMetadataNotFoundEventArgs.php
2 changes: 1 addition & 1 deletion docs/en/tutorials/extra-lazy-associations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ easily using a combination of ``count`` and ``slice``.
``removeElement`` directly issued DELETE queries to the database from
version 2.4.0 to 2.7.0. This circumvents the flush operation and might run
outside a transactional boundary if you don't create one yourself. We
consider this a critical bug in the assumptio of how the ORM works and
consider this a critical bug in the assumption of how the ORM works and
reverted ``removeElement`` EXTRA_LAZY behavior in 2.7.1.


Expand Down
2 changes: 1 addition & 1 deletion doctrine-mapping.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:choice>
<xs:attribute name="name" type="xs:NMTOKEN" use="optional"/>
<xs:attribute name="columns" type="xs:string" use="required"/>
<xs:attribute name="columns" type="xs:string" use="optional"/>
<xs:attribute name="fields" type="xs:string" use="optional"/>
<xs:attribute name="flags" type="xs:string" use="optional"/>
<xs:anyAttribute namespace="##other"/>
Expand Down
20 changes: 20 additions & 0 deletions lib/Doctrine/ORM/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -982,4 +982,24 @@ public function setDefaultQueryHint($name, $value)
{
$this->_attributes['defaultQueryHints'][$name] = $value;
}

/**
* Gets a list of entity class names to be ignored by the SchemaTool
*
* @return list<class-string>
*/
public function getSchemaIgnoreClasses(): array
{
return $this->_attributes['schemaIgnoreClasses'] ?? [];
}

/**
* Sets a list of entity class names to be ignored by the SchemaTool
*
* @param list<class-string> $schemaIgnoreClasses List of entity class names
*/
public function setSchemaIgnoreClasses(array $schemaIgnoreClasses): void
{
$this->_attributes['schemaIgnoreClasses'] = $schemaIgnoreClasses;
}
}
1 change: 1 addition & 0 deletions lib/Doctrine/ORM/Query/Filter/SQLFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ final protected function getConnection(): Connection
* Gets the SQL query part to add to a query.
*
* @param string $targetTableAlias
* @psalm-param ClassMetadata<object> $targetEntity
*
* @return string The constraint SQL if there is available, empty string otherwise.
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ private function processingNotRequired(
return isset($processedClasses[$class->name]) ||
$class->isMappedSuperclass ||
$class->isEmbeddedClass ||
($class->isInheritanceTypeSingleTable() && $class->name !== $class->rootEntityName);
($class->isInheritanceTypeSingleTable() && $class->name !== $class->rootEntityName) ||
in_array($class->name, $this->em->getConfiguration()->getSchemaIgnoreClasses());
}

/**
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/ORM/Tools/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Setup
* Use this method to register all autoloads for a downloaded Doctrine library.
* Pick the directory the library was uncompressed into.
*
* @deprecated Use Composer's autoloader instead.
*
* @param string $directory
*
* @return void
Expand Down
5 changes: 4 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.13.1@5cf660f63b548ccd4a56f62d916ee4d6028e01a3">
<files psalm-version="v4.15.0@a1b5e489e6fcebe40cb804793d964e99fc347820">
<file src="lib/Doctrine/ORM/AbstractQuery.php">
<DeprecatedMethod occurrences="3">
<code>getResultCacheDriver</code>
Expand Down Expand Up @@ -999,6 +999,9 @@
<code>$this-&gt;table</code>
<code>$this-&gt;table</code>
</PropertyTypeCoercion>
<RedundantCast occurrences="1">
<code>array_values</code>
</RedundantCast>
<RedundantConditionGivenDocblockType occurrences="3">
<code>$className !== null</code>
<code>$mapping !== false</code>
Expand Down
28 changes: 28 additions & 0 deletions tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,34 @@ public function testIncorrectUniqueConstraintsBasedOnFields(): void
$this->expectException(MappingException::class);
$schemaTool->getSchemaFromMetadata([$class]);
}

/**
* @group schema-configuration
*/
public function testConfigurationSchemaIgnoredEntity(): void
{
$em = $this->getTestEntityManager();
$schemaTool = new SchemaTool($em);

$classes = [
$em->getClassMetadata(FirstEntity::class),
$em->getClassMetadata(SecondEntity::class),
];

$schema = $schemaTool->getSchemaFromMetadata($classes);

self::assertTrue($schema->hasTable('first_entity'), 'Table first_entity should exist.');
self::assertTrue($schema->hasTable('second_entity'), 'Table second_entity should exist.');

$em->getConfiguration()->setSchemaIgnoreClasses([
SecondEntity::class,
]);

$schema = $schemaTool->getSchemaFromMetadata($classes);

self::assertTrue($schema->hasTable('first_entity'), 'Table first_entity should exist.');
self::assertFalse($schema->hasTable('second_entity'), 'Table second_entity should not exist.');
}
}

/**
Expand Down
21 changes: 5 additions & 16 deletions tests/Doctrine/Tests/OrmTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,12 @@ abstract class OrmTestCase extends DoctrineTestCase
/** @var Cache|null */
protected $secondLevelCacheDriverImpl = null;

/**
* @param mixed $alias
*/
protected function createAnnotationDriver(array $paths = [], $alias = null): AnnotationDriver
protected function createAnnotationDriver(array $paths = []): AnnotationDriver
{
// Register the ORM Annotations in the AnnotationRegistry
$reader = new Annotations\AnnotationReader();

if (class_exists(Annotations\PsrCachedReader::class)) {
$reader = new Annotations\PsrCachedReader($reader, new ArrayAdapter());
} else {
$reader = new Annotations\CachedReader($reader, DoctrineProvider::wrap(new ArrayAdapter()));
}

Annotations\AnnotationRegistry::registerFile(__DIR__ . '/../../../lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');

return new AnnotationDriver($reader, (array) $paths);
return new AnnotationDriver(
new Annotations\PsrCachedReader(new Annotations\AnnotationReader(), new ArrayAdapter()),
$paths
);
}

/**
Expand Down

0 comments on commit 414aae5

Please sign in to comment.