Skip to content

Commit

Permalink
Merge pull request #61 from XetaIO/laravel9
Browse files Browse the repository at this point in the history
Update project to Laravel9
  • Loading branch information
Xety authored Apr 1, 2022
2 parents 18c52ca + 3699638 commit 1787e3c
Show file tree
Hide file tree
Showing 72 changed files with 550 additions and 266 deletions.
14 changes: 11 additions & 3 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
namespace Xetaravel\Exceptions;

use Illuminate\Auth\AuthenticationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable;

class Handler extends ExceptionHandler
Expand All @@ -25,6 +22,17 @@ class Handler extends ExceptionHandler
\Illuminate\Validation\ValidationException::class
];

/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];

/**
* Report or log an exception.
*
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Discuss/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public function create(Request $request): RedirectResponse
$post = DiscussPostRepository::create($request->all());
$user = DiscussUserRepository::create($request->all());

$parser = new MentionParser($post);
$parser = new MentionParser($post, [
'regex' => config('mentions.regex')
]);
$content = $parser->parse($post->content);

//dd($content);
Expand Down
20 changes: 19 additions & 1 deletion app/Http/Controllers/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use Phattarachai\LaravelMobileDetect\Agent;
use Xetaravel\Models\Session;

class SecurityController extends Controller
Expand All @@ -27,10 +28,27 @@ public function index(Request $request): View
{
$records = Session::expires()->where('user_id', Auth::id())->get();

$agent = new Agent();

$sessions = [];

foreach ($records as $record) {
$infos = get_browser($record->user_agent);
$agent->setUserAgent($record->user_agent);

$device_type = ($agent->isDesktop() ? 'desktop' :
$agent->isPhone()) ? 'phone' :
($agent->isTablet() ? 'tablet' : 'unknown');

$infos = [
'platform' => $agent->platform(),
'platform_version' => $agent->version((string) $agent->platform()),
'browser' => $agent->browser(),
'browser_version' => $agent->version((string) $agent->browser()),
'desktop' => $agent->isDesktop(),
'phone' => $agent->isPhone(),
'tablet' => $agent->isTablet(),
'device_type' => $device_type
];

$record->infos = $infos;

Expand Down
16 changes: 10 additions & 6 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ class Kernel extends HttpKernel
* @var array
*/
protected $middleware = [
\Xetaravel\Http\Middleware\CheckForMaintenanceMode::class,
// \Xetaravel\Http\Middleware\TrustHosts::class,
\Xetaravel\Http\Middleware\TrustProxies::class,
\Illuminate\Http\Middleware\HandleCors::class,
\Xetaravel\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\Xetaravel\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\Xetaravel\Http\Middleware\TrustProxies::class,
];

