From 578e6687e8e029b3fce85c27031f165c8d4ef773 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Wed, 4 Aug 2021 09:46:42 +0200 Subject: [PATCH 1/2] - Add MailjetSms.php --- app/Lib/LDC/MailjetSms.php | 70 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 app/Lib/LDC/MailjetSms.php diff --git a/app/Lib/LDC/MailjetSms.php b/app/Lib/LDC/MailjetSms.php new file mode 100644 index 0000000..114159d --- /dev/null +++ b/app/Lib/LDC/MailjetSms.php @@ -0,0 +1,70 @@ +app = $app; + $this->loadDefaultOptions(); + } + + protected function loadDefaultOptions(): MailjetSms + { + $this->config = $this->app['config']->get('services.mailjet'); + return $this; + } + + protected function buildHttpClient(): Client + { + return new Client([ + 'allow_redirects' => false, + 'connect_timeout' => 3, + 'verify' => false, + 'headers' => [ + 'User-Agent' => 'LDCMailjetSms/1.0', + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + 'Authorization' => sprintf('Bearer %s', $this->config['sms_token']), + ], + 'timeout' => 5, + ]); + } + + public function send(string $message, string $to, $from = null): ResponseInterface + { + $from = $from ?? $this->config['sms_from']; + $client = $this->buildHttpClient(); + + try { + $response = $client->post($this->config['sms_endpoint'], [ + 'json' => [ + 'Text' => $message, + 'From' => $from, + 'To' => $to, + ] + ]); + } catch (\GuzzleHttp\Exception\RequestException $ex) { + Log::debug('error ' . $ex->getMessage()); + if (!is_null($ex->getResponse())){ + Log::debug((string) $ex->getResponse()->getBody()); + } + throw $ex; + } + + + + return $response; + } +} From 22ebf3c2c584a86d58f98d68cf09ebdd6994c79f Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Wed, 4 Aug 2021 09:48:00 +0200 Subject: [PATCH 2/2] - Add emails/exception.blade.php --- resources/views/emails/exception.blade.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 resources/views/emails/exception.blade.php diff --git a/resources/views/emails/exception.blade.php b/resources/views/emails/exception.blade.php new file mode 100644 index 0000000..e69347a --- /dev/null +++ b/resources/views/emails/exception.blade.php @@ -0,0 +1,17 @@ + + + + Le Gaulois Exception Handler + + + +

Une erreur est survenue sur le site Le Gaulois

+

{{ $exception->getMessage() }}

+

url : {{ $url ?? 'none' }}

+

date : {{ date('Y-m-d H:i:s') }}

+

code : {{$exception->getCode() }}

+

file : {{$exception->getFile() }}

+

line : {{$exception->getLine() }}

+

Veuillez vérifier les logs pour en voir la trace.

+ +