Last active
January 29, 2016 03:04
-
-
Save mchelen/096fadcdfe0f45fabcfb to your computer and use it in GitHub Desktop.
exception handling in constructor demo
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
| vendor | |
| composer.lock | |
| example.log |
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
| { | |
| "name": "example/example", | |
| "description": "an example", | |
| "require": { | |
| "monolog/monolog": "^1.17" | |
| }, | |
| "autoload": { | |
| "psr-4": { | |
| "example\\example\\": "Foo" | |
| } | |
| } | |
| } |
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 | |
| namespace Example; | |
| class Foo { | |
| private $logger; | |
| public function __construct(\Psr\Log\LoggerInterface $logger) { | |
| $this->logger = $logger; | |
| } | |
| public function bar($baz) { | |
| $this->logger->addDebug($baz); | |
| } | |
| } |
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 | |
| require "vendor/autoload.php"; | |
| require "Foo.php"; | |
| use Monolog\Logger; | |
| use Monolog\Handler\StreamHandler; | |
| // create a log channel | |
| $log = new Logger('name'); | |
| $log->pushHandler(new StreamHandler('example.log', Logger::DEBUG)); | |
| $foo = new Foo($log); | |
| $foo->bar("qux"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment