Skip to content

Support multiple arguments in finders #12784

@robertpustulka

Description

@robertpustulka

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 4.0.0

Currently finders support the following API: find($name, array $options = []) which translates to findName(Query $query, array $options).

While it provides a nice way of configuring finder options it forces you to manually check and validate each option if you accept specific classes or types of options.

I was thinking that maybe we could allow anything to be passed to the finder and make PHP validate arguments with type hinting.

For example finder declared as findSomething(Query $q, Entity $e, int $number) could be called like find('something', $entity, 5).

I think that could be achieved painlessly with variadic arguments (... syntax). Table::find($type = 'all', $options = []) can be changed into Table::find($type = 'all', ... $args). It would still accept array as a second argument and pass it correctly to the finder method.

What do you think? Should it be as easy as it looks or maybe I'm missing something?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions