mirror of
https://github.com/getformwork/formwork.git
synced 2025-01-17 13:38:22 +01:00
Defer loading of Admin
This commit is contained in:
parent
23e8d19d74
commit
47654dd6ee
@ -8,7 +8,7 @@ use Formwork\Admin\Users\Users;
|
||||
use Formwork\Assets;
|
||||
use Formwork\Formwork;
|
||||
use Formwork\Languages\LanguageCodes;
|
||||
use Formwork\Page;
|
||||
use Formwork\Pages\Page;
|
||||
use Formwork\Response\RedirectResponse;
|
||||
use Formwork\Utils\FileSystem;
|
||||
use Formwork\Utils\HTTPRequest;
|
||||
@ -40,18 +40,15 @@ final class Admin
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->load();
|
||||
}
|
||||
|
||||
public function load(): void
|
||||
{
|
||||
$this->loadSchemes();
|
||||
|
||||
$this->users = Users::load();
|
||||
|
||||
$this->loadTranslations();
|
||||
$this->loadErrorHandler();
|
||||
|
||||
$this->loadRoutes();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -254,13 +251,12 @@ final class Admin
|
||||
*/
|
||||
protected function loadTranslations(): void
|
||||
{
|
||||
$languageCode = Formwork::instance()->config()->get('admin.lang');
|
||||
if ($this->isLoggedIn()) {
|
||||
$languageCode = $this->user()->language();
|
||||
}
|
||||
$path = Formwork::instance()->config()->get('translations.paths.admin');
|
||||
Formwork::instance()->translations()->loadFromPath($path);
|
||||
Formwork::instance()->translations()->setCurrent($languageCode);
|
||||
|
||||
if ($this->isLoggedIn()) {
|
||||
Formwork::instance()->translations()->setCurrent($this->user()->language());
|
||||
}
|
||||
}
|
||||
|
||||
protected function loadSchemes(): void
|
||||
@ -282,15 +278,4 @@ final class Admin
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load administration panel routes
|
||||
*/
|
||||
protected function loadRoutes(): void
|
||||
{
|
||||
Formwork::instance()->router()->loadFromFile(
|
||||
Formwork::instance()->config()->get('routes.files.admin'),
|
||||
Str::wrap(Formwork::instance()->config()->get('admin.root'), '/')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,12 @@
|
||||
namespace Formwork\Admin\Users;
|
||||
|
||||
use Formwork\Admin\Security\Password;
|
||||
use Formwork\Data\Contracts\Arrayable;
|
||||
use Formwork\Formwork;
|
||||
use Formwork\Utils\Registry;
|
||||
use Formwork\Utils\Session;
|
||||
|
||||
class User
|
||||
class User implements Arrayable
|
||||
{
|
||||
/**
|
||||
* Array containing user data
|
||||
@ -83,7 +84,6 @@ class User
|
||||
$this->$var = $this->data[$var];
|
||||
}
|
||||
|
||||
$this->avatar = new Avatar($this->data['avatar']);
|
||||
$this->permissions = new Permissions($this->role);
|
||||
}
|
||||
|
||||
@ -132,7 +132,11 @@ class User
|
||||
*/
|
||||
public function avatar(): Avatar
|
||||
{
|
||||
return $this->avatar;
|
||||
if (isset($this->avatar)) {
|
||||
return $this->avatar;
|
||||
}
|
||||
|
||||
return $this->avatar = new Avatar($this->data['avatar']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,7 +83,6 @@ final class Formwork
|
||||
$this->loadSite();
|
||||
$this->loadCache();
|
||||
$this->loadRouter();
|
||||
$this->loadAdmin();
|
||||
$this->loadRoutes();
|
||||
}
|
||||
|
||||
@ -156,7 +155,12 @@ final class Formwork
|
||||
*/
|
||||
public function admin(): ?Admin
|
||||
{
|
||||
return $this->admin;
|
||||
if (isset($this->admin)) {
|
||||
return $this->admin;
|
||||
}
|
||||
return $this->admin = $this->config->get('admin.enabled')
|
||||
? new Admin()
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -265,15 +269,7 @@ final class Formwork
|
||||
|
||||
protected function loadRouter(): void
|
||||
{
|
||||
$this->router = new Router();
|
||||
}
|
||||
|
||||
protected function loadAdmin(): void
|
||||
{
|
||||
if ($this->config->get('admin.enabled')) {
|
||||
$this->admin = new Admin();
|
||||
$this->admin->load();
|
||||
}
|
||||
$this->router = new Router($this->request);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -281,6 +277,13 @@ final class Formwork
|
||||
*/
|
||||
protected function loadRoutes(): void
|
||||
{
|
||||
if ($this->config->get('admin.enabled')) {
|
||||
$this->router->loadFromFile(
|
||||
$this->config()->get('routes.files.admin'),
|
||||
Str::wrap($this->config()->get('admin.root'), '/')
|
||||
);
|
||||
}
|
||||
|
||||
$this->router->loadFromFile($this->config()->get('routes.files.system'));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user