mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
722f2d178a
commit
4974996cbe
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user