From 4974996cbeb401d251124bd480cbea893bbecc43 Mon Sep 17 00:00:00 2001 From: DorsetDigital Date: Mon, 26 Feb 2018 19:31:44 +0000 Subject: [PATCH] Update 01_Error_Handling.md Add use statements in initial code sample for completeness and hopefully avoid errors when code is copy & pasted Add a 'be' to dependency injection paragraph so it reads properly --- docs/en/02_Developer_Guides/07_Debugging/01_Error_Handling.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/en/02_Developer_Guides/07_Debugging/01_Error_Handling.md b/docs/en/02_Developer_Guides/07_Debugging/01_Error_Handling.md index 64fcc3fb8..a2b87ab6c 100644 --- a/docs/en/02_Developer_Guides/07_Debugging/01_Error_Handling.md +++ b/docs/en/02_Developer_Guides/07_Debugging/01_Error_Handling.md @@ -15,6 +15,8 @@ can be accessed via the `Injector`: ```php use SilverStripe\Core\Injector\Injector; +use Psr\Log\LoggerInterface; +use SilverStripe\Security\Security; Injector::inst()->get(LoggerInterface::class)->info('User has logged in: ID #' . Security::getCurrentUser()->ID); Injector::inst()->get(LoggerInterface::class)->debug('Query executed: ' . $sql); @@ -55,7 +57,7 @@ throw new \LogicException("Query failed: " . $sql); ### Accessing the logger via dependency injection. -It can quite verbose to call `Injector::inst()->get(LoggerInterface::class)` all the time. More importantly, +It can be quite verbose to call `Injector::inst()->get(LoggerInterface::class)` all the time. More importantly, it also means that you're coupling your code to global state, which is a bad design practise. A better approach is to use depedency injection to pass the logger in for you. The [Injector](../extending/Injector) can help with this. The most straightforward is to specify a `dependencies` config setting, like this: