-
-
Notifications
You must be signed in to change notification settings - Fork 71
Feature: iterable source file path names for ColocatedMappingDriver
#429
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
Feature: iterable source file path names for ColocatedMappingDriver
#429
Conversation
Why are there 9 commits? Please make fewer commits, with better messages. |
This is necessary, since in doctrine#429 we would like to use a different way of "finding files" - using a client-defined iterable. Thus, the only way to do the switch is to split the loops.
db80dd4
to
92a392d
Compare
`i` flag is removed - it makes search case-insensitive. There's no point in making search case-insensitive for an extension regex (`.php`), since the extension is always lowercase. `GET_MATCH` is changed into `MATCH` - using `MATCH` is more obvious, since there are **NO implicit modifications** of the result as in the case of `GET_MATCH`, which returns only the "matched" part of the path string instead of the actual `SplFileInfo` item. `^.+` part of regex is removed - it's no longer necessary, since it had only been required for `GET_MATCH` to return the full path. Now, with `MATCH`, regex only affects results filtering and does not affect the results themselves.
This is necessary, since in doctrine#429 we would like to use a different way of "finding files" - using a client-defined iterable. Thus, the only way to do the switch is to split the loops.
…e path names Before it was only possible to pass an array of paths where to look for. Now, it's possible to explicitly provide fine-grained iterable of only necessary files to the Driver. It's anticipated to use Symfony Finder in the Bundles using this library. This gives much flexibility for client code to configure which files should be included and which should not.
92a392d
to
a6cb5a1
Compare
Thanks @rela589n ! |
Thank you, @greg0ire So, the depending libraries need to be updated now. Do you have any considerations about how to do this properly? |
Do something similar to what you've done in your test, then contribute to I guess the same needs to be done on the ODM part. Then you can add deprecations. |
Sure! The only question I have right now is how to make things mesh together, since the changes made to
So, you mean the service that can accept an array of paths, and will implement
If I understand correctly, it could be achieved via a Compiler Pass |
You can start like this, then before merging we release
Right now, there is a way to configure the paths through config, right? Well that service should be able to reuse that config to do the same thing using the new way. |
…d paths when `ColocatedMappingDriver::addPaths()` is called after instance creation. After github.com/doctrine/pull/429/ had been merged, it could bring in subtle bugs during migration toward the new `$sourceFilePathNames` approach. If the client code had called `addPaths()` after the instance creation, it would've been ignored (without any warning or so), and paths would not have been used. This commit fixes that. Retroactively added paths will be taken into account as well as ``$sourceFilePathNames`.
…d paths when `ColocatedMappingDriver::addPaths()` is called after instance creation. After github.com/doctrine/pull/429/ had been merged, it could bring in subtle bugs during migration toward the new `$sourceFilePathNames` approach. If the client code had called `addPaths()` after the instance creation, it would've been ignored (without any warning or so), and paths would not have been used. This commit fixes that. Retroactively added paths will be taken into account as well as ``$sourceFilePathNames`.
…d paths when `ColocatedMappingDriver::addPaths()` is called after instance creation. After github.com/doctrine/pull/429/ had been merged, it could bring in subtle bugs during migration toward the new `$sourceFilePathNames` approach. If the client code had called `addPaths()` after the instance creation, it would've been ignored (without any warning or so), and paths would not have been used. This commit fixes that. Retroactively added paths will be taken into account as well as ``$sourceFilePathNames`.
…d paths. After github.com/doctrine/pull/429/ had been merged, it could bring in subtle bugs during migration toward the new `$sourceFilePathNames` approach. If the client code had called `addPaths()` after the instance creation, it would've been ignored (without any warning or so), and paths would not have been used. This commit fixes that. Retroactively added paths will be taken into account as well as ``$sourceFilePathNames`.
After github.com/doctrine/pull/429/ was merged, it could introduce subtle bugs during migration toward the new `$sourceFilePathNames` approach. If client code called `addPaths()` after instance creation, it would be ignored (without any warning), and paths would not be used. The current commit fixes that. Retroactively added paths will be taken into account along with the `$sourceFilePathNames` iterable.
In the scope of doctrine/persistence#429 there was added `ColocatedMappingDriver::$sourceFilePathNames`, which is available starting from `doctrine/persistence` >= 4.1. This commit integrates those changes into `AttributeDriver`. Since `doctrine/orm` maintains the support for `doctrine/persistence` of older versions, `AttributeDriver` ensures that `$sourceFilePathNames` is actually defined. Tests use `InstalledVersions` to opt into new behavior if `doctrine/persistence` is at least version 4.1. New behavior is adapted by using `glob()` on paths.
In the scope of doctrine/persistence#429 there was added `ColocatedMappingDriver::$sourceFilePathNames`, which is available starting from `doctrine/persistence` >= 4.1. This commit integrates those changes into `AttributeDriver`. Since `doctrine/orm` maintains the support for `doctrine/persistence` of older versions, `AttributeDriver` ensures that `$sourceFilePathNames` is actually defined. Tests use `InstalledVersions` to opt into new behavior if `doctrine/persistence` is at least version 4.1. New behavior is adapted by using `glob()` on paths.
In the scope of doctrine/persistence#429 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$sourceFilePathNames`, which allows passing the iterable of file paths 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, `AttributeDriver` ensures that `$sourceFilePathNames` is actually defined. Tests use `InstalledVersions` to opt into new behaviour if `doctrine/persistence` is at least version 4.1. The new behaviour is adapted by using `glob()` on paths.
In the scope of doctrine/persistence#429 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$sourceFilePathNames`, which allows passing the iterable of file paths 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, `AttributeDriver` ensures that `$sourceFilePathNames` is actually defined. Tests use `InstalledVersions` to opt into new behaviour if `doctrine/persistence` is at least version 4.1. `AttributeDriver` now accepts a new boolean to opt into the new behaviour. This flag is used to distinguish between an array of directory paths (the existing way) and iterable of file paths (the new way). The old behaviour can be adapted into new by using `glob()` search on directory paths.
In the scope of doctrine/persistence#429 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$sourceFilePathNames`, which allows passing the iterable of file paths 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, `AttributeDriver` ensures that `$sourceFilePathNames` is actually defined. Tests use `InstalledVersions` to opt into new behaviour if `doctrine/persistence` is at least version 4.1. `AttributeDriver` now accepts a new boolean to opt into the new behaviour. This flag is used to distinguish between an array of directory paths (the existing way) and iterable of file paths (the new way). The old behaviour can be adapted into new by using `glob()` search on directory paths.
In the scope of doctrine/persistence#429 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$sourceFilePathNames`, which allows passing an iterable 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 `$sourceFilePathNames` is actually defined. Tests use `InstalledVersions` to opt into new behaviour if `doctrine/persistence` is at least version 4.1. `AttributeDriver` now accepts a new boolean to opt into the new behaviour. This flag is used to distinguish between an array of directory paths (the existing way) and the iterable of file paths (the new way). The old behaviour can be adapted into new by using `glob()` search on directory paths.
In the scope of doctrine/persistence#429 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$sourceFilePathNames`, which allows passing an iterable 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 `$sourceFilePathNames` is actually defined. Tests use `InstalledVersions` to opt into new behaviour if `doctrine/persistence` is at least version 4.1. `AttributeDriver` now accepts a new boolean to opt into the new behaviour. This flag is used to distinguish between an array of directory paths (the existing way) and the iterable of file paths (the new way). The old behaviour can be adapted into the new one by using `glob()` search on directory paths.
In the scope of doctrine/persistence#429 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$sourceFilePathNames`, which allows passing an iterable 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 `$sourceFilePathNames` is actually defined. Tests use `InstalledVersions` to opt into new behaviour if `doctrine/persistence` is at least version 4.1. `AttributeDriver` now accepts a new boolean to opt into the new behaviour. This flag is used to distinguish between an array of directory paths (the existing way) and the iterable of file paths (the new way). The old behaviour can be adapted into the new one by using `glob()` search on directory paths.
In the scope of doctrine/persistence#429 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$sourceFilePathNames`, which allows passing an iterable 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 `$sourceFilePathNames` is actually defined. Tests use `InstalledVersions` to opt into new behaviour if `doctrine/persistence` is at least version 4.1. `AttributeDriver` now accepts a new boolean to opt into the new behaviour. This flag is used to distinguish between an array of directory paths (the existing way) and the iterable of file paths (the new way). The old behaviour can be adapted into the new one by using `glob()` search on directory paths.
In the scope of doctrine/persistence#429 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$sourceFilePathNames`, which allows passing an iterable 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 `$sourceFilePathNames` is actually defined. Tests use `InstalledVersions` to opt into new behaviour if `doctrine/persistence` is at least version 4.1. `AttributeDriver` now accepts a new boolean to opt into the new behaviour. This flag is used to distinguish between an array of directory paths (the existing way) and the iterable of file paths (the new way). The old behaviour can be adapted into the new one by using `glob()` search on directory paths.
In the scope of doctrine/persistence#429 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$sourceFilePathNames`, which allows passing the iterable of file paths 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, `AttributeDriver` ensures that `$sourceFilePathNames` is actually defined. Tests use `InstalledVersions` to opt into new behaviour if `doctrine/persistence` is at least version 4.1. `AttributeDriver` now accepts a new boolean to opt into the new behaviour. This flag is used to distinguish between an array of directory paths (the existing way) and iterable of file paths (the new way). The old behaviour can be adapted into new by using `glob()` search on directory paths.
From @GromNaN in doctrine/mongodb-odm#2794 (comment):
The iterable doesn't necessarily implement $pathsAsFilePaths = false;
$first = true;
foreach ($paths as $path) {
if ($first && is_file($path)) {
$pathsAsFilePaths = true;
}
} A bit weird, but if it allows not having to change the method signature, it sounds great! |
Extra question: do you think there might be cases where people would need to call The answer will impact #430 I'm starting to think the best implementation could be to do something like this foreach ($paths as $path) {
switch(true) {
case is_file($path):
$this->newLogic($path);
break;
case is_dir($path):
$this->legacyLogic($path);
break;
default:
throw new \InvalidArgumentException(sprintf(
'"%s" is neither a file nor a directory.',
$path,
));
}
}
A side effect of this is that it would allow |
Don't you think that this will complicate the interface? If it be so, why would we not allow either $pathsAsFilePaths = match(true) {
is_file($paths[0]) => true,
is_dir($paths[0]) => false,
default => throw new RuntimeException();
} With the difference that it doesn't require ArrayAccess: $pathsAsFilePaths = true;
foreach ($paths as $path) {
if (!is_file($path)) {
$pathsAsFilePaths = false;
}
break;
} Since we plan to migrate toward the iterable of files, IMO we should not allow |
Makes sense. So while it would be technically possible with the code I mentioned, let's not document that it's possible. Do you have thoughts about my |
Can't see any Anyway, if the driver uses an iterable of files, there's no need for files to be added via One more question I have, though, is whether https://github.com/doctrine/DoctrineBundle is going to be updated so that iterable is the new default? Do we check for |
Yes, I think iterable should be the new default, and that we should use |
Understand. I asked because it's private, and I was hesitant to check if the property exists outside of the class. So, what's next? Should I go and implement the driver without any extra arguments? |
Yes. If you want me to, I can revert #429 (or maybe only a6cb5a1), then you can submit something with a revert of the revert, your modifications, and modifications from #430, it might be easier for everyone to review. |
Let's do it |
Yes! When setting the The constructor will accept
The methods In the end, this trait should perhaps be totally depreciated. |
In favor of a new trait? In any case, let us add the deprecations after the O[DR]M and bundles have been adapted to the new code please. |
That's an interesting statement. Using
Didn't get this either |
Yeah but it will make the new way harder to use in trivial cases, which include tests.
I think @GromNaN means you could create a new trait instead of modifying the existing one. |
It's as simple as creating a new object. return new MyDriver(new ArrayIterator($filePaths)); |
In the scope of doctrine/persistence#429 (available from `doctrine/persistence` >= 4.1) there was added `ColocatedMappingDriver::$sourceFilePathNames`, which allows passing an iterable 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 `$sourceFilePathNames` is actually defined. Tests use `InstalledVersions` to opt into new behaviour if `doctrine/persistence` is at least version 4.1. `AttributeDriver` now accepts a new boolean to opt into the new behaviour. This flag is used to distinguish between an array of directory paths (the existing way) and the iterable of file paths (the new way). The old behaviour can be adapted into the new one by using `glob()` search on directory paths.
This PR follows from #424.
It aims to rework
ColocatedMappingDriver
so that it won't have the responsibility of scanning for files in the provided directories, but will instead accept an iterable of source file path names. Thus, every individual component usingColocatedMappingDriver
should provide a complete iterator that covers all files.Ultimately, Symfony Finder should be used to grab a list of PHP files that must be mapped. This aims for more flexibility regarding file scanning, so that users would be able to customize what files to include.