`Reflector` disallows handlers with multiple parameters

Aperta Adatta ai principianti
#34 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php, symfony
Ambito
backend

Direzione di ricerca

Leggi src/DI/Utils/Reflector.php intorno alla riga 70 dove viene lanciata LogicalException per handler con più di un parametro. Rimuovi quella condizione per allinearti con il HandleMessageMiddleware di symfony/messenger. Esegui i test della libreria, aggiungendo un test per handler a più parametri se non esiste, per confermare che la restrizione è sparita.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Contributte\Messenger\DI\Utils\Reflector disallows handlers with multiple parameters, even though they are explicitly supported by symfony/messenger itself.

HandleMessageMiddleware can call handler with multiple parameters like Acknowledger, Envelope, stamps themselves or other args passed via HandlerArgumentsStamp
https://github.com/symfony/messenger/blob/8.2/Middleware/HandleMessageMiddleware.php#L176

    private function callHandler(HandlerDescriptor $handlerDescriptor, Envelope $envelope, ?Acknowledger $ack): mixed
    {
        $arguments = [$envelope->getMessage()];
        if (null !== $ack) {
            $arguments[] = $ack;
        }
        if (null !== $handlerArgumentsStamp = $envelope->last(HandlerArgumentsStamp::class)) {
            $arguments = [...$arguments, ...$handlerArgumentsStamp->getAdditionalArguments()];
        }
        foreach ($handlerDescriptor->getStampParameters() as $name => [$class, $allowsNull, $hasDefault, $position]) {
            if (\array_key_exists($position, $arguments) || \array_key_exists($name, $arguments)) {
                continue;
            }
            if (Envelope::class === $class) {
                $arguments[$name] = $envelope;
            } elseif (null !== $stamp = $envelope->last($class)) {
                $arguments[$name] = $stamp;
            } elseif (!$hasDefault) {
                if (!$allowsNull) {
                    throw new LogicException(\sprintf('Handler "%s" requires a "%s" stamp for argument "$%s", but the envelope carries none.', $handlerDescriptor->getName(), $class, $name));
                }
                $arguments[$name] = null;
            }
        }
        $handler = $handlerDescriptor->getHandler();

        return $handler(...$arguments);

these handlers are disallowed in contributte/messenger here https://github.com/contributte/messenger/blob/master/src/DI/Utils/Reflector.php#L70

if ($rcMethod->getNumberOfParameters() !== 1 && !$rc->implementsInterface(BatchHandlerInterface::class)) {
  throw new LogicalException(sprintf('Only one parameter is allowed in "%s::%s()."', $class, $options['method']));
}

I think this condition should be simply removed

Lingua principale
PHP
Stelle
5
Fork
14
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.