Feature: #100071 - Introduce non-magic repository find methods
See forge#100071
Description
Extbase repositories come with a magic __
method to allow calling
the following methods without implementing:
find
By [Property Name] ($property Value) find
One By [Property Name] ($property Value) count
By [Property Name] ($property Value)
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,
saying method find
does not exist. Also, type declarations are
impossible to use because with __
everything is mixed
. And
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:
find
By (array $criteria, ...): Query Result Interface find
One By (array $criteria, ...): object |null count
(array $criteria, ...): int
The naming of those methods follows those of doctrine/
and only
count
differs from the formerly count
. While all magic
methods only allow for a single comparison (property
= property
),
those methods allow for multiple comparisons, called constraints.
Example:
$this->blogRepository->findBy(['author' => 1, 'published' => true]);
Impact
The new methods support a broader feature set, support IDEs, static code analyzers and type declarations.