Skip to content

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Aug 13, 2025

Q A
Type feature
BC Break no
Fixed issues

Summary

Alternative to #2794 using doctrine/persistence#433

@GromNaN GromNaN marked this pull request as draft August 13, 2025 14:37
@GromNaN GromNaN requested a review from Copilot August 13, 2025 14:37
Copilot

This comment was marked as outdated.

@GromNaN GromNaN changed the title Class locator Enable ClassLocator from Doctrine Persistence 4.1 Aug 13, 2025
rela589n and others added 4 commits August 22, 2025 01:01
In the scope of doctrine/persistence#432
(available from `doctrine/persistence` >= 4.1) there was added
`ColocatedMappingDriver::$filePaths`, which allows
passing an `Traversable` of file paths for the mapping driver to use.
This commit integrates those changes into `AttributeDriver`
(and `AnnotationDriver`).

Since `doctrine/orm` maintains the support
for `doctrine/persistence` of older versions, the `AttributeDriver`
ensures that `$filePaths` is actually defined.
Tests use `InstalledVersions` to opt into new behaviour if
`doctrine/persistence` is at least version 4.1.

The old behaviour can be adapted into new by using
`DirectoryFilesIterator` and `FilePathNameIterator` on directory paths.
@GromNaN GromNaN force-pushed the class-locator branch 3 times, most recently from 6388dd8 to 80989af Compare August 21, 2025 23:50
@GromNaN GromNaN marked this pull request as ready for review August 21, 2025 23:51
@GromNaN GromNaN requested review from Copilot and greg0ire August 21, 2025 23:51
Copilot

This comment was marked as outdated.

