Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save syofyanzuhad/ce44ff8beb46bd3b1a4fa9b09b8f2e40 to your computer and use it in GitHub Desktop.
Save syofyanzuhad/ce44ff8beb46bd3b1a4fa9b09b8f2e40 to your computer and use it in GitHub Desktop.
<?php
interface Logger
{
public function execute($message);
}
class LogToDatabase implements Logger
{
public function execute($message){
var_dump('log the message to a database :'.$message);
}
}
class LogToFile implements Logger
{
public function execute($message)
{
var_dump('log the message to a file :'.$message);
}
}
class UsersController
{
protected $logger;
public function __construct(Logger $logger)
{
$this->logger = $logger;
}
public function show()
{
$user = 'nahid';
$this->logger->execute($user);
}
}
$controller = new UsersController(new LogToDatabase);
$controller->show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment