Created
July 12, 2015 15:41
-
-
Save pedrochaves/dbcf8b1aa107a5d16099 to your computer and use it in GitHub Desktop.
Traits logger
This file contains hidden or 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 | |
interface Loggable | |
{ | |
public function log($message, $level); | |
public function setLogger(LoggerInterface $logger); | |
} | |
trait Logger | |
{ | |
private $logger; | |
public function setLogger(LoggerInterface $logger) | |
{ | |
$this->logger = $logger; | |
} | |
public function log($message, $level) | |
{ | |
$this->logger->log($message); | |
} | |
} | |
class Foo implements Loggable | |
{ | |
use Logger; | |
} |
This file contains hidden or 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 | |
interface Loggable | |
{ | |
public function log($message, $level); | |
public function setLogger(LoggerInterface $logger); | |
} | |
class Logger | |
{ | |
private $logger; | |
public function setLogger(LoggerInterface $logger) | |
{ | |
$this->logger = $logger; | |
} | |
public function log($message, $level) | |
{ | |
$this->logger->log($message); | |
} | |
} | |
class Foo extends Logger | |
{ | |
use Logger; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment