Feature: #100071 - Introduce non-magic repository find methods¶
Extbase repositories come with a magic
__call() method to allow calling
the following methods without implementing:
Magic methods are quite handy but they have a huge disadvantage. There is no
proper IDE support i.e. most IDEs show an error or at least a warning,
findByAuthor() does not exist. Also, type declarations are
impossible to use because with
__call() everything is
last but not least, static code analysis - like PHPStan - cannot properly
analyze those and give meaningful errors.
Therefore, there is a new set of methods without all those downsides:
findBy(array $criteria, ...): QueryResultInterface
findOneBy(array $criteria, ...): object|null
count(array $criteria, ...): int
The naming of those methods follows those of
doctrine/orm and only
count() differs from the formerly
countBy(). While all magic
methods only allow for a single comparison (
those methods allow for multiple comparisons, called constraints.
$this->blogRepository->findBy(['author' => 1, 'published' => true]);
The new methods support a broader feature set, support IDEs, static code analyzers and type declarations.