Autowiring: resolve union and intersection parameter types in DiContainer
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 68/100
Direção de pesquisa
Start by reading resolveParameter() in src/Di/DiContainer.php and note where it only handles ReflectionNamedType; also read autowire() since it shares that path. Add the new named constructor and message template in src/Di/Enums/ExceptionMessages.php, then write failing cases in tests/Unit/Di/ for each scenario listed in Acceptance. Done means those tests pass, ambiguous unions are not guessed, unsatisfied intersections are rejected, and CHANGELOG.md records the behavior change.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Problem
Quantum\Di\DiContainer::resolveParameter() reads a parameter type only when it is a ReflectionNamedType. For a union (A|B) or an intersection (Reader&Writer) type the type is ignored, so the parameter falls through to the passed arguments, then the default value, then null.
Result (checked on PHP 8.1):
public function __construct(A|B $dep)fails with aTypeErrorthat gives no hint about the container.public function __construct(A|B|null $dep)silently receivesnull, even whenAis registered in the container.Reader&Writeris never resolved, even when an implementing class is registered.
Proposal
Resolve a union or intersection parameter only when the choice is unambiguous. Never guess from the declaration order and never pass null silently.
- Union: drop
nulland builtin members. If exactly one remaining member can be resolved (it is registered in the container, or it is an instantiable class), use it. If several can, do not pick one. - Intersection: use a registered or instantiable member and check that the result satisfies every part of the type (
instanceoffor each). A result that does not satisfy all parts is not used. - Otherwise: keep the existing order (passed argument, default value). If neither exists, throw a
DiExceptionwith a clear message (new named constructor and message template insrc/Di/Enums/ExceptionMessages.php) that names the class, the parameter and the type, instead of aTypeErroror a silentnull. - The same rules apply to
autowire()of a closure, which sharesresolveParameter().
Why not the order of declaration
Other containers differ: one rejects union types (Marko, a clear exception), one tries members in declaration order (Tempest, which also does not check that an intersection is satisfied as a whole), one tries each branch and verifies it (Canvas). Declaration order makes A|B and B|A behave differently, so it is not used here.
Acceptance
- Tests in
tests/Unit/Di/for: union with one registered member, union with none, union with several resolvable members,A|B|nullwith and without a default, intersection with a registered implementation that satisfies all parts, intersection that does not, closure autowiring. CHANGELOG.mdentry. A parameter that failed before with aTypeErrornow resolves or throws aDiException; the exception type changes, so it is noted as a behavior change.
Milestone 3.2.0 (a different exception type on a path that used to throw TypeError).
- Linguagem predominante
- PHP
- Estrelas
- 43
- Forks
- 22
- Merge médio
- 54min
- PRs com merge (30d)
- 57
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de quantum-php/framework
-
bug good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
quantum-php/framework#692 ·
Mantenedores costumam responder em até 1 dia
-
routing testing
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
quantum-php/framework#547 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
quantum-php/framework#694 ·
Mantenedores costumam responder em até 1 dia
-
Raise PHPStan to level 9Abertarefactoring tech debt
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 20/100
quantum-php/framework#693 ·
Mantenedores costumam responder em até 1 dia
-
install:debugbar reads the package folder from the working directory and uses the default storage adapterTalvez já em andamento @armanist assumiu hoje. Abertabug console debugbar good first issue
quantum-php/framework#691 · 1 responsável ·
Mantenedores costumam responder em até 1 dia
Todas as issues de quantum-php/framework
Issues semelhantes
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 70/100
ajeetraina/awesome-docker-sbx#559 ·
-
dependencies enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
novalo-dev/Prestashop-MCP-Server#329 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 80/100
Mantenedores costumam responder em até 1 dia
-
bug origin:interactive status:available
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
Ultimate-Multisite/ultimate-multisite#2131 ·
Mantenedores costumam responder em até 1 dia
-
sync-en
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia