mongodb-odm icon indicating copy to clipboard operation
mongodb-odm copied to clipboard

Refactor handling of BSON filters

Open alcaeus opened this issue 5 years ago • 0 comments

Feature Request

Q A
New Feature yes
RFC yes
BC Break not yet

Summary

The Configuration::addFilter method currently only allows adding a filter by specifying its name, class and optional parameters. When needed, those filters are instantiated by the FilterCollection according to the configuration. There are several issues with this approach:

  • The base class for filters specifies a final constructor that takes a DocumentManager instance. This makes it impossible to create more complex filters that might rely on other objects to do their work
  • Due to FilterCollection instantiating the filters itself, they cannot be configured as services in the Symfony Bundle (see https://github.com/doctrine/DoctrineMongoDBBundle/issues/547). Similar to that, using dependency injection to inject other services is impossible due to the constructor as mentioned above.

To alleviate these pains, the filter handling should be changed completely to allow more flexibility:

  • Instead of providing an abstract class with a final constructor, we should provide an interface that must be implemented by each filter
  • The addFilterCriteria should not only receive a ClassMetadata instance but also the document manager in use. This allows reusing a filter instance for multiple document managers
  • The addFilter method in Configuration needs to be extended to allow adding a filter instance to the configuration instead of just its class name. FilterCollection must be added accordingly.

The old way of adding filters should be deprecated and dropped in 3.0. Until then, both ways of adding filters will be supported.

alcaeus avatar Mar 29 '19 06:03 alcaeus