@GromNaN GromNaN requested a review from Copilot August 26, 2025 13:54
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables support for ClassLocator from Doctrine Persistence 4.1+, providing improved flexibility for locating ODM classes by supporting class locators alongside traditional directory-based mapping.

  • Adds conditional support for ClassLocator interface in AttributeDriver and AnnotationDriver
  • Updates test cases to use the new ClassLocator API when available
  • Adds documentation examples for FileClassLocator and ClassNames usage

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeDriver.php Updates constructor to accept ClassLocator instances and fixes typo in class docblock
lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php Updates constructor to support ClassLocator and fixes initialization order
tests/Doctrine/ODM/MongoDB/Tests/BaseTestCase.php Adds conditional FileClassLocator usage in metadata driver creation
tests/Doctrine/ODM/MongoDB/Tests/Mapping/*.php Updates test drivers to accept paths parameter and use new APIs conditionally
tests/Doctrine/ODM/MongoDB/Tests/Tools/Console/Command/Schema/UpdateCommandTest.php Refactors driver creation to use ClassNames when available
docs/en/reference/metadata-drivers.rst Adds comprehensive documentation for new ClassLocator usage patterns

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@GromNaN GromNaN merged commit 4f3dbd0 into doctrine:2.12.x Aug 27, 2025
22 checks passed
@GromNaN GromNaN deleted the class-locator branch August 27, 2025 08:00
@GromNaN GromNaN added this to the 2.12.0 milestone Aug 27, 2025
@GromNaN GromNaN changed the title Enable ClassLocator from Doctrine Persistence 4.1 Enable ClassLocator from Doctrine Persistence 4.1 in the attribute and annotation drivers Aug 27, 2025
rela589n added a commit to rela589n/symfony that referenced this pull request Aug 27, 2025
In the scope of doctrine/persistence#433
(available from `doctrine/persistence` >= 4.1) there was added
`ColocatedMappingDriver::$classLocator`, which allows passing any
instance of `ClassLocator` for the mapping driver to use.

This commit integrates those changes into `AbstractDoctrineExtension`,
used by respective ORM, MongoDB-ODM, PHPCR-ODM bundles. The solution
registers a "mapping_class_finder" service that can be used by the
client code to customize class finding logic.

The changes come into play starting with doctrine/persistence >= 4.1,
and the actual registration happens only if `AttributeDriver` supports
`ClassLocator`.

Dependent libraries would adhere to the same interface, where
`ClassLocator` is in the first argument.

The changes were introduced for:
- ORM: doctrine/orm#12131;
- ODM: doctrine/mongodb-odm#2802;
- PHPCR ODM: doctrine/phpcr-odm#875.
rela589n added a commit to rela589n/symfony that referenced this pull request Aug 27, 2025
In the scope of doctrine/persistence#433
(available from `doctrine/persistence` >= 4.1) there was added
`ColocatedMappingDriver::$classLocator`, which allows passing any
instance of `ClassLocator` for the mapping driver to use.

This commit integrates those changes into `AbstractDoctrineExtension`,
used by respective ORM, MongoDB-ODM, PHPCR-ODM bundles. The solution
registers a "mapping_class_finder" service that can be used by the
client code to customize class finding logic.

The changes come into play starting with doctrine/persistence >= 4.1,
and the actual registration happens only if `AttributeDriver` supports
`ClassLocator`.

Dependent libraries would adhere to the same interface, where
`ClassLocator` is in the first argument.

The changes were introduced for:
- ORM: doctrine/orm#12131;
- ODM: doctrine/mongodb-odm#2802;
- PHPCR ODM: doctrine/phpcr-odm#875.
rela589n added a commit to rela589n/symfony that referenced this pull request Aug 27, 2025
In the scope of doctrine/persistence#433
(available from `doctrine/persistence` >= 4.1) there was added
`ColocatedMappingDriver::$classLocator`, which allows passing any
instance of `ClassLocator` for the mapping driver to use.

This commit integrates those changes into `AbstractDoctrineExtension`,
used by respective ORM, MongoDB-ODM, PHPCR-ODM bundles. The solution
registers a "mapping_class_finder" service that can be used by the
client code to customize class finding logic.

The changes come into play starting with doctrine/persistence >= 4.1,
and the actual registration happens only if `AttributeDriver` supports
`ClassLocator`.

Dependent libraries would adhere to the same interface, where
`ClassLocator` is in the first argument.

The changes were introduced for:
- ORM: doctrine/orm#12131;
- ODM: doctrine/mongodb-odm#2802;
- PHPCR ODM: doctrine/phpcr-odm#875.
rela589n added a commit to rela589n/symfony that referenced this pull request Aug 27, 2025
In the scope of doctrine/persistence#433
(available from `doctrine/persistence` >= 4.1) there was added
`ColocatedMappingDriver::$classLocator`, which allows passing any
instance of `ClassLocator` for the mapping driver to use.

This commit integrates those changes into `AbstractDoctrineExtension`,
used by respective ORM, MongoDB-ODM, PHPCR-ODM bundles. The solution
registers a "mapping_class_finder" service that can be used by the
client code to customize class finding logic.

The changes come into play starting with doctrine/persistence >= 4.1,
and the actual registration happens only if `AttributeDriver` supports
`ClassLocator`.

Dependent libraries would adhere to the same interface, where
`ClassLocator` is in the first argument.

The changes were introduced for:
- ORM: doctrine/orm#12131;
- ODM: doctrine/mongodb-odm#2802;
- PHPCR ODM: doctrine/phpcr-odm#875.
rela589n added a commit to rela589n/symfony that referenced this pull request Aug 27, 2025
In the scope of doctrine/persistence#433
(available from `doctrine/persistence` >= 4.1) there was added
`ColocatedMappingDriver::$classLocator`, which allows passing any
instance of `ClassLocator` for the mapping driver to use.

This commit integrates those changes into `AbstractDoctrineExtension`,
used by respective ORM, MongoDB-ODM, PHPCR-ODM bundles. The solution
registers a "mapping_class_finder" service that can be used by the
client code to customize class finding logic.

The changes come into play starting with doctrine/persistence >= 4.1,
and the actual registration happens only if `AttributeDriver` supports
`ClassLocator`.

Dependent libraries would adhere to the same interface, where
`ClassLocator` is in the first argument.

The changes were introduced for:
- ORM: doctrine/orm#12131;
- ODM: doctrine/mongodb-odm#2802;
- PHPCR ODM: doctrine/phpcr-odm#875.
rela589n added a commit to rela589n/symfony that referenced this pull request Aug 27, 2025
In the scope of doctrine/persistence#433
(available from `doctrine/persistence` >= 4.1) there was added
`ColocatedMappingDriver::$classLocator`, which allows passing any
instance of `ClassLocator` for the mapping driver to use.

This commit integrates those changes into `AbstractDoctrineExtension`,
used by respective ORM, MongoDB-ODM, PHPCR-ODM bundles. The solution
registers a "mapping_class_finder" service that can be used by the
client code to customize class finding logic.

The changes come into play starting with doctrine/persistence >= 4.1,
and the actual registration happens only if `AttributeDriver` supports
`ClassLocator`.

Dependent libraries would adhere to the same interface, where
`ClassLocator` is in the first argument.

The changes were introduced for:
- ORM: doctrine/orm#12131;
- ODM: doctrine/mongodb-odm#2802;
- PHPCR ODM: doctrine/phpcr-odm#875.
rela589n added a commit to rela589n/symfony that referenced this pull request Aug 29, 2025
In the scope of doctrine/persistence#433
(available from `doctrine/persistence` >= 4.1) there was added
`ColocatedMappingDriver::$classLocator`, which allows passing any
instance of `ClassLocator` for the mapping driver to use.

This commit integrates those changes into `AbstractDoctrineExtension`,
used by respective ORM, MongoDB-ODM, PHPCR-ODM bundles. The solution
registers a "mapping_class_finder" service that can be used by the
client code to customize class finding logic.

The changes come into play starting with doctrine/persistence >= 4.1,
and the actual registration happens only if `AttributeDriver` supports
`ClassLocator`.

Dependent libraries would adhere to the same interface, where
`ClassLocator` is in the first argument.

The changes were introduced for:
- ORM: doctrine/orm#12131;
- ODM: doctrine/mongodb-odm#2802;
- PHPCR ODM: doctrine/phpcr-odm#875.
rela589n added a commit to rela589n/symfony that referenced this pull request Aug 29, 2025
In the scope of doctrine/persistence#433
(available from `doctrine/persistence` >= 4.1) there was added
`ColocatedMappingDriver::$classLocator`, which allows passing any
instance of `ClassLocator` for the mapping driver to use.

This commit integrates those changes into `AbstractDoctrineExtension`,
used by respective ORM, MongoDB-ODM, PHPCR-ODM bundles. The solution
registers a "mapping_class_finder" service that can be used by the
client code to customize class finding logic.

The changes come into play starting with doctrine/persistence >= 4.1,
and the actual registration happens only if `AttributeDriver` supports
`ClassLocator`.

Dependent libraries would adhere to the same interface, where
`ClassLocator` is in the first argument.

The changes were introduced for:
- ORM: doctrine/orm#12131;
- ODM: doctrine/mongodb-odm#2802;
- PHPCR ODM: doctrine/phpcr-odm#875.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants