Dependency injection & service container
Në shqip: Injektimi i varësive në PHP
ShpjegimiSQ
Në vend që një klasë të krijojë vetë varësitë (new Mailer()), i merr nga konstruktori. „Service container“-i i Laravel-it dhe Symfony-së i krijon dhe i lidh automatikisht (autowiring).
EnglishEN
Instead of a class creating its own dependencies (new Mailer()), it receives them via the constructor. Laravel's and Symfony's “service container” creates and wires them automatically (autowiring).
Si ta mendosh
Si një restorant ku kuzhinieri merr përbërësit nga furnizuesi, në vend që t'i rrisë vetë.
Lexoje në anglisht
Like a restaurant where the chef gets ingredients from a supplier instead of growing them.
Shembull kodiphp
class PorosiService {
public function __construct(private Mailer $mailer) {}
}