Migration complete
This commit is contained in:
43
app/Proxy/VisitorProxy.php
Normal file
43
app/Proxy/VisitorProxy.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Proxy;
|
||||
|
||||
use App\Auth\XenForoUser;
|
||||
use App\Services\XenforoService;
|
||||
|
||||
/**
|
||||
* @mixin XenForoUser
|
||||
*/
|
||||
class VisitorProxy
|
||||
{
|
||||
private ?XenForoUser $currentVisitor;
|
||||
private array $users = [];
|
||||
|
||||
public function __construct(?XenForoUser $user)
|
||||
{
|
||||
$this->currentVisitor = $user;
|
||||
}
|
||||
|
||||
public function __get( string $name ): mixed
|
||||
{
|
||||
return $this->currentVisitor?->$name;
|
||||
}
|
||||
|
||||
public function __invoke( int $userId ): ?XenForoUser
|
||||
{
|
||||
if( !isset( $this->users[$userId] ) ){
|
||||
$this->users[$userId] = app(XenforoService::class)->getXfUser($userId);
|
||||
}
|
||||
return $this->users[$userId];
|
||||
}
|
||||
|
||||
public function loggedIn(): bool
|
||||
{
|
||||
return $this->currentVisitor !== null;
|
||||
}
|
||||
|
||||
public function guest(): bool
|
||||
{
|
||||
return $this->currentVisitor === null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user