From ed43a2bfd584984306006d8a384b28992fc48752 Mon Sep 17 00:00:00 2001 From: SupianIDz Date: Sun, 19 May 2019 12:27:45 +0800 Subject: [PATCH] Commit Sun May 19 12:27:45 2019 --- app/Config/Logger.php | 15 --------- app/Console/Kernel.php | 2 +- app/HTTP/Controller/Controller.php | 2 +- server.php | 2 +- system/Exception/ExceptionHandler.php | 31 +++++++++++++++++-- system/Provider/AutoloadServiceProvider.php | 14 +++++++-- system/Provider/EncryptionServiceProvider.php | 6 ++++ system/Provider/RouteServiceProvider.php | 14 +++++++-- 8 files changed, 59 insertions(+), 27 deletions(-) delete mode 100755 app/Config/Logger.php diff --git a/app/Config/Logger.php b/app/Config/Logger.php deleted file mode 100755 index b833b32..0000000 --- a/app/Config/Logger.php +++ /dev/null @@ -1,15 +0,0 @@ - - * @link : www.octopy.xyz - * @license : MIT - */ - -return []; diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 81de033..3c41d60 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -18,5 +18,5 @@ class Kernel extends CLIKernel { - // for now i have no idea for this section + // for now I don't have an idea for this section } diff --git a/app/HTTP/Controller/Controller.php b/app/HTTP/Controller/Controller.php index dce3d78..cc2d4ad 100644 --- a/app/HTTP/Controller/Controller.php +++ b/app/HTTP/Controller/Controller.php @@ -18,5 +18,5 @@ class Controller extends BaseController { - // + // for now I don't have an idea for this section } diff --git a/server.php b/server.php index 5ac0c8c..8aa0f4f 100644 --- a/server.php +++ b/server.php @@ -16,7 +16,7 @@ parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ); -/** +/* * This file allows us to emulate Apache's "mod_rewrite" functionality from the * built-in PHP web server. This provides a convenient way to test a Octopy * application without having installed a "real" web server software here. diff --git a/system/Exception/ExceptionHandler.php b/system/Exception/ExceptionHandler.php index 85a8d7d..8af39a9 100755 --- a/system/Exception/ExceptionHandler.php +++ b/system/Exception/ExceptionHandler.php @@ -50,7 +50,7 @@ public function console(Throwable $exception) $vars = $this->vars($exception); $color = new Color; - dd($exception->getMessage()); + $output = "\n"; $output .= $color->apply('b:red', ' ' . $vars['exception'] . ' '); $output .= $color->apply('c:white', ' : '); @@ -64,7 +64,32 @@ public function console(Throwable $exception) $output .= "\n"; if (is_file($vars['file']) && is_readable($vars['file'])) { - $output .= $this->app['syntax']->highlight($vars['file'], $vars['line'], 3, 3); + $output .= $this->app['syntax']->highlight($vars['file'], $vars['line'], 2, 2); + $output .= "\n"; + } + + if (!empty($vars['trace'])) { + $output .= $color->apply('c:red', 'Stacktrace :'); + $output .= "\n"; + + foreach ($vars['trace'] as $no => $trace) { + $no++; + $output .= $color->apply('c:lightgray', " $no. "); + + if (isset($trace['file'])) { + $output .= $color->apply('c:green', $trace['file']); + $output .= $color->apply('c:lightgray', ' '); + $output .= $color->apply('c:lightgray', $trace['line']); + } elseif (isset($trace['class'])) { + $output .= $color->apply('c:green', $trace['class']); + $output .= $color->apply('c:lightgray', '::'); + $output .= $color->apply('c:lightgray', $trace['function']); + $output .= $color->apply('c:lightgray', '(...)'); + } + + $output .= "\n"; + } + } else { $output .= "\n"; } @@ -108,7 +133,7 @@ private function vars(Throwable $exception):array 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTrace(), - 'message' => $exception->getMessage(), + 'message' => head(explode("\n", $exception->getMessage())), 'exception' => last(explode(BS, get_class($exception))), ]; } diff --git a/system/Provider/AutoloadServiceProvider.php b/system/Provider/AutoloadServiceProvider.php index f958a12..58e9155 100644 --- a/system/Provider/AutoloadServiceProvider.php +++ b/system/Provider/AutoloadServiceProvider.php @@ -14,6 +14,8 @@ namespace Octopy\Provider; +use Octopy\Encryption\Exception\DecryptException; + class AutoloadServiceProvider extends ServiceProvider { /** @@ -29,9 +31,15 @@ public function register() $autoload .= '46AE3E009A9883E4F2C38542E300A16D'; if (file_exists($autoload)) { - $this->app['autoload']->classmap( - $this->app['encrypter']->decrypt(file_get_contents($autoload)) - ); + try { + $this->app['autoload']->classmap( + $this->app['encrypter']->decrypt(file_get_contents($autoload)) + ); + } catch (DecryptException $exception) { + if (! $this->app->console()) { + throw new DecryptException('The MAC is invalid, please re-run autoload cache command.'); + } + } } if ($composer = $this->app['config']['app.composer']) { diff --git a/system/Provider/EncryptionServiceProvider.php b/system/Provider/EncryptionServiceProvider.php index 8b35767..378095c 100644 --- a/system/Provider/EncryptionServiceProvider.php +++ b/system/Provider/EncryptionServiceProvider.php @@ -24,6 +24,12 @@ class EncryptionServiceProvider extends ServiceProvider */ public function register() { + if (empty(env('APP_KEY'))) { + $this->app['config']->set('app', array_merge($this->app['config']['app'], [ + 'key' => 'base64:F8EDudSAuRK08KoAtb3otCzYQ9yzF+KlpaN12H/vQAw=' + ])); + } + $key = $this->key( $config = $this->app['config']['app'] ); diff --git a/system/Provider/RouteServiceProvider.php b/system/Provider/RouteServiceProvider.php index 9d54b3b..8364004 100755 --- a/system/Provider/RouteServiceProvider.php +++ b/system/Provider/RouteServiceProvider.php @@ -14,6 +14,8 @@ namespace Octopy\Provider; +use Octopy\Encryption\Exception\DecryptException; + class RouteServiceProvider extends ServiceProvider { /** @@ -30,9 +32,15 @@ public function boot() $cache .= '9C46408A3BC655C68505C57A11D6C4EE'; if (file_exists($cache)) { - $this->app['router']->load( - $this->app['encrypter']->decrypt(file_get_contents($cache)) - ); + try { + $this->app['router']->load( + $this->app['encrypter']->decrypt(file_get_contents($cache)) + ); + } catch (DecryptException $exception) { + if (! $this->app->console()) { + throw new DecryptException('The MAC is invalid, please re-run route cache command.'); + } + } } else { if (method_exists($this, 'map')) { $this->map();