/**
Expand All @@ -38,8 +40,9 @@ class Kernel extends HttpKernel
],

'api' => [
'throttle:60,1',
'bindings',
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];

Expand All @@ -53,11 +56,12 @@ class Kernel extends HttpKernel
protected $routeMiddleware = [
'auth' => \Xetaravel\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
//'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \Xetaravel\Http\Middleware\RedirectIfAuthenticated::class,
//'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
namespace Xetaravel\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.
*
* @var array
* @var array<int, string>
*/
protected $except = [
//
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Middleware/SessionLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public function handle($request, Closure $next)

$session = Session::where('id', $request->session()->getId())->first();

if (is_null($session)) {
return $next($request);
}

$data = [
'url' => $request->path(),
'method' => $request->method()
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 Xetaravel\Http\Middleware;

use Illuminate\Http\Middleware\TrustHosts as Middleware;

class TrustHosts extends Middleware
{
/**
* Get the host patterns that should be trusted.
*
* @return array<int, string|null>
*/
public function hosts()
{
return [
$this->allSubdomainsOfApplicationUrl(),
];
}
}
17 changes: 10 additions & 7 deletions app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
<?php

namespace Xetaravel\Http\Middleware;

use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;

class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array
* @var array<int, string>|string|null
*/
protected $proxies;

/**
* The headers that should be used to detect proxies.
*
* @var string
* @var int
*/
protected $headers = Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO;
protected $headers =
Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO |
Request::HEADER_X_FORWARDED_AWS_ELB;
}
4 changes: 2 additions & 2 deletions app/Markdown/Emoji/EmojiExtension.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
namespace Xetaravel\Markdown\Emoji;

use League\CommonMark\ConfigurableEnvironmentInterface;
use League\CommonMark\Environment\EnvironmentBuilderInterface;
use League\CommonMark\Extension\ExtensionInterface;

final class EmojiExtension implements ExtensionInterface
{

public function register(ConfigurableEnvironmentInterface $environment)
public function register(EnvironmentBuilderInterface $environment): void
{
$environment->addInlineParser(new EmojiParser);
}
Expand Down
11 changes: 6 additions & 5 deletions app/Markdown/Emoji/EmojiParser.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php
namespace Xetaravel\Markdown\Emoji;

use League\CommonMark\Inline\Element\Image;
use League\CommonMark\Inline\Parser\InlineParserInterface;
use League\CommonMark\InlineParserContext;
use League\CommonMark\Extension\CommonMark\Node\Inline\Image;
use League\CommonMark\Parser\Inline\InlineParserInterface;
use League\CommonMark\Parser\InlineParserContext;
use League\CommonMark\Parser\Inline\InlineParserMatch;

class EmojiParser implements InlineParserInterface
{
Expand Down Expand Up @@ -44,9 +45,9 @@ public function __construct()
*
* @return array
*/
public function getCharacters(): array
public function getMatchDefinition(): InlineParserMatch
{
return [':'];
return InlineParserMatch::string(':');
}

/**
Expand Down
88 changes: 2 additions & 86 deletions app/Markdown/Reply/Reply.php
Original file line number Diff line number Diff line change
@@ -1,92 +1,8 @@
<?php
namespace Xetaravel\Markdown\Reply;

use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\ContextInterface;
use League\CommonMark\Cursor;
use League\CommonMark\Node\Inline\AbstractStringContainer;

class Reply extends AbstractBlock
class Reply extends AbstractStringContainer
{
/**
* The route used to display the post.
*
* @var string
*/
protected $route;

/**
* The user of the reply.
*
* @var string
*/
protected $user;

/**
* Constructor.
*
* @param string $route The route used to display the post.
* @param string $user The user of the reply.
*/
public function __construct(string $route, string $user)
{
$this->route = $route;
$this->user = $user;
}

/**
* Get the route.
*
* @return string
*/
public function getRoute()
{
return $this->route;
}

/**
* Get the user.
*
* @return string
*/
public function getUser()
{
return $this->user;
}

/**
* Returns true if this block can contain the given block as a child node
*
* @param AbstractBlock $block
*
* @return bool
*/
public function canContain(AbstractBlock $block): bool
{
return false;
}

/**
* Returns true if block type can accept lines of text
*
* @return bool
*/
public function acceptsLines(): bool
{
return true;
}

/**
* Whether this is a code block
*
* @return bool
*/
public function isCode(): bool
{
return false;
}

public function matchesNextLine(Cursor $cursor): bool
{
return false;
}
}
8 changes: 4 additions & 4 deletions app/Markdown/Reply/ReplyExtension.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
namespace Xetaravel\Markdown\Reply;

use League\CommonMark\ConfigurableEnvironmentInterface;
use League\CommonMark\Environment\EnvironmentBuilderInterface;
use League\CommonMark\Extension\ExtensionInterface;

final class ReplyExtension implements ExtensionInterface
{
public function register(ConfigurableEnvironmentInterface $environment)
public function register(EnvironmentBuilderInterface $environment): void
{
$environment
->addBlockParser(new ReplyParser)
->addBlockRenderer(Reply::class, new ReplyRenderer);
->addInlineParser(new ReplyParser())
->addRenderer(Reply::class, new ReplyRenderer());
}
}
Loading

0 comments on commit 1787e3c

Please sign in to comment.