diff --git a/app/Exceptions/E.php b/app/Exceptions/E.php deleted file mode 100644 index 372cb1bc..00000000 --- a/app/Exceptions/E.php +++ /dev/null @@ -1,39 +0,0 @@ -showErrorPage(); - } else { - $this->showErrorJson(); - } - } - - private function showErrorJson() - { - $exception['errno'] = $this->code; - $exception['msg'] = $this->message; - @header('Content-type: application/json; charset=utf-8'); - exit(json_encode($exception)); - } - - private function showErrorPage() - { - echo \View::make('errors.e')->with('code', $this->code) - ->with('message', $this->message) - ->render(); - exit; - } -} diff --git a/app/Exceptions/PrettyPageException.php b/app/Exceptions/PrettyPageException.php index e06f9c2b..739f748e 100644 --- a/app/Exceptions/PrettyPageException.php +++ b/app/Exceptions/PrettyPageException.php @@ -4,5 +4,26 @@ namespace App\Exceptions; class PrettyPageException extends \Exception { + /** + * Custom error handler + * + * @param string $message + * @param integer $code + * @param boolean $render, to show a error page + */ + function __construct($message = "Error occured.", $code = -1, $render = false) + { + parent::__construct($message, $code); + if ($render) + $this->showErrorPage(); + } + + private function showErrorPage() + { + echo \View::make('errors.e')->with('code', $this->code) + ->with('message', $this->message) + ->render(); + exit; + } } diff --git a/config/app.php b/config/app.php index 7b98d124..2e6e2fa8 100644 --- a/config/app.php +++ b/config/app.php @@ -219,7 +219,6 @@ return [ 'Option' => App\Services\Facades\Option::class, 'Utils' => App\Services\Utils::class, 'Minecraft' => App\Services\Minecraft::class, - 'Validate' => App\Services\Validate::class, 'Updater' => App\Services\Updater::class, 'Database' => App\Services\Facades\Database::class, diff --git a/setup/bootstrap.php b/setup/bootstrap.php index e9f4b7a9..3ecc30ee 100644 --- a/setup/bootstrap.php +++ b/setup/bootstrap.php @@ -35,6 +35,29 @@ Illuminate\Support\Facades\Facade::setFacadeApplication($app); (new Illuminate\Database\DatabaseServiceProvider($app))->register(); (new Illuminate\Filesystem\FilesystemServiceProvider($app))->register(); +$app['url'] = $app->share(function ($app) { + $routes = $app['router']->getRoutes(); + + // The URL generator needs the route collection that exists on the router. + // Keep in mind this is an object, so we're passing by references here + // and all the registered routes will be available to the generator. + $app->instance('routes', $routes); + + $request = Symfony\Component\HttpFoundation\Request::createFromGlobals(); + + $request = (new Illuminate\Http\Request)->duplicate( + $request->query->all(), $request->request->all(), $request->attributes->all(), + // quick fix: replace request URI with empty string + $request->cookies->all(), $request->files->all(), array_replace($request->server->all(), ['REQUEST_URI' => '']) + ); + + $url = new Illuminate\Routing\UrlGenerator( + $routes, $request + ); + + return $url; +}); + $app->singleton('database', App\Services\Database\Database::class); $app->singleton('option', App\Services\OptionRepository::class); diff --git a/setup/index.php b/setup/index.php index 5a8f1808..7d6b7185 100644 --- a/setup/index.php +++ b/setup/index.php @@ -4,7 +4,7 @@ */ require __DIR__."/bootstrap.php"; - +throw new App\Exceptions\PrettyPageException('非法参数', 1, true); // If already installed if (checkTableExist()) { View::show('setup.locked'); @@ -73,7 +73,7 @@ switch ($step) { if (!is_dir(BASE_DIR.'/storage/textures/')) { if (!mkdir(BASE_DIR.'/storage/textures/')) - throw new E('textures 文件夹创建失败,请确认目录权限是否正确,或者手动放置一个。', -1); + throw new App\Exceptions\PrettyPageException('textures 文件夹创建失败,请确认目录权限是否正确,或者手动放置一个。', -1); } echo View::make('setup.steps.3')->with('email', $_POST['email'])->with('password', $_POST['password']); @@ -81,6 +81,6 @@ switch ($step) { break; default: - throw new App\Exceptions\E('非法参数', 1, true); + throw new App\Exceptions\PrettyPageException('非法参数', 1, true); break; }