Skip to content

Make MediaQuery parameter injection explicit with #[Inject] #106

@koriym

Description

@koriym

Problem

Ray.MediaQuery currently supports parameter injection for omitted optional object parameters.

#[DbQuery('todo_add')]
public function add(string $title, ?Uuid $id = null): void;

When called as:

$repository->add('Buy milk');

$id is resolved from DI.

This is convenient, but the method signature does not clearly communicate whether $id is intended to be:

  • a SQL bind parameter supplied by the caller, or
  • a DI-injected parameter supplied by MediaQuery.

Proposal

Support an explicit injection marker for MediaQuery parameters:

#[DbQuery('todo_add')]
public function add(
    string $title,
    #[Inject] ?Uuid $id = null
): void;

#[Inject] would document that the parameter is intentionally resolved from DI when omitted.

Backward compatibility

This does not need to be a breaking change initially.

Suggested migration path:

  1. Add support for #[Inject].
  2. Continue supporting current implicit injection behavior.
  3. Emit a notice / deprecation notice / logger warning when MediaQuery performs implicit DI for an omitted object parameter without #[Inject].
  4. In a future major version, consider requiring #[Inject] for injected parameters.

Motivation

This makes MediaQuery interfaces more self-documenting and avoids ambiguity between SQL input parameters and DI-provided parameters.

It also helps IDEs, static analysis, and code generators understand which parameters are caller-supplied and which are injected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions