From 8eeba650f46394e5a31cce8cbc8074e5998dc718 Mon Sep 17 00:00:00 2001 From: bantya <16685565+bantya@users.noreply.github.com> Date: Sat, 5 Oct 2019 22:05:34 +0530 Subject: [PATCH] Implemented error handler --- composer.json | 5 +- composer.lock | 143 +++++++++++++++++++++++++++++++++++++++++++------- index.php | 60 ++++++++++++--------- 3 files changed, 163 insertions(+), 45 deletions(-) diff --git a/composer.json b/composer.json index 58cac26..16e6eaf 100755 --- a/composer.json +++ b/composer.json @@ -4,9 +4,10 @@ "illuminate/database": "^5.4", "illuminate/events": "^5.4", "phpmailer/phpmailer": "^5.2", - "spipu/html2pdf": "^5.0" + "spipu/html2pdf": "^5.0", + "filp/whoops": "^2.5" }, "config": { "secure-http": false - } + } } diff --git a/composer.lock b/composer.lock index 030da06..4f41c6b 100755 --- a/composer.lock +++ b/composer.lock @@ -1,11 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "hash": "80a518d3a2cd8e9963bbe3033cf7baef", - "content-hash": "d918653a298f1df70d14a53a20cf25c7", + "content-hash": "20d3451b7373a6b3ed895213ea679048", "packages": [ { "name": "doctrine/inflector", @@ -72,7 +71,68 @@ "singularize", "string" ], - "time": "2017-07-22 12:18:28" + "time": "2017-07-22T12:18:28+00:00" + }, + { + "name": "filp/whoops", + "version": "2.5.0", + "source": { + "type": "git", + "url": "https://github.com/filp/whoops.git", + "reference": "cde50e6720a39fdacb240159d3eea6865d51fd96" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/filp/whoops/zipball/cde50e6720a39fdacb240159d3eea6865d51fd96", + "reference": "cde50e6720a39fdacb240159d3eea6865d51fd96", + "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", + "symfony/var-dumper": "^2.6 || ^3.0 || ^4.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.2-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": "2019-08-07T09:00:00+00:00" }, { "name": "illuminate/container", @@ -116,7 +176,7 @@ ], "description": "The Illuminate Container package.", "homepage": "https://laravel.com", - "time": "2017-08-14 18:00:01" + "time": "2017-08-14T18:00:01+00:00" }, { "name": "illuminate/contracts", @@ -160,7 +220,7 @@ ], "description": "The Illuminate Contracts package.", "homepage": "https://laravel.com", - "time": "2017-08-27 09:20:20" + "time": "2017-08-27T09:20:20+00:00" }, { "name": "illuminate/database", @@ -219,7 +279,7 @@ "orm", "sql" ], - "time": "2017-09-03 15:31:52" + "time": "2017-09-03T15:31:52+00:00" }, { "name": "illuminate/events", @@ -264,7 +324,7 @@ ], "description": "The Illuminate Events package.", "homepage": "https://laravel.com", - "time": "2017-08-27 02:05:29" + "time": "2017-08-27T02:05:29+00:00" }, { "name": "illuminate/support", @@ -321,7 +381,7 @@ ], "description": "The Illuminate Support package.", "homepage": "https://laravel.com", - "time": "2017-09-04 14:00:07" + "time": "2017-09-04T14:00:07+00:00" }, { "name": "nesbot/carbon", @@ -374,7 +434,7 @@ "datetime", "time" ], - "time": "2017-01-16 07:55:07" + "time": "2017-01-16T07:55:07+00:00" }, { "name": "phpmailer/phpmailer", @@ -451,7 +511,7 @@ } ], "description": "PHPMailer is a full-featured email creation and transfer class for PHP", - "time": "2017-08-28 11:12:07" + "time": "2017-08-28T11:12:07+00:00" }, { "name": "psr/container", @@ -500,7 +560,54 @@ "container-interop", "psr" ], - "time": "2017-02-14 16:28:37" + "time": "2017-02-14T16:28:37+00:00" + }, + { + "name": "psr/log", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", + "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.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": "2018-11-20T15:27:04+00:00" }, { "name": "psr/simple-cache", @@ -548,7 +655,7 @@ "psr-16", "simple-cache" ], - "time": "2017-01-02 13:31:39" + "time": "2017-01-02T13:31:39+00:00" }, { "name": "spipu/html2pdf", @@ -601,7 +708,7 @@ "html2pdf", "pdf" ], - "time": "2017-06-16 13:23:32" + "time": "2017-06-16T13:23:32+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -660,7 +767,7 @@ "portable", "shim" ], - "time": "2017-06-14 15:44:48" + "time": "2017-06-14T15:44:48+00:00" }, { "name": "symfony/translation", @@ -725,7 +832,7 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2017-07-29 21:54:42" + "time": "2017-07-29T21:54:42+00:00" }, { "name": "tecnickcom/tcpdf", @@ -787,7 +894,7 @@ "pdf417", "qrcode" ], - "time": "2017-04-26 08:14:48" + "time": "2017-04-26T08:14:48+00:00" }, { "name": "twig/twig", @@ -852,7 +959,7 @@ "keywords": [ "templating" ], - "time": "2017-09-27 18:06:46" + "time": "2017-09-27T18:06:46+00:00" } ], "packages-dev": [], diff --git a/index.php b/index.php index 6e498f3..f7feceb 100755 --- a/index.php +++ b/index.php @@ -7,18 +7,19 @@ * @Contact me: vinaykhobragade99@gmail.com * @Github: github.com/feat7 */ - use \app\config\Config; +use Illuminate\Events\Dispatcher; +use \Whoops\Handler\PrettyPageHandler; + +// Set the event dispatcher used by Eloquent models... (optional) +use Illuminate\Container\Container; use Illuminate\Database\Capsule\Manager as Capsule; -if(!file_exists(__DIR__ . "/env.config.php")){ - exit("Environment file not found. Please coyp env.config.example.php to env.config.php or see the documentation for more details"); +if (! file_exists(__DIR__ . '/env.config.php')) { + exit('Environment file not found. Please coyp env.config.example.php to env.config.php or see the documentation for more details'); } -require_once 'env.config.php'; - -if(APP_MODE == '__DEV__') -ini_set('display_errors', 'on'); //Just for development mode +require_once 'env.config.php'; session_start(); //The game begins @@ -29,11 +30,23 @@ $loader->add('system', __DIR__); $loader->add('app', __DIR__); +if (APP_MODE == '__DEV__') { + ini_set('display_errors', 'on'); + + //Just for development mode + $whoops = new \Whoops\Run(); + $whoops->prependHandler(new PrettyPageHandler()); + $whoops->register(); +} else if (APP_MODE == '__PRODUCTION__') { + ini_set('display_errors', 'off'); +} + + + /** * @Let us eat a capsule to use eloquent */ - -$capsule = new Capsule; +$capsule = new Capsule(); $capsule->addConnection([ 'driver' => 'mysql', @@ -41,15 +54,12 @@ 'database' => DB_NAME, 'username' => DB_USER, 'password' => DB_PASS, - 'charset' => 'utf8', + 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ]); -// Set the event dispatcher used by Eloquent models... (optional) -use Illuminate\Events\Dispatcher; -use Illuminate\Container\Container; -$capsule->setEventDispatcher(new Dispatcher(new Container)); +$capsule->setEventDispatcher(new Dispatcher(new Container())); // Make this Capsule instance available globally via static methods... (optional) $capsule->setAsGlobal(); @@ -57,24 +67,24 @@ // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher()) $capsule->bootEloquent(); //eloquent boot done - $kernel = new system\Kernel(); //boot kernel /** * @function view - * @param view: string | path to view template + * @param view: string | path to view template * @param vars: array | inject variabes into view template + * @param mixed $view + * @param mixed $vars */ - function view($view, $vars = []) { - $twigLoader = new Twig_Loader_Filesystem('./app/views'); - $twig = new Twig_Environment($twigLoader, array( - 'cache' => './app/cache', - 'auto_reload' => true, - 'debug' => true - )); + $twigLoader = new Twig_Loader_Filesystem('./app/views'); + $twig = new Twig_Environment($twigLoader, [ + 'cache' => './app/cache', + 'auto_reload' => true, + 'debug' => true, + ]); $twig->addExtension(new Twig_Extension_Debug()); - $template = $twig->loadTemplate($view); - echo $template->render($vars); + $template = $twig->loadTemplate($view); + echo $template->render($vars); }