Let's say you have a framework with 2 components which are located in separate folders and namespaces. You want them to be decoupled to a level, that each of them can be used on its own.
The first class provides a certain functionality, like writing message into log files:
<?php
namespace \Sample\Log;
class Logger impements LoggerInterface {
public function log($message) { //Write message into log file } }
The second class also provides a framework functionality, but should also be able to write log messages using the provided class.
namespace \Sample\Config;
class Config
{
protected $logger;
public function setLogger(LoggerInterface $logger)
{
$this->logger=$logger
}
public function loadConfig(){
include('config.php')
$this->logger->log('Config file loaded!');
}
}
Where should the interface be located to allow framework users to only use config class? Should they be in Sample/Interfaces/, Sample/Logger/, Sample/Config/ or somewhere else? All three of the options I provided have certain pros and cons, so I'm not really sure where I should put it.
<?php
interface LoggerInterface
{
public function log($message);
}