diff --git a/app/modules/web/Controllers/ControllerBase.php b/app/modules/web/Controllers/ControllerBase.php index f5254e2f..2478438c 100644 --- a/app/modules/web/Controllers/ControllerBase.php +++ b/app/modules/web/Controllers/ControllerBase.php @@ -129,7 +129,6 @@ abstract class ControllerBase $this->view->assign('ctx_userIsAdminAcc', $this->userData->getIsAdminAcc()); $this->view->assign('themeUri', $this->view->getTheme()->getThemeUri()); $this->view->assign('isDemo', $this->configData->isDemoEnabled()); - $this->view->assign('icons', $this->theme->getIcons()); $this->view->assign('configData', $this->configData); $this->view->assign('sk', $this->session->isLoggedIn() ? $this->session->generateSecurityKey() : ''); diff --git a/app/modules/web/Controllers/Helpers/HelperBase.php b/app/modules/web/Controllers/Helpers/HelperBase.php index c3ef4a78..c127b583 100644 --- a/app/modules/web/Controllers/Helpers/HelperBase.php +++ b/app/modules/web/Controllers/Helpers/HelperBase.php @@ -78,6 +78,9 @@ abstract class HelperBase * @param ContextInterface $context * @param EventDispatcher $eventDispatcher * @param Container $container + * + * @throws \DI\DependencyException + * @throws \DI\NotFoundException */ final public function __construct(Template $template, Config $config, ContextInterface $context, EventDispatcher $eventDispatcher, Container $container) { diff --git a/app/modules/web/Controllers/Helpers/LayoutHelper.php b/app/modules/web/Controllers/Helpers/LayoutHelper.php index 34297dae..e09ae239 100644 --- a/app/modules/web/Controllers/Helpers/LayoutHelper.php +++ b/app/modules/web/Controllers/Helpers/LayoutHelper.php @@ -31,7 +31,6 @@ use SP\Core\AppInfoInterface; use SP\Core\Crypt\CryptPKI; use SP\Core\Exceptions\SPException; use SP\Core\Language; -use SP\Core\UI\Theme; use SP\Core\UI\ThemeInterface; use SP\Html\DataGrid\Action\DataGridAction; use SP\Http\Uri; @@ -402,7 +401,7 @@ final class LayoutHelper extends HelperBase */ protected function initialize() { - $this->theme = $this->dic->get(Theme::class); + $this->theme = $this->dic->get(ThemeInterface::class); $this->loggedIn = $this->context->isLoggedIn(); diff --git a/app/modules/web/Controllers/Traits/WebControllerTrait.php b/app/modules/web/Controllers/Traits/WebControllerTrait.php index 89bc7caf..093c6e75 100644 --- a/app/modules/web/Controllers/Traits/WebControllerTrait.php +++ b/app/modules/web/Controllers/Traits/WebControllerTrait.php @@ -34,7 +34,7 @@ use SP\Core\Context\SessionContext; use SP\Core\Events\EventDispatcher; use SP\Core\Exceptions\SPException; use SP\Core\PhpExtensionChecker; -use SP\Core\UI\Theme; +use SP\Core\UI\ThemeInterface; use SP\Http\Request; use SP\Mvc\Controller\ControllerTrait; @@ -64,7 +64,7 @@ trait WebControllerTrait */ protected $session; /** - * @var Theme + * @var ThemeInterface */ protected $theme; /** @@ -133,7 +133,7 @@ trait WebControllerTrait $this->config = $dic->get(Config::class); $this->configData = $this->config->getConfigData(); $this->session = $dic->get(ContextInterface::class); - $this->theme = $dic->get(Theme::class); + $this->theme = $dic->get(ThemeInterface::class); $this->eventDispatcher = $dic->get(EventDispatcher::class); $this->router = $dic->get(Klein::class); $this->request = $dic->get(Request::class); diff --git a/app/modules/web/Init.php b/app/modules/web/Init.php index 7f3da76a..2e242b86 100644 --- a/app/modules/web/Init.php +++ b/app/modules/web/Init.php @@ -34,7 +34,7 @@ use SP\Core\Crypt\Session as CryptSession; use SP\Core\Crypt\UUIDCookie; use SP\Core\Language; use SP\Core\ModuleBase; -use SP\Core\UI\Theme; +use SP\Core\UI\ThemeInterface; use SP\DataModel\ItemPreset\SessionTimeout; use SP\Http\Address; use SP\Plugin\PluginManager; @@ -72,7 +72,7 @@ final class Init extends ModuleBase */ private $context; /** - * @var Theme + * @var ThemeInterface */ private $theme; /** @@ -106,7 +106,7 @@ final class Init extends ModuleBase parent::__construct($container); $this->context = $container->get(ContextInterface::class); - $this->theme = $container->get(Theme::class); + $this->theme = $container->get(ThemeInterface::class); $this->language = $container->get(Language::class); $this->secureSessionService = $container->get(SecureSessionService::class); $this->pluginManager = $container->get(PluginManager::class); @@ -118,10 +118,12 @@ final class Init extends ModuleBase * * @param string $controller * + * @throws \DI\DependencyException + * @throws \DI\NotFoundException * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException * @throws \SP\Core\Exceptions\ConstraintException - * @throws \SP\Core\Exceptions\InvalidClassException * @throws \SP\Core\Exceptions\QueryException + * @throws \SP\Core\Exceptions\SPException * @throws \SP\Repositories\NoSuchItemException * @throws \Exception */ @@ -143,7 +145,7 @@ final class Init extends ModuleBase $this->language->setLanguage(); // Initialize theme - $this->theme->initialize(); + $this->theme->initTheme(); } else { logger('Browser reload'); @@ -156,7 +158,7 @@ final class Init extends ModuleBase $this->language->setLanguage(true); // Re-Initialize theme - $this->theme->initialize(true); + $this->theme->initTheme(true); } // Comprobar si es necesario cambiar a HTTPS diff --git a/lib/Definitions.php b/lib/Definitions.php index 0cd7febe..908d0950 100644 --- a/lib/Definitions.php +++ b/lib/Definitions.php @@ -31,6 +31,7 @@ use SP\Core\Acl\Acl; use SP\Core\Acl\Actions; use SP\Core\Context\ContextInterface; use SP\Core\UI\Theme; +use SP\Core\UI\ThemeInterface; use SP\Http\Request; use SP\Services\Account\AccountAclService; use SP\Storage\Database\DatabaseConnectionData; @@ -65,7 +66,7 @@ return [ }, Acl::class => \DI\autowire(Acl::class) ->constructorParameter('action', get(Actions::class)), - Theme::class => \DI\autowire(Theme::class) + ThemeInterface::class => \DI\autowire(Theme::class) ->constructorParameter('module', APP_MODULE), PHPMailer::class => \DI\create(PHPMailer::class) ->constructor(true), diff --git a/lib/SP/Core/UI/Theme.php b/lib/SP/Core/UI/Theme.php index 2e388dcd..73281d75 100644 --- a/lib/SP/Core/UI/Theme.php +++ b/lib/SP/Core/UI/Theme.php @@ -104,36 +104,28 @@ final class Theme implements ThemeInterface $this->module = $module; } - /** - * @param bool $force - * - * @throws InvalidClassException - */ - public function initialize($force = false) - { - if (is_dir(VIEW_PATH)) { - $this->initTheme($force); - $this->initIcons(); - } - } - /** * Inicializar el tema visual a utilizar * * @param bool $force Forzar la detección del tema para los inicios de sesión * * @return void + * @throws InvalidClassException */ public function initTheme($force = false) { - if (empty($this->themeName) || $force === true) { - $this->themeName = $this->getUserTheme() ?: $this->getGlobalTheme(); - } + if (is_dir(VIEW_PATH)) { + if (empty($this->themeName) || $force === true) { + $this->themeName = $this->getUserTheme() ?: $this->getGlobalTheme(); + } - $this->themeUri = Bootstrap::$WEBURI . '/app/modules/' . $this->module . 'themes' . $this->themeName; - $this->themePath = str_replace(APP_ROOT, '', VIEW_PATH) . DIRECTORY_SEPARATOR . $this->themeName; - $this->themePathFull = VIEW_PATH . DIRECTORY_SEPARATOR . $this->themeName; - $this->viewsPath = $this->themePathFull . DIRECTORY_SEPARATOR . 'views'; + $this->themeUri = Bootstrap::$WEBURI . '/app/modules/' . $this->module . 'themes' . $this->themeName; + $this->themePath = str_replace(APP_ROOT, '', VIEW_PATH) . DIRECTORY_SEPARATOR . $this->themeName; + $this->themePathFull = VIEW_PATH . DIRECTORY_SEPARATOR . $this->themeName; + $this->viewsPath = $this->themePathFull . DIRECTORY_SEPARATOR . 'views'; + + $this->initIcons(); + } } /** diff --git a/lib/SP/Html/DataGrid/DataGridBase.php b/lib/SP/Html/DataGrid/DataGridBase.php index dbd96e85..035d6db1 100644 --- a/lib/SP/Html/DataGrid/DataGridBase.php +++ b/lib/SP/Html/DataGrid/DataGridBase.php @@ -28,7 +28,6 @@ defined('APP_ROOT') || die(); use SP\Core\Acl\ActionsInterface; use SP\Core\Exceptions\FileNotFoundException; -use SP\Core\UI\Theme; use SP\Core\UI\ThemeInterface; use SP\Html\DataGrid\Action\DataGridActionInterface; use SP\Html\DataGrid\Layout\DataGridHeader; @@ -131,7 +130,7 @@ abstract class DataGridBase implements DataGridInterface */ protected $tableTemplate; /** - * @var Theme + * @var ThemeInterface */ protected $theme; diff --git a/lib/SP/Mvc/View/Template.php b/lib/SP/Mvc/View/Template.php index d95a77b7..8d6675c6 100644 --- a/lib/SP/Mvc/View/Template.php +++ b/lib/SP/Mvc/View/Template.php @@ -28,7 +28,6 @@ defined('APP_ROOT') || die(); use SP\Bootstrap; use SP\Core\Exceptions\FileNotFoundException; -use SP\Core\UI\Theme; use SP\Core\UI\ThemeInterface; /** @@ -72,9 +71,9 @@ final class Template private $upgraded = false; /** - * @param Theme $theme + * @param ThemeInterface $theme */ - public function __construct(Theme $theme) + public function __construct(ThemeInterface $theme) { $this->theme = $theme; $this->vars = new TemplateVarCollection(); @@ -352,14 +351,10 @@ final class Template */ public function render() { - if (count($this->templates) === 0) { + if (empty($this->templates)) { throw new FileNotFoundException(__('La plantilla no contiene archivos')); } - /** - * No more icons var. - * $icons = $this->vars->get('icons'); - */ $icons = $this->theme->getIcons(); $configData = $this->vars->get('configData'); $sk = $this->vars->get('sk'); @@ -368,6 +363,8 @@ final class Template $_getvar = function ($key, $default = null) { if (DEBUG && !$this->vars->exists($key)) { logger(sprintf(__('No es posible obtener la variable "%s"'), $key), 'WARN'); + + return $default; } return $this->vars->get($key, $default); diff --git a/lib/SP/Services/Auth/LoginService.php b/lib/SP/Services/Auth/LoginService.php index 22120480..96d7b6df 100644 --- a/lib/SP/Services/Auth/LoginService.php +++ b/lib/SP/Services/Auth/LoginService.php @@ -32,7 +32,7 @@ use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Core\Exceptions\SPException; use SP\Core\Language; -use SP\Core\UI\Theme; +use SP\Core\UI\ThemeInterface; use SP\DataModel\UserLoginData; use SP\DataModel\UserPreferencesData; use SP\Http\Request; @@ -81,7 +81,7 @@ final class LoginService extends Service */ private $configData; /** - * @var Theme + * @var ThemeInterface */ private $theme; /** @@ -429,7 +429,7 @@ final class LoginService extends Service protected function initialize() { $this->configData = $this->config->getConfigData(); - $this->theme = $this->dic->get(Theme::class); + $this->theme = $this->dic->get(ThemeInterface::class); $this->userService = $this->dic->get(UserService::class); $this->language = $this->dic->get(Language::class); $this->trackService = $this->dic->get(TrackService::class);