Skip to content

Commit

Permalink
Update to Laravel 8
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMicky-FR committed Sep 8, 2020
1 parent f3ce5b8 commit 932e084
Show file tree
Hide file tree
Showing 45 changed files with 2,040 additions and 1,227 deletions.
35 changes: 8 additions & 27 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Azuriom\Exceptions;

use Azuriom\Azuriom;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\ViewErrorBag;
Expand Down Expand Up @@ -31,32 +32,15 @@ class Handler extends ExceptionHandler
];

/**
* Report or log an exception.
* Register the exception handling callbacks for the application.
*
* @param \Throwable $exception
* @return void
*
* @throws \Exception
*/
public function report(Throwable $exception)
public function register()
{
parent::report($exception);

$this->reportException($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Throwable $exception
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Throwable
*/
public function render($request, Throwable $exception)
{
return parent::render($request, $exception);
$this->reportable(function (Exception $e) {
//
});
}

/**
Expand Down Expand Up @@ -112,15 +96,12 @@ protected function fallbackRenderHttpException(HttpExceptionInterface $e)

/**
* Report the exception to Azuriom to provide quick fix of errors.
*
* @param \Throwable $exception
*/
protected function reportException(Throwable $exception)
{
if ($this->shouldntReport($exception)) {
return;
}

if (config('app.debug')) {
if (config('app.debug') || app()->runningInConsole()) {
return;
}

Expand Down
5 changes: 0 additions & 5 deletions app/Extensions/Plugin/BasePluginServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ protected function loadMigrations()
$this->loadMigrationsFrom($this->pluginPath('database/migrations'));
}

protected function loadFactories()
{
$this->loadFactoriesFrom($this->pluginPath('database/factories'));
}

protected function registerRouteDescriptions()
{
$this->app['plugins']->addRouteDescription($this->routeDescriptions());
Expand Down
3 changes: 1 addition & 2 deletions app/Extensions/Plugin/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Azuriom\Extensions\ExtensionManager;
use Azuriom\Extensions\UpdateManager;
use Azuriom\Support\Files;
use Azuriom\Support\Optimizer;
use Composer\Autoload\ClassLoader;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
Expand Down Expand Up @@ -493,7 +492,7 @@ protected function createAssetsLink(string $plugin)
$pluginAssetsPath = $this->path($plugin, 'assets');

if ($this->files->exists($pluginAssetsPath)) {
Files::relativeLink($pluginAssetsPath, $this->pluginsPublicPath($plugin));
$this->files->relativeLink($pluginAssetsPath, $this->pluginsPublicPath($plugin));
}
}
}
3 changes: 1 addition & 2 deletions app/Extensions/Theme/ThemeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Azuriom\Extensions\ExtensionManager;
use Azuriom\Extensions\UpdateManager;
use Azuriom\Models\Setting;
use Azuriom\Support\Files;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Cache;
use RuntimeException;
Expand Down Expand Up @@ -336,7 +335,7 @@ protected function createAssetsLink(string $theme)
$themeAssetsPath = $this->path('assets', $theme);

if ($this->files->exists($themeAssetsPath)) {
Files::relativeLink($themeAssetsPath, $this->themesPublicPath($theme));
$this->files->relativeLink($themeAssetsPath, $this->themesPublicPath($theme));
}
}
}
2 changes: 1 addition & 1 deletion app/Games/Minecraft/MinecraftOnlineGame.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getUserUniqueId(string $name)
return Cache::remember('games.minecraft.uuid.'.$name, now()->addMinutes(30), function () use ($name) {
$response = Http::get("https://api.mojang.com/users/profiles/minecraft/{$name}");

$uuid = Arr::get($response->throw()->json(), 'id');
$uuid = $response->throw()->json('id');

if ($uuid === null) {
throw new RuntimeException("No UUID for {$name}");
Expand Down
6 changes: 3 additions & 3 deletions app/Games/Steam/SteamGame.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ public function trans(string $key, array $placeholders = [])
public function getUserProfile(User $user)
{
return Cache::remember("users.{$user->id}.steam", now()->addMinutes(15), function () use ($user) {
$data = Http::get(self::USER_INFO_URL, [
$response = Http::get(self::USER_INFO_URL, [
'key' => config('services.steam.client_secret'),
'steamids' => $user->game_id,
])->throw()->json();
]);

return Arr::get($data, 'response.players.0');
return $response->throw()->json('response.players.0');
});
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function linkStorage()

Files::removeLink($link);

Files::relativeLink($target, $link);
File::relativeLink($target, $link);

return redirect()->route('admin.settings.performance')
->with('success', trans('messages.status-success'));
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ class Kernel extends HttpKernel
*/
protected $middleware = [
\Azuriom\Http\Middleware\EnsureInstalled::class,
// \Azuriom\Http\Middleware\TrustHosts::class,
\Azuriom\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\Azuriom\Http\Middleware\CheckForMaintenanceMode::class,
\Azuriom\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\Azuriom\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
Expand All @@ -42,7 +43,7 @@ class Kernel extends HttpKernel
],

'api' => [
'throttle:60,1',
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],

Expand All @@ -65,7 +66,6 @@ class Kernel extends HttpKernel
'admin' => \Azuriom\Http\Middleware\AdminAuthenticate::class,
'auth' => \Azuriom\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'captcha' => \Azuriom\Http\Middleware\VerifyCaptcha::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Azuriom\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;

class CheckForMaintenanceMode extends Middleware
class PreventRequestsDuringMaintenance extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
Expand Down
12 changes: 8 additions & 4 deletions app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ class RedirectIfAuthenticated
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @param string[]|null ...$guards
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
public function handle($request, Closure $next, ...$guards)
{
if (Auth::guard($guard)->check()) {
return redirect()->home();
$guards = empty($guards) ? [null] : $guards;

foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect()->home();
}
}

return $next($request);
Expand Down
20 changes: 20 additions & 0 deletions app/Http/Middleware/TrustHosts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Azuriom\Http\Middleware;

use Illuminate\Http\Middleware\TrustHosts as Middleware;

class TrustHosts extends Middleware
{
/**
* Get the host patterns that should be trusted.
*
* @return array
*/
public function hosts()
{
return [
$this->allSubdomainsOfApplicationUrl(),
];
}
}
2 changes: 1 addition & 1 deletion app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TrustProxies extends Middleware
/**
* The trusted proxies for this application.
*
* @var array|string
* @var array|string|null
*/
protected $proxies;

Expand Down
4 changes: 3 additions & 1 deletion app/Models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Azuriom\Models\Traits\HasMarkdown;
use Azuriom\Models\Traits\HasUser;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
Expand All @@ -19,8 +20,9 @@
*/
class Comment extends Model
{
use HasUser;
use HasFactory;
use HasMarkdown;
use HasUser;

/**
* The attributes that are mass assignable.
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Like.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Azuriom\Models;

use Azuriom\Models\Traits\HasUser;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
Expand All @@ -16,6 +17,7 @@
*/
class Like extends Model
{
use HasFactory;
use HasUser;

/**
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Azuriom\Models\Traits\HasUser;
use Azuriom\Models\Traits\Loggable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

Expand All @@ -32,6 +33,7 @@
class Post extends Model
{
use Attachable;
use HasFactory;
use HasImage;
use HasUser;
use Loggable;
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Azuriom\Casts\Color;
use Azuriom\Models\Traits\Loggable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
Expand All @@ -23,6 +24,7 @@
*/
class Role extends Model
{
use HasFactory;
use Loggable;

/**
Expand Down
2 changes: 2 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Azuriom\Notifications\ResetPassword as ResetPasswordNotification;
use Azuriom\Notifications\VerifyEmail as VerifyEmailNotification;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

Expand Down Expand Up @@ -41,6 +42,7 @@
*/
class User extends Authenticatable implements MustVerifyEmail
{
use HasFactory;
use InteractsWithMoney;
use Notifiable;
use Searchable;
Expand Down
11 changes: 11 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
use Azuriom\Models\Page;
use Azuriom\Models\Post;
use Azuriom\Notifications\AlertNotificationChannel;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -30,6 +33,14 @@ public function register()
*/
public function boot()
{
Paginator::useBootstrap();

Factory::guessFactoryNamesUsing(function (string $modelName) {
$modelName = Str::after($modelName, '\\Models\\');

return "Database\\Factories\\{$modelName}Factory";
});

JsonResource::withoutWrapping();

Notification::extend('alert', function () {
Expand Down
2 changes: 0 additions & 2 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class EventServiceProvider extends ServiceProvider
*/
public function boot()
{
parent::boot();

//
}
}
Loading

0 comments on commit 932e084

Please sign in to comment.