Created
June 20, 2019 10:09
-
-
Save infinitypaul/eec0362e9e149b800d5a092463aec100 to your computer and use it in GitHub Desktop.
Dependency injection using constructor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserRepository | |
{ | |
private $db; | |
private $config; | |
private $users; | |
public function __construct(Database $db, Config $config, User $users) | |
{ | |
$this->db = $db; | |
$this->config = $config; | |
$this->users = $users; | |
} | |
public function allUser(){ | |
foreach ($this->users->all() as $user){ | |
echo $user->name. '\n'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment