Last active
September 27, 2021 14:30
-
-
Save nahidulhasan/bed8396c5b8c82e6da30a23a7b7b3901 to your computer and use it in GitHub Desktop.
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 LogToDatabase | |
{ | |
public function execute($message) | |
{ | |
var_dump('log the message to a database :'.$message); | |
} | |
} | |
class LogToFile | |
{ | |
public function execute($message) | |
{ | |
var_dump('log the message to a file :'.$message); | |
} | |
} | |
class UsersController | |
{ | |
protected $logger; | |
public function __construct(LogToFile $logger) | |
{ | |
$this->logger = $logger; | |
} | |
public function show() | |
{ | |
$user = 'nahid'; | |
$this->logger->execute($user); | |
} | |
} | |
$controller = new UsersController(new LogToFile); | |
$controller->show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment