-
-
Notifications
You must be signed in to change notification settings - Fork 74
Feature: ColocatedMappingDriver::$fileRegex #424
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: ColocatedMappingDriver::$fileRegex #424
Conversation
723ebd7 to
de10da0
Compare
|
Hi, @greg0ire , could you please check it? |
|
@greg0ire , just a gentle reminder that I'm still waiting |
|
I don't see how this addresses the concerned voiced in #417 (comment) or follow the recommendation made in #417 (comment) |
|
I reopened the PR, because I couldn't get the response |
|
I agree that using Symfony Finder would be better for complex use cases. It's great component and I appreciate it. |
|
@greg0ire , what can we do to move on? |
|
@greg0ire , just a polite nudge 🙂 can we move onward? |
|
Not unless you move from the regex implementation to the iterable files implementation. |
|
Yes, to move with this I need to understand your vision and how you anticipate this. |
|
@greg0ire , Hi, could you please respond? |
|
No. |
|
Where do you expect iterable of files to be passed in? |
|
@greg0ire , hi! regarding iterable files approach, do you expect finder to be passed in as That's how ORM driver uses it: class AttributeDriver implements MappingDriver
{
use ColocatedMappingDriver;
public function __construct(array $paths, bool $reportFieldsWhereDeclared = true)
{
// @@
$this->addPaths($paths);
}
} |
|
@greg0ire , how do you expect iterable to be given? |
|
I would expect it to be passed in the constructor of the driver, as I don't think it should be changed afterwards. I don't think you want to add more paths at runtime, everything should be provided when compiling the dependency injection container (in the context of Symfony) IMO. |
|
So, as I understand, we should:
Obviously, this is full of BC breaks. Is it acceptable?
Yes, I agree with that. I'm all in for immutability when possible. The question is whether it's possible. |
No. I think you could maintain 2 separate properties and deprecate one of the 2, and throw an exception when the user attempts to write to both.
I hope… if it is not, then we might allow the contribution of a method that allows to add more paths afterwards, but first, let's try without, shall we? |
|
Right now doctrine/orm driver constructor method signature looks like this: public function __construct(array $paths, bool $reportFieldsWhereDeclared = true)We could probably change Thus, if On So |
|
Ah, I didn't have the fact that the constructor was defined in the driver in mind. I think we should rather make this opt-in, with a boolean as a third argument to this, that can throw an exception in 4.x, just like |
Will it be any better than the suggested approach? I presume it's possible that you didn't fully get what I intended to communicate. It's possible to keep the existing signature (parameter-count-wise) and trigger deprecation only in cases where an old /**
- * @param array<string> $paths
- * @param true $reportFieldsWhereDeclared no-op, to be removed in 4.0
+ * @param array<string>|iterable<\SplFileInfo> $paths
+ * @param true $reportFieldsWhereDeclared no-op, to be removed in 4.0
*/
- public function __construct(array $paths, bool $reportFieldsWhereDeclared = true)
+ public function __construct(iterable $paths, bool $reportFieldsWhereDeclared = true)
{
if (! $reportFieldsWhereDeclared) {
throw new InvalidArgumentException(sprintf(
@@ -48,7 +48,17 @@
}
$this->reader = new AttributeReader();
- $this->addPaths($paths);
+
+ $isArrayOfStrings = static fn (array $items): bool => [] === array_filter(
+ $items,
+ static fn(mixed $item): bool => !is_string($item),
+ );
+
+ if (is_array($paths) && $isArrayOfStrings($paths)) {
+ $this->addPaths($paths); // this will trigger deprecation
+ } else {
+ $this->filesIterator = $paths;
+ }
}Later on, only
It's possible, just as it was before |
|
Pretty sure I understood what you said.
OK, I misspoke, I mean 2 filenames, when previously, strings used to mean directories. There needs to be a way to tell that the strings in the array are filenames, and should be treated as such. |
|
Why should we allow passing the file names? |
|
Well @derrabus 's suggestion is to pass an iterable of files, right? So we should have a constructor that allows to either pass paths (legacy way), or filenames (new way). Whether the filenames are passed with an |
Yes, that's right:
From the docs:
Thus, to use Symfony Finder, it'd be necessary first to From the simplicity standpoint, it's easier to pass an iterable of file names rather than the iterable of files. |
No, you could still write an iterator that calls |
|
All right, what about |
|
Ultimately yes, but I think maybe the deprecations could be contributed later, once the Symfony Bundles (ORM/ODM) have adapted, so that people do not get unfixable deprecations. I imagine that the plan is to have all bundles instantiate a finder, and pass it configuration specified by the user. |
|
I've opened the above PR that implements it. |
|
Closing after revert of file paths #431. This should be implemented using a file paths iterator, like Symfony Finder. |
Hi!
I would like to ask for one more review of the proposed feature.
In this MR I've simplified it all to the minimal, taking into account previous comments about complex regex.
Please, review it, and feel free to ask if there are any questions 🙂 .
Thank you!