-
Notifications
You must be signed in to change notification settings - Fork 232
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
Dependency Injection and ODM Filter #547
Comments
This makes sense, however given latest trends I think we should either allow pointing to a service or somehow discover the filters and autoconfigure them. The first option seems to be easier and leaves the door opened for the 2nd one so I think it might be better. So instead of injecting services manually like in the bundle you've linked we could leverage autowiring and start with
aiming to have simpler construct in the future for enabled filters.
This however would require reworking a bit filters to accept instance of a filter instead of class name. Having said that, injecting services as parameters might be easier for first step, a PR will be appreciated! |
I'm agree with you. However I analysed the code of public function enable(string $name) : BsonFilter
{
if (! $this->has($name)) {
throw new InvalidArgumentException("Filter '" . $name . "' does not exist.");
}
if (! $this->isEnabled($name)) {
$filterClass = $this->config->getFilterClassName($name);
$filterParameters = $this->config->getFilterParameters($name);
**$filter = new $filterClass($this->dm);**
foreach ($filterParameters as $param => $value) {
$filter->setParameter($param, $value);
}
$this->enabledFilters[$name] = $filter;
}
return $this->enabledFilters[$name];
} |
Yeah, I realized that by the time I was finishing my comment :)
|
I've created doctrine/mongodb-odm#1986 to track the refactoring of the filter logic to allow better configuration. Once this has been implemented in ODM we can then talk about using auto configuration and tags on services to tie filters to document managers 👍 |
Hello,
Did you plan to add the possibility to inject services in filters?
In fact, actually we can only inject static parameters.
This bundle MongodbOdmFiltersBundle add this functionnality.
The text was updated successfully, but these errors were encountered: