- Small WIP of template and adjusted the composer.json allowing registration into the autoload
This commit is contained in:
parent
db8bf36cf7
commit
ec873145d2
|
@ -10,5 +10,10 @@
|
||||||
"email": "info@mcnd.ca"
|
"email": "info@mcnd.ca"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {}
|
"require": {},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"TheBugs\\": "src/"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,12 @@ class JavascriptMiddleware implements MiddlewareInterface
|
||||||
"headers" => [
|
"headers" => [
|
||||||
"User-Agent" => "TheBugs/1.0",
|
"User-Agent" => "TheBugs/1.0",
|
||||||
],
|
],
|
||||||
|
# Callable functions
|
||||||
|
"functions" => []
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter list, allows custom invokable
|
* Filter list, allows custom invokable too
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $filters = [];
|
protected $filters = [];
|
||||||
|
@ -56,6 +58,12 @@ class JavascriptMiddleware implements MiddlewareInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach($this->filters['functions'] as $func) {
|
||||||
|
if ( $func->bindTo($this, $this)() ) {
|
||||||
|
return $handler->handle($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->throwError(json_decode($request->getBody(), true));
|
$this->throwError(json_decode($request->getBody(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
<script>
|
||||||
|
(function(send) {
|
||||||
|
XMLHttpRequest.prototype.send = function(data) {
|
||||||
|
console.log("Hey ! Something was sent !");
|
||||||
|
send.call(this, data);
|
||||||
|
};
|
||||||
|
})(XMLHttpRequest.prototype.send);
|
||||||
|
|
||||||
|
class ErrorHandler
|
||||||
|
{
|
||||||
|
constructor(options) {
|
||||||
|
if ( options ) {
|
||||||
|
if ( "url" in options ) {
|
||||||
|
this.url = options['url'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.catchError();
|
||||||
|
}
|
||||||
|
|
||||||
|
catchError() {
|
||||||
|
window.onerror = function(message, url, line, column, error) {
|
||||||
|
fetch(this.url ? this.url : window.location.href, {
|
||||||
|
method: "post",
|
||||||
|
headers: {
|
||||||
|
'Accept': "application/json",
|
||||||
|
'Content-Type': "application/json",
|
||||||
|
'User-Agent': "TheBugs/1.0"
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
'message': message,
|
||||||
|
'url': url,
|
||||||
|
'line': line,
|
||||||
|
'column': column,
|
||||||
|
'stack': error.stack,
|
||||||
|
'location': window.location.toString()
|
||||||
|
})
|
||||||
|
}).then( response => response ).then(data => {
|
||||||
|
console.info("Error reported", data);
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
get url() {
|
||||||
|
return this._url;
|
||||||
|
}
|
||||||
|
|
||||||
|
set url(set) {
|
||||||
|
return this._url = set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
Loading…
Reference in New Issue