Skip to content

Instantly share code, notes, and snippets.

@nahidulhasan
Last active September 27, 2021 14:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nahidulhasan/bed8396c5b8c82e6da30a23a7b7b3901 to your computer and use it in GitHub Desktop.
Save nahidulhasan/bed8396c5b8c82e6da30a23a7b7b3901 to your computer and use it in GitHub Desktop.
<?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