1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PiouPiou\RibsAdminBundle\EventListener; |
4
|
|
|
|
5
|
|
|
use PiouPiou\RibsAdminBundle\Entity\User; |
6
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
7
|
|
|
use Symfony\Component\HttpKernel\Event\ExceptionEvent; |
8
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
9
|
|
|
|
10
|
|
|
class ExceptionListener |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var ParameterBagInterface |
14
|
|
|
*/ |
15
|
|
|
private $paramter; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var User |
19
|
|
|
*/ |
20
|
|
|
private $user; |
21
|
|
|
|
22
|
|
|
public function __construct(ParameterBagInterface $parameterBag, TokenStorageInterface $tokenStorage) |
23
|
|
|
{ |
24
|
|
|
$this->paramter = $parameterBag; |
25
|
|
|
if ($tokenStorage->getToken() && is_object($tokenStorage->getToken()->getUser()) && $tokenStorage->getToken()->getUser()->getUser()) { |
|
|
|
|
26
|
|
|
$this->user = $tokenStorage->getToken()->getUser()->getUser(); |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function onKernelException(ExceptionEvent $event) |
31
|
|
|
{ |
32
|
|
|
$slack_webhook = $this->paramter->get('ribs_admin.slack_webhook'); |
33
|
|
|
if ($slack_webhook) { |
34
|
|
|
$data = array(); |
35
|
|
|
$data['channel'] = '#errors'; |
36
|
|
|
$data['username'] = $_SERVER['HTTP_HOST']; |
37
|
|
|
$data['text'] = "• *Erreur* : " . strip_tags($event->getThrowable()->getMessage()); |
38
|
|
|
$data['text'] .= "\n• *Erreur File* : " . strip_tags($event->getThrowable()->getFile()) . " at line :" . strip_tags($event->getThrowable()->getLine()); |
39
|
|
|
$data['text'] .= "\n• *URL* : " . $event->getRequest()->getUri(); |
40
|
|
|
|
41
|
|
|
if ($this->user) { |
42
|
|
|
$data['text'] .= "\n• *Utilisateur* : " . $this->user . " with id : " . $this->user->getId(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$data['unfurl_links'] = false; |
46
|
|
|
$data_json = json_encode($data); |
47
|
|
|
|
48
|
|
|
$ch = curl_init(); |
49
|
|
|
curl_setopt($ch, CURLOPT_URL, $slack_webhook); |
|
|
|
|
50
|
|
|
curl_setopt($ch, CURLOPT_POST, 1); |
51
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_json))); |
52
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json); |
53
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
54
|
|
|
curl_exec($ch); |
|
|
|
|
55
|
|
|
curl_close($ch); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.