mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-21 06:19:38 +08:00
fix UrlGenerator at error page
This commit is contained in:
parent
b73c819142
commit
691f26e736
@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
class E 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();
|
||||
} 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user