Skip to content

Instantly share code, notes, and snippets.

@infinitypaul
Created June 20, 2019 10:09
Show Gist options
  • Save infinitypaul/eec0362e9e149b800d5a092463aec100 to your computer and use it in GitHub Desktop.
Save infinitypaul/eec0362e9e149b800d5a092463aec100 to your computer and use it in GitHub Desktop.
Dependency injection using constructor
<?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