Skip to main content

Posts

Showing posts from 2019

Dependency Injection

Dependency injection is a programming technique that makes a class independent of its dependencies. It achieves that by decoupling the usage of an object from its creation. Example Setup/Dependency: composer require symfony/dependency-injection composer require symfony/yaml composer require symfony/config Create folder "src" Add entry in composer.json "autoload":{"psr-4"{"DI\\": "src/"} and then run composer dump-autoload -o File: /Src/Mail.php <?php namespace DI; class Mail{     private $cc;     function __construct($fromname,$fromemail)     {         $this->fromname = $fromname;         $this->fromemail = $fromemail;     }     function sendMail($to,$subject,$message)     {          $headers = "MIME-Version: 1.0" . "\r\n";          $headers ....