Merge branch 'master' of https://git.mcnd.ca/mcndave/the-bugs into dev
This commit is contained in:
commit
689c3203e7
|
@ -1,2 +1,2 @@
|
||||||
composer.lock
|
composer.lock
|
||||||
/vendor/
|
/vendor/
|
||||||
|
|
42
LICENSE
42
LICENSE
|
@ -1,21 +1,21 @@
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2019 Dave Mc Nicoll
|
Copyright (c) 2019 Dave Mc Nicoll
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
# thebugs
|
# thebugs
|
||||||
A PSR-15 compliant library helping to trace errors in development and production environment.
|
A PSR-15 compliant library helping to trace errors in development and production environment.
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
{
|
{
|
||||||
"name": "mcnd/thebugs",
|
"name": "mcnd/thebugs",
|
||||||
"description": "A PSR-15 compliant library helping to trace errors in development and production environment",
|
"description": "A PSR-15 compliant library helping to trace errors in development and production environment",
|
||||||
"keywords" : ["debug","error","bug"],
|
"keywords" : ["debug","error","bug"],
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Dave Mc Nicoll",
|
"name": "Dave Mc Nicoll",
|
||||||
"email": "info@mcnd.ca"
|
"email": "info@mcnd.ca"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {},
|
"require": {},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"TheBugs\\": "src/"
|
"TheBugs\\": "src/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,12 @@ class EmailConfiguration
|
||||||
|
|
||||||
public $smtpUseTLS = false;
|
public $smtpUseTLS = false;
|
||||||
|
|
||||||
|
public $toAddress = "";
|
||||||
|
|
||||||
|
public $fromAddress = "";
|
||||||
|
|
||||||
|
public $fromName = "";
|
||||||
|
|
||||||
public function __construct($type = self::AUTH_TYPE_SMTP)
|
public function __construct($type = self::AUTH_TYPE_SMTP)
|
||||||
{
|
{
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
|
|
@ -2,19 +2,11 @@
|
||||||
|
|
||||||
namespace TheBugs;
|
namespace TheBugs;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseFactoryInterface,
|
use Psr\Http\Message\ResponseInterface,
|
||||||
Psr\Container\ContainerInterface,
|
|
||||||
Psr\Http\Message\ResponseInterface,
|
|
||||||
Psr\Http\Message\ServerRequestInterface,
|
Psr\Http\Message\ServerRequestInterface,
|
||||||
Psr\Http\Server\MiddlewareInterface,
|
Psr\Http\Server\MiddlewareInterface,
|
||||||
Psr\Http\Server\RequestHandlerInterface;
|
Psr\Http\Server\RequestHandlerInterface;
|
||||||
|
|
||||||
use Zend\Diactoros\Response,
|
|
||||||
Zend\Diactoros\ServerRequest,
|
|
||||||
Zend\Diactoros\Stream,
|
|
||||||
Zend\Diactoros\Uri;
|
|
||||||
|
|
||||||
|
|
||||||
class EmailErrorMiddleware implements MiddlewareInterface
|
class EmailErrorMiddleware implements MiddlewareInterface
|
||||||
{
|
{
|
||||||
protected /* EmailConfiguration */ $emailConfiguration;
|
protected /* EmailConfiguration */ $emailConfiguration;
|
||||||
|
@ -35,9 +27,8 @@ class EmailErrorMiddleware implements MiddlewareInterface
|
||||||
$response = $handler->handle($request);
|
$response = $handler->handle($request);
|
||||||
|
|
||||||
if ( $response->getStatusCode() === 500 ) {
|
if ( $response->getStatusCode() === 500 ) {
|
||||||
|
$this->mailer->setTo($this->emailConfiguration->toAddress);
|
||||||
$this->mailer->setTo('dave.mcnicoll@cslsj.qc.ca');
|
$this->mailer->setFrom([$this->emailConfiguration->fromAddress => $this->emailConfiguration->fromName]);
|
||||||
$this->mailer->setFrom(['test@johndoe.com' => 'John Doe']);
|
|
||||||
|
|
||||||
$bugReport = $response->getBody()->__toString();
|
$bugReport = $response->getBody()->__toString();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TheBugs;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseFactoryInterface,
|
||||||
|
Psr\Container\ContainerInterface,
|
||||||
|
Psr\Http\Message\ResponseInterface,
|
||||||
|
Psr\Http\Message\ServerRequestInterface,
|
||||||
|
Psr\Http\Server\MiddlewareInterface,
|
||||||
|
Psr\Http\Server\RequestHandlerInterface;
|
||||||
|
|
||||||
|
use Monolog\Logger;
|
||||||
|
use Monolog\Formatter\HtmlFormatter;
|
||||||
|
use Monolog\Processor\WebProcessor,
|
||||||
|
Monolog\Processor\MemoryUsageProcessor,
|
||||||
|
Monolog\Processor\IntrospectionProcessor;
|
||||||
|
|
||||||
|
use MonologPHPMailer\PHPMailerHandler;
|
||||||
|
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
|
||||||
|
class EmailMiddleware implements MiddlewareInterface
|
||||||
|
{
|
||||||
|
const DEFAULT_FROM_NAME = "Bug Email Reporter";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHPMailer object
|
||||||
|
* @var PHPMailer
|
||||||
|
*/
|
||||||
|
protected $phpmailer = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Monolog object
|
||||||
|
* @var Logger object
|
||||||
|
*/
|
||||||
|
protected $logger = null;
|
||||||
|
|
||||||
|
public function __construct(array $mail, array $options = [], PHPMailer $mailer = null, Logger $logger = null)
|
||||||
|
{
|
||||||
|
$this->mailer = $mailer ?: new PHPMailer(true);
|
||||||
|
$this->logger = $logger ?: new Logger('default');
|
||||||
|
$this->handler = new PHPMailerHandler($this->mailer);
|
||||||
|
|
||||||
|
$this->mailer->isSMTP();
|
||||||
|
$this->mailer->Host = $mail['host'];
|
||||||
|
$this->mailer->SMTPAuth = $mail['smtp_auth'] ?? true;
|
||||||
|
$this->mailer->Username = $mail['username'];
|
||||||
|
$this->mailer->Password = $mail['password'];
|
||||||
|
|
||||||
|
$this->mailer->setFrom($mail['from_address'], $mail['from_name'] ?? static::DEFAULT_FROM_NAME);
|
||||||
|
|
||||||
|
foreach($this->adjustAddress($mail['to'] ?? []) as $item) {
|
||||||
|
$this->mailer->addAddress($item['address'], $item['name'] ?? "");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($this->adjustAddress($mail['cc'] ?? []) as $item) {
|
||||||
|
$this->mailer->addCC($item['address'], $item['name'] ?? "");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($this->adjustAddress($mail['bcc'] ?? []) as $item) {
|
||||||
|
$this->mailer->addBCC($item['address'], $item['name'] ?? "");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->handler->setFormatter(new HtmlFormatter);
|
||||||
|
$this->logger->pushHandler($this->handler);
|
||||||
|
|
||||||
|
$this->logger->pushProcessor(new IntrospectionProcessor);
|
||||||
|
$this->logger->pushProcessor(new MemoryUsageProcessor);
|
||||||
|
$this->logger->pushProcessor(new WebProcessor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||||
|
{
|
||||||
|
return $handler->handle($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function adjustAddress($address) {
|
||||||
|
return is_string($address) ? [ [ 'address' => $address ] ] : $address;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,26 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace TheBugs\Exception;
|
namespace TheBugs\Exception;
|
||||||
|
|
||||||
class JavascriptException extends \Exception {
|
class JavascriptException extends \Exception {
|
||||||
|
|
||||||
protected $url;
|
protected $url;
|
||||||
|
|
||||||
protected $stacktrace;
|
protected $stacktrace;
|
||||||
|
|
||||||
public function __construct(string $message, int $code, Exception $previous = null, string $file, int $line, string $url, array $trace)
|
public function __construct(string $message, int $code, Exception $previous = null, string $file, int $line, string $url, array $trace)
|
||||||
{
|
{
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
$this->code = $code;
|
$this->code = $code;
|
||||||
$this->previous = $previous;
|
$this->previous = $previous;
|
||||||
$this->file = $file;
|
$this->file = $file;
|
||||||
$this->line = $line;
|
$this->line = $line;
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
$this->stacktrace = $trace;
|
$this->stacktrace = $trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString() {
|
public function __toString() {
|
||||||
return __CLASS__ . ": [{$this->url}:{$this->code}]: {$this->message}\n" . json_encode($this->stacktrace);
|
return __CLASS__ . ": [{$this->url}:{$this->code}]: {$this->message}\n" . json_encode($this->stacktrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue