aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2020-04-28 20:42:25 +0200
committern-peugnet <n.peugnet@free.fr>2020-04-28 20:42:44 +0200
commit3ba521e5d60a05510aa97d826215b7660d3dcb59 (patch)
treef843fd180032c8b10917e32b6cf790574c3f2185
parent9090550d241f9f7b3246b24bfd323bd988add749 (diff)
downloadwcms-3ba521e5d60a05510aa97d826215b7660d3dcb59.tar.gz
wcms-3ba521e5d60a05510aa97d826215b7660d3dcb59.zip
chore: add whoops for a better dev environment
-rw-r--r--README.md11
-rw-r--r--app/class/Config.php16
-rw-r--r--composer.json1
-rw-r--r--composer.lock110
-rw-r--r--index.php21
5 files changed, 147 insertions, 12 deletions
diff --git a/README.md b/README.md
index 0bb744f..58de3b7 100644
--- a/README.md
+++ b/README.md
@@ -58,10 +58,10 @@ There is lot more you can by altering the `BODY`.
-Devellopement team
+Development team
------------------
-W is a project created and maintained by [Vincent Peugnet](https://github.com/vincent-peugnet), an amateur computer science enthousiast who can only code in PHP. It now includes [Nicolas Peugnet](https://github.com/n-peugnet) (his brother) as JS develloper, technical advisor and every challenges that are too complicated for Vincent.
+W is a project created and maintained by [Vincent Peugnet](https://github.com/vincent-peugnet), an amateur computer science enthousiast who can only code in PHP. It now includes [Nicolas Peugnet](https://github.com/n-peugnet) (his brother) as JS developer, technical advisor and every challenges that are too complicated for Vincent.
We can also mention [Guilhem Prévost Leygonie]() as legendary number one user and now as an issue writer too.
@@ -133,10 +133,15 @@ There are 3 different build environments that `make` can use:
The build environment can be set either for each `make` command by changing it in the `.env` file or on a per command basis by adding it at the end of the command (e.g. `make build ENV=prod`).
+PHP development
+---------------
+
+There is an error reporting debug mode using [Whoops](https://github.com/filp/whoops). It can be enabled by setting the value of `debug` in `config.json` to one of [editors supported by Whoops](https://github.com/filp/whoops/blob/master/docs/Open%20Files%20In%20An%20Editor.md).
+
JS development
--------------
-While developing the JS sources it is useful to run webpack in watch mode so that the bundles get built at each file change. To do so, use the following command:
+While developing JS code it is useful to run webpack in watch mode so that the bundles get built at each file change. To do so, use the following command:
make watch
diff --git a/app/class/Config.php b/app/class/Config.php
index 37321e4..c7d1a78 100644
--- a/app/class/Config.php
+++ b/app/class/Config.php
@@ -2,8 +2,6 @@
namespace Wcms;
-use Http\Client\Common\Plugin\RetryPlugin;
-
abstract class Config
{
protected static $pagetable = 'mystore';
@@ -35,6 +33,8 @@ abstract class Config
protected static $bookmark = [];
protected static $secretkey = null;
protected static $sentrydsn = '';
+ /** @var string|false $debug */
+ protected static $debug = false;
public const SECRET_KEY_MIN = 16;
public const SECRET_KEY_MAX = 128;
@@ -271,6 +271,11 @@ abstract class Config
return self::$sentrydsn;
}
+ public static function debug()
+ {
+ return self::$debug;
+ }
+
// __________________________________________ S E T ______________________________________
@@ -469,6 +474,13 @@ abstract class Config
}
}
+ public static function setdebug($debug)
+ {
+ if (is_string($debug)) {
+ self::$debug = $debug;
+ }
+ }
+
diff --git a/composer.json b/composer.json
index 072f4e2..95a2d94 100644
--- a/composer.json
+++ b/composer.json
@@ -9,6 +9,7 @@
"michelf/php-markdown": "^1.8"
},
"require-dev": {
+ "filp/whoops": "^2.7",
"pepakriz/phpstan-exception-rules": "^0.10.1",
"phpstan/phpstan": "^0.12.19",
"phpstan/phpstan-phpunit": "^0.12.8",
diff --git a/composer.lock b/composer.lock
index ffc81ad..5606478 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "content-hash": "fa8ab175273737ddd7b8aed0ce7bc82f",
+ "content-hash": "6da5a2cb510d9953dfe07df3411f9cd9",
"packages": [
{
"name": "altorouter/altorouter",
@@ -332,6 +332,67 @@
"time": "2019-10-21T16:45:58+00:00"
},
{
+ "name": "filp/whoops",
+ "version": "2.7.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/filp/whoops.git",
+ "reference": "fff6f1e4f36be0e0d0b84d66b413d9dcb0c49130"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/filp/whoops/zipball/fff6f1e4f36be0e0d0b84d66b413d9dcb0c49130",
+ "reference": "fff6f1e4f36be0e0d0b84d66b413d9dcb0c49130",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^5.5.9 || ^7.0",
+ "psr/log": "^1.0.1"
+ },
+ "require-dev": {
+ "mockery/mockery": "^0.9 || ^1.0",
+ "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0",
+ "symfony/var-dumper": "^2.6 || ^3.0 || ^4.0 || ^5.0"
+ },
+ "suggest": {
+ "symfony/var-dumper": "Pretty print complex values better with var-dumper available",
+ "whoops/soap": "Formats errors as SOAP responses"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.6-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Whoops\\": "src/Whoops/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Filipe Dobreira",
+ "homepage": "https://github.com/filp",
+ "role": "Developer"
+ }
+ ],
+ "description": "php error handling for cool kids",
+ "homepage": "https://filp.github.io/whoops/",
+ "keywords": [
+ "error",
+ "exception",
+ "handling",
+ "library",
+ "throwable",
+ "whoops"
+ ],
+ "time": "2020-01-15T10:00:00+00:00"
+ },
+ {
"name": "guzzlehttp/promises",
"version": "v1.3.1",
"source": {
@@ -2076,6 +2137,53 @@
"time": "2016-08-06T14:39:51+00:00"
},
{
+ "name": "psr/log",
+ "version": "1.1.3",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/php-fig/log.git",
+ "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc",
+ "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.1.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Psr\\Log\\": "Psr/Log/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "PHP-FIG",
+ "homepage": "http://www.php-fig.org/"
+ }
+ ],
+ "description": "Common interface for logging libraries",
+ "homepage": "https://github.com/php-fig/log",
+ "keywords": [
+ "log",
+ "psr",
+ "psr-3"
+ ],
+ "time": "2020-03-23T09:12:05+00:00"
+ },
+ {
"name": "ralouphie/getallheaders",
"version": "3.0.3",
"source": {
diff --git a/index.php b/index.php
index 154d947..f4e3321 100644
--- a/index.php
+++ b/index.php
@@ -1,14 +1,12 @@
<?php
-use Wcms\Logger;
-
session_start();
require('./vendor/autoload.php');
try {
- Logger::init('w_error.log', 2);
+ Wcms\Logger::init('w_error.log', 2);
} catch (Throwable $e) {
die('Unable to init logs: ' . $e->getMessage());
}
@@ -16,6 +14,14 @@ try {
$app = new Wcms\Application();
$app->wakeup();
+if (class_exists('Whoops\Run') && !empty(Wcms\Config::debug())) {
+ $whoops = new \Whoops\Run();
+ $handler = new \Whoops\Handler\PrettyPageHandler();
+ $handler->setEditor(\Wcms\Config::debug());
+ $whoops->pushHandler($handler);
+ $whoops->register();
+}
+
if (isreportingerrors()) {
Sentry\init([
'dsn' => Wcms\Config::sentrydsn(),
@@ -33,11 +39,14 @@ if (isreportingerrors()) {
try {
$matchoper = new Wcms\Routes();
$matchoper->match();
-} catch (Exception $e) {
+} catch (Throwable $e) {
if (isreportingerrors()) {
Sentry\captureException($e);
}
- Logger::errorex($e, true);
+ Wcms\Logger::errorex($e, true);
http_response_code(500);
- echo '<h1>⚠ Woops ! There is a little problem : </h1>', $e->getMessage(), "\n";
+ if (isset($whoops)) {
+ $whoops->handleException($e);
+ }
+ echo '<h1>⚠ Whoops ! There is a little problem : </h1>', $e->getMessage(), "\n";
}