-
-
Notifications
You must be signed in to change notification settings - Fork 71
Introduce ClassLocator
to find class names for attribute drivers
#433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When checking $includedFiles for an included file, the previous `in_array()` approach, executed in a loop, is very expensive. Basically, it results in performance of O(N * M), where N - number of declared classes, M - number of included classes. The current approach is O(N), since `isset()` check has constant `O(1)` time.
This change makes it easy for the depending libraries to use iterable of `SplFileInfo`, adapted to the format of `ColocatedMappingDriver` file paths. For example, one could provide an instance of Symfony Finder, adapted with `FilePathNameIterator` without having to reinvent it from scratch.
This change makes it easy for the client code to migrate toward the newer version. The migration would be as easy as passing `new FilePathIterator(new DirectoryFilesIterator($paths))` into the constructor instead of the array of `$paths`.
This commit adds support for `ColocatedMappingDriver` to accept `iterable` of file paths. Before it was only possible to accept an array of directory paths. Now, one could provide fine-grained iterator of only necessary files to the Driver. Bundles should use Symfony Finder to implement it, since it gives much flexibility to the client code to configure which files should be included and which not. Backward compatibility is achieved with the following approach: If it's an array, then it should be OK to take a look at `$paths[0]` and determine if it is a file or a directory. If it's not an array, we can assume that it's `$filePaths` iterable that's given.
@rela589n This PR goes a step further than what you've proposed, by exposing a list of class names instead of scanning file. |
greg0ire
reviewed
Aug 12, 2025
greg0ire
reviewed
Aug 12, 2025
ClassLocator
to find classes names for attribute driversClassLocator
to find class names for attribute drivers
8e475b1
to
1ee8060
Compare
greg0ire
previously approved these changes
Aug 13, 2025
rela589n
reviewed
Aug 13, 2025
rela589n
added a commit
to rela589n/doctrine-phpcr-odm
that referenced
this pull request
Aug 16, 2025
The changes integrate doctrine/persistence#433 ClassLocator allows clients to pass any iterable of classes they might want.
rela589n
added a commit
to rela589n/doctrine-orm
that referenced
this pull request
Aug 16, 2025
In the scope of doctrine/persistence#433 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$classLocator` property, which allows passing any instance of `ClassLocator` for the mapping driver to use. This commit integrates those changes into `AttributeDriver`. Since `doctrine/orm` maintains the support for `doctrine/persistence` of older versions, tests ensure that `ClassLocator` actually exists. The old paths behaviour can be adapted into the new by using `FileClassLocator::createFromDirectories($directoryPaths)` and passing it as a class locator to `AttributeDriver`. # Conflicts: # tests/Tests/ORM/Persisters/BinaryIdPersisterTest.php
rela589n
added a commit
to rela589n/doctrine-orm
that referenced
this pull request
Aug 16, 2025
In the scope of doctrine/persistence#433 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$classLocator` (`ClassLocator`) property, which allows passing any instance of `ClassLocator` for the mapping driver to use. This commit integrates those changes into `AttributeDriver`. Since `doctrine/orm` maintains the support for `doctrine/persistence` of older versions, tests ensure that `ClassLocator` actually exists. The old paths' behaviour can be adapted into the new by passing `FileClassLocator` into `AttributeDriver` (see `FileClassLocator::createFromDirectories($directoryPaths)`).
rela589n
added a commit
to rela589n/doctrine-orm
that referenced
this pull request
Aug 16, 2025
In the scope of doctrine/persistence#433 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$classLocator` (`ClassLocator`) property, which allows passing any instance of `ClassLocator` for the mapping driver to use. This commit integrates those changes into `AttributeDriver`. Since `doctrine/orm` maintains the support for `doctrine/persistence` of older versions, tests ensure that `ClassLocator` actually exists. The old paths' behaviour can be adapted into the new by passing `FileClassLocator` into `AttributeDriver` (see `FileClassLocator::createFromDirectories($directoryPaths)`).
rela589n
added a commit
to rela589n/doctrine-phpcr-odm
that referenced
this pull request
Aug 16, 2025
The changes integrate doctrine/persistence#433 ClassLocator allows clients to pass any iterable of classes they might want.
rela589n
added a commit
to rela589n/doctrine-orm
that referenced
this pull request
Aug 20, 2025
In the scope of doctrine/persistence#433 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$classLocator` (`ClassLocator`) property, which allows passing any instance of `ClassLocator` for the mapping driver to use. This commit integrates those changes into `AttributeDriver`. Since `doctrine/orm` maintains the support for `doctrine/persistence` of older versions, tests ensure that `ClassLocator` actually exists. The old paths' behaviour can be adapted into the new by passing `FileClassLocator` into `AttributeDriver` (see `FileClassLocator::createFromDirectories($directoryPaths)`).
rela589n
added a commit
to rela589n/doctrine-orm
that referenced
this pull request
Aug 20, 2025
In the scope of doctrine/persistence#433 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$classLocator` (`ClassLocator`) property, which allows passing any instance of `ClassLocator` for the mapping driver to use. This commit integrates those changes into `AttributeDriver`. Since `doctrine/orm` maintains the support for `doctrine/persistence` of older versions, tests ensure that `ClassLocator` actually exists. The old paths' behaviour can be adapted into the new by passing `FileClassLocator` into `AttributeDriver` (see `FileClassLocator::createFromDirectories($directoryPaths)`).
rela589n
added a commit
to rela589n/doctrine-phpcr-odm
that referenced
this pull request
Aug 21, 2025
The changes integrate doctrine/persistence#433 ClassLocator allows clients to pass any iterable of classes they might want.
rela589n
added a commit
to rela589n/doctrine-phpcr-odm
that referenced
this pull request
Aug 21, 2025
The changes integrate doctrine/persistence#433 ClassLocator allows clients to pass any iterable of classes they might want.
rela589n
added a commit
to rela589n/doctrine-orm
that referenced
this pull request
Aug 21, 2025
In the scope of doctrine/persistence#433 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$classLocator` (`ClassLocator`) property, which allows passing any instance of `ClassLocator` for the mapping driver to use. This commit integrates those changes into `AttributeDriver`. Since `doctrine/orm` maintains the support for `doctrine/persistence` of older versions, tests ensure that `ClassLocator` actually exists. The old paths' behaviour can be adapted into the new by passing `FileClassLocator` into `AttributeDriver` (see `FileClassLocator::createFromDirectories($directoryPaths)`).
rela589n
added a commit
to rela589n/doctrine-phpcr-odm
that referenced
this pull request
Aug 21, 2025
These changes integrate doctrine/persistence#433 `ClassLocator` allows clients to pass any iterable of classes they might want.
rela589n
added a commit
to rela589n/doctrine-phpcr-odm
that referenced
this pull request
Aug 21, 2025
These changes integrate doctrine/persistence#433 `ClassLocator` allows clients to pass any iterable of classes they might want.
rela589n
added a commit
to rela589n/doctrine-orm
that referenced
this pull request
Aug 21, 2025
In the scope of doctrine/persistence#433 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$classLocator` (`ClassLocator`) property, which allows passing any instance of `ClassLocator` for the mapping driver to use. This commit integrates those changes into `AttributeDriver`. Since `doctrine/orm` maintains the support for `doctrine/persistence` of older versions, tests ensure that `ClassLocator` actually exists. The old paths' behaviour can be adapted into the new by passing `FileClassLocator` into `AttributeDriver` (see `FileClassLocator::createFromDirectories($directoryPaths)`).
rela589n
added a commit
to rela589n/doctrine-orm
that referenced
this pull request
Aug 21, 2025
In the scope of doctrine/persistence#433 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$classLocator` (`ClassLocator`) property, which allows passing any instance of `ClassLocator` for the mapping driver to use. This commit integrates those changes into `AttributeDriver`. Since `doctrine/orm` maintains the support for `doctrine/persistence` of older versions, tests ensure that `ClassLocator` actually exists. The old paths' behaviour can be adapted into the new by passing `FileClassLocator` into `AttributeDriver` (see `FileClassLocator::createFromDirectories($directoryPaths)`).
rela589n
added a commit
to rela589n/doctrine-orm
that referenced
this pull request
Aug 23, 2025
In the scope of doctrine/persistence#433 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$classLocator` (`ClassLocator`) property, which allows passing any instance of `ClassLocator` for the mapping driver to use. This commit integrates those changes into `AttributeDriver`. Since `doctrine/orm` maintains the support for `doctrine/persistence` of older versions, tests ensure that `ClassLocator` actually exists. The old paths' behaviour can be adapted into the new by passing `FileClassLocator` into `AttributeDriver` (see `FileClassLocator::createFromDirectories($directoryPaths)`).
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Alternative approach to #432 to decouple the class name discovery from the read of metadata in the attribute (and annotation) drivers.
Other drivers use a
FileLocator
to provide the list of files to read.For the attribute/annotation/static-php drivers, the driver class itself does the directory scanning, while its main purpose is to load the metadata of each class.
In this PR I introduce a
ClassLocator
interface with 2 implementations:ClassNames
is a simple list of classes namesFileClassLocator
scans a list of files, it can also be constructed from a list of directories to support the current usage.FileClassLocator::createFromDirectories($dirPaths, $fileExtension, $excludedDirs)
.My goal is to make it possible in Symfony to tag any class in the project with the
#[Entity]
attribute and get it identified by the EntityManager. Symfony DI resource discovery feature will be leveraged so that we don't need to scan the directories in Doctrine (which is done at runtime, and may be cached).