remove constant BASE_DIR

This commit is contained in:
printempw 2016-11-21 21:50:24 +08:00
parent 3a527137d4
commit 4ef6fba0c6
12 changed files with 42 additions and 61 deletions

View File

@ -5,11 +5,13 @@ namespace App\Http\Controllers;
use Utils; use Utils;
use Schema; use Schema;
use Option; use Option;
use Storage;
use Artisan; use Artisan;
use Database; use Database;
use App\Models\User; use App\Models\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Validation\Validator; use Illuminate\Validation\Validator;
use App\Exceptions\PrettyPageException;
class SetupController extends Controller class SetupController extends Controller
{ {
@ -121,10 +123,7 @@ class SetupController extends Controller
protected function createDirectories() protected function createDirectories()
{ {
if (!is_dir(BASE_DIR.'/storage/textures/')) { Utils::checkTextureDirectory();
if (!mkdir(BASE_DIR.'/storage/textures/'))
throw new App\Exceptions\PrettyPageException('/storage/textures 文件夹创建失败,请检查目录权限是否正确,或者手动放置一个。', -1);
}
} }
protected function checkTablesExist() protected function checkTablesExist()

View File

@ -100,7 +100,7 @@ class TextureController extends Controller
if (isset($responses[0]) && $responses[0] instanceof \Symfony\Component\HttpFoundation\Response) { if (isset($responses[0]) && $responses[0] instanceof \Symfony\Component\HttpFoundation\Response) {
return $responses[0]; return $responses[0];
} else { } else {
$filename = BASE_DIR."/storage/textures/{$t->hash}"; $filename = storage_path("textures/{$t->hash}");
$png = Minecraft::generateAvatarFromSkin($filename, $size); $png = Minecraft::generateAvatarFromSkin($filename, $size);
imagepng($png); imagepng($png);
@ -135,7 +135,7 @@ class TextureController extends Controller
if (isset($responses[0]) && $responses[0] instanceof \Symfony\Component\HttpFoundation\Response) { if (isset($responses[0]) && $responses[0] instanceof \Symfony\Component\HttpFoundation\Response) {
return $responses[0]; return $responses[0];
} else { } else {
$filename = BASE_DIR."/storage/textures/{$t->hash}"; $filename = storage_path("textures/{$t->hash}");
if ($t->type == "cape") { if ($t->type == "cape") {
$png = Minecraft::generatePreviewFromCape($filename, $size); $png = Minecraft::generatePreviewFromCape($filename, $size);

View File

@ -121,7 +121,7 @@ class Player extends Model
{ {
if ($this->getTexture($type)) { if ($this->getTexture($type)) {
$hash = $this->getTexture($type); $hash = $this->getTexture($type);
$path = BASE_DIR."/storage/textures/".$hash; $path = storage_path("textures/$hash");
if (Storage::disk('textures')->has($hash)) { if (Storage::disk('textures')->has($hash)) {
// Cache friendly // Cache friendly
@ -202,7 +202,9 @@ class Player extends Model
{ {
// Support both CustomSkinLoader API & UniSkinAPI // Support both CustomSkinLoader API & UniSkinAPI
if ($api_type == self::CSL_API || $api_type == self::USM_API) { if ($api_type == self::CSL_API || $api_type == self::USM_API) {
$responses = Event::fire(new GetPlayerJson($this, $api_type)); $responses = Event::fire(new GetPlayerJson($this, $api_type));
// if listeners return nothing // if listeners return nothing
if (isset($responses[0]) && $responses[0] !== null) { if (isset($responses[0]) && $responses[0] !== null) {
return $responses[0]; return $responses[0];

View File

@ -3,6 +3,7 @@
namespace App\Providers; namespace App\Providers;
use View; use View;
use Utils;
use Schema; use Schema;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@ -29,7 +30,7 @@ class BootServiceProvider extends ServiceProvider
protected function checkFileExists() protected function checkFileExists()
{ {
if (!file_exists(BASE_DIR."/.env")) { if (!file_exists(base_path('.env'))) {
throw new PrettyPageException(trans('setup.file.no-dot-env'), -1); throw new PrettyPageException(trans('setup.file.no-dot-env'), -1);
} }
} }
@ -63,10 +64,7 @@ class BootServiceProvider extends ServiceProvider
return redirect('/setup')->send(); return redirect('/setup')->send();
} }
if (!is_dir(BASE_DIR.'/storage/textures/')) { Utils::checkTextureDirectory();
if (!mkdir(BASE_DIR.'/storage/textures/'))
throw new PrettyPageException(trans('setup.file.permission-error'), -1);
}
if (version_compare(config('app.version'), option('version', ''), '>')) { if (version_compare(config('app.version'), option('version', ''), '>')) {
return redirect('/setup/update')->send(); return redirect('/setup/update')->send();

View File

@ -1,28 +0,0 @@
<?php
namespace App\Services\Database;
class Migration
{
/**
* Create tables, prefix will be added automatically
*
* @return void
*/
public static function creatTables()
{
require BASE_DIR."/setup/tables.php";
}
public static function __callStatic($method, $args)
{
if (strpos($method, 'import') !== false) {
$filename = BASE_DIR."/setup/migrations/".snake_case($method).".php";
if (file_exists($filename)) {
return require $filename;
}
}
throw new \InvalidArgumentException('Non-existent migration');
}
}

View File

@ -51,7 +51,7 @@ class Updater
public function __construct($current_version) public function __construct($current_version)
{ {
$this->current_version = $current_version; $this->current_version = $current_version;
$this->update_sources = require BASE_DIR."/config/update.php"; $this->update_sources = config('update');
$source = Option::get('update_source'); $source = Option::get('update_source');
@ -115,7 +115,7 @@ class Updater
if (!$silent) if (!$silent)
echo "<p>下载完成。</p>"; echo "<p>下载完成。</p>";
$update_cache = BASE_DIR."/setup/update_cache/"; $update_cache = storage_path('update_cache');
if (!is_dir($update_cache)) { if (!is_dir($update_cache)) {
if (false === mkdir($update_cache)) { if (false === mkdir($update_cache)) {
@ -126,7 +126,7 @@ class Updater
$zip_path = $update_cache."update_".time().".zip"; $zip_path = $update_cache."update_".time().".zip";
if (Storage::put($zip_path, $file) === false) { if (Storage::put($zip_path, $file) === false) {
Storage::removeDir(BASE_DIR.'/setup/update_cache/'); Storage::removeDir($update_cache);
return false; return false;
} }

View File

@ -2,9 +2,9 @@
namespace App\Services; namespace App\Services;
use App\Exceptions\PrettyPageException;
use Storage;
use Log; use Log;
use Storage;
use App\Exceptions\PrettyPageException;
class Utils class Utils
{ {
@ -17,11 +17,11 @@ class Utils
public static function upload($file) public static function upload($file)
{ {
$path = 'tmp'.time(); $path = 'tmp'.time();
$absolute_path = BASE_DIR."/storage/textures/$path"; $absolute_path = storage_path("textures/$path");
try { try {
if (false === move_uploaded_file($file['tmp_name'], $absolute_path)) { if (false === move_uploaded_file($file['tmp_name'], $absolute_path)) {
throw new Exception('Failed to remove uploaded files, please check the permission', 1); throw new \Exception('Failed to remove uploaded files, please check the permission', 1);
} }
} catch (\Exception $e) { } catch (\Exception $e) {
Log::warning("Failed to move uploaded file, $e"); Log::warning("Failed to move uploaded file, $e");
@ -79,4 +79,13 @@ class Utils
return $str; return $str;
} }
public static function checkTextureDirectory()
{
if (!Storage::disk('storage')->has('textures')) {
// mkdir
if (!Storage::disk('storage')->makeDirectory('textures'))
throw new PrettyPageException(trans('setup.file.permission-error'), -1);
}
}
} }

View File

@ -137,7 +137,7 @@ if (! function_exists('bs_menu')) {
function bs_menu($type) function bs_menu($type)
{ {
$menu = require BASE_DIR."/config/menu.php"; $menu = config('menu');
event($type == "user" ? new App\Events\ConfigureUserMenu($menu) event($type == "user" ? new App\Events\ConfigureUserMenu($menu)
: new App\Events\ConfigureAdminMenu($menu)); : new App\Events\ConfigureAdminMenu($menu));

View File

@ -1,8 +1,6 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
define('BASE_DIR', __DIR__);
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Register The Auto Loader | Register The Auto Loader
@ -15,9 +13,9 @@ define('BASE_DIR', __DIR__);
| |
*/ */
require BASE_DIR.'/bootstrap/autoload.php'; require __DIR__.'/bootstrap/autoload.php';
$app = require_once BASE_DIR.'/bootstrap/app.php'; $app = require_once __DIR__.'/bootstrap/app.php';
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View File

@ -48,6 +48,11 @@ return [
'root' => storage_path('app'), 'root' => storage_path('app'),
], ],
'storage' => [
'driver' => 'local',
'root' => storage_path(),
],
'textures' => [ 'textures' => [
'driver' => 'local', 'driver' => 'local',
'root' => storage_path('textures'), 'root' => storage_path('textures'),

View File

@ -7,11 +7,9 @@
* @author printempw <h@prinzeugen.net> * @author printempw <h@prinzeugen.net>
*/ */
define('BASE_DIR', __DIR__); require __DIR__.'/bootstrap/autoload.php';
require BASE_DIR.'/bootstrap/autoload.php'; $app = require_once __DIR__.'/bootstrap/app.php';
$app = require_once BASE_DIR.'/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

View File

@ -31,7 +31,7 @@
} }
$zip = new ZipArchive(); $zip = new ZipArchive();
$extract_dir = BASE_DIR."/setup/update_cache/{$updater->latest_version}"; $extract_dir = storage_path("update_cache/{$updater->latest_version}");
$res = $zip->open($zip_path); $res = $zip->open($zip_path);
if ($res === true) { if ($res === true) {
@ -42,12 +42,12 @@
} }
$zip->close(); $zip->close();
if (Storage::copyDir($extract_dir, BASE_DIR) !== true) { if (Storage::copyDir($extract_dir, base_path()) !== true) {
Storage::removeDir(BASE_DIR.'/setup/update_cache/'); Storage::removeDir(storage_path('update_cache'));
exit('无法覆盖文件。'); exit('无法覆盖文件。');
} else { } else {
echo "<p>正在覆盖文件</p>"; echo "<p>正在覆盖文件</p>";
Storage::removeDir(BASE_DIR.'/setup/update_cache/'); Storage::removeDir(storage_path('update_cache'));
echo "<p>正在清理</p>"; echo "<p>正在清理</p>";
} }
echo "<p>更新完成。</p>"; echo "<p>更新完成。</p>";
@ -57,7 +57,7 @@
</div><!-- /.box-body --> </div><!-- /.box-body -->
<div class="box-footer"> <div class="box-footer">
<a href="../setup/update.php" class="btn btn-primary">下一步</a> <a href="{{ url('setup/update') }}" class="btn btn-primary">下一步</a>
</div> </div>
</div> </div>