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
This commit is contained in:
DorsetDigital 2018-02-26 19:31:44 +00:00 committed by GitHub
parent 722f2d178a
commit 4974996cbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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: