diff --git a/app/modules/web/Controllers/AccountController.php b/app/modules/web/Controllers/AccountController.php index 9337af04..2b3b16ad 100644 --- a/app/modules/web/Controllers/AccountController.php +++ b/app/modules/web/Controllers/AccountController.php @@ -28,12 +28,12 @@ use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; +use SP\Core\Context\SessionContext; use SP\Core\Crypt\Vault; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; -use SP\Core\Session\Session; use SP\Core\UI\ThemeIcons; use SP\DataModel\AccountExtData; use SP\Http\JsonResponse; @@ -869,7 +869,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->checkLoggedIn(); } - if (DEBUG === true && $this->session->getAppStatus() === Session::APP_STATUS_RELOADED) { + if (DEBUG === true && $this->session->getAppStatus() === SessionContext::APP_STATUS_RELOADED) { $this->session->resetAppStatus(); // Reset de los datos de ACL de cuentas diff --git a/app/modules/web/Controllers/ControllerBase.php b/app/modules/web/Controllers/ControllerBase.php index dd3c83ac..1dd9ba77 100644 --- a/app/modules/web/Controllers/ControllerBase.php +++ b/app/modules/web/Controllers/ControllerBase.php @@ -32,10 +32,10 @@ use Psr\Container\ContainerInterface; use SP\Config\Config; use SP\Config\ConfigData; use SP\Core\Acl\Acl; +use SP\Core\Context\SessionContext; use SP\Core\Events\EventDispatcher; use SP\Core\Exceptions\FileNotFoundException; use SP\Core\Language; -use SP\Core\Session\Session; use SP\Core\UI\Theme; use SP\DataModel\ProfileData; use SP\Modules\Web\Controllers\Helpers\LayoutHelper; @@ -103,7 +103,7 @@ abstract class ControllerBase */ protected $config; /** - * @var Session + * @var SessionContext */ protected $session; /** @@ -144,7 +144,7 @@ abstract class ControllerBase $this->config = $this->dic->get(Config::class); $this->configData = $this->config->getConfigData(); - $this->session = $this->dic->get(Session::class); + $this->session = $this->dic->get(SessionContext::class); $this->theme = $this->dic->get(Theme::class); $this->eventDispatcher = $this->dic->get(EventDispatcher::class); $this->acl = $this->dic->get(Acl::class); diff --git a/app/modules/web/Controllers/Helpers/HelperBase.php b/app/modules/web/Controllers/Helpers/HelperBase.php index 875bc0ed..7b811cae 100644 --- a/app/modules/web/Controllers/Helpers/HelperBase.php +++ b/app/modules/web/Controllers/Helpers/HelperBase.php @@ -28,8 +28,8 @@ use DI\Container; use Psr\Container\ContainerInterface; use SP\Config\Config; use SP\Config\ConfigData; +use SP\Core\Context\SessionContext; use SP\Core\Events\EventDispatcher; -use SP\Core\Session\Session; use SP\Mvc\View\Template; /** @@ -48,7 +48,7 @@ abstract class HelperBase */ protected $configData; /** - * @var Session + * @var SessionContext */ protected $session; /** @@ -69,11 +69,11 @@ abstract class HelperBase * * @param \SP\Mvc\View\Template $template * @param Config $config - * @param Session $session + * @param SessionContext $session * @param EventDispatcher $eventDispatcher * @param Container $container */ - final public function __construct(Template $template, Config $config, Session $session, EventDispatcher $eventDispatcher, Container $container) + final public function __construct(Template $template, Config $config, SessionContext $session, EventDispatcher $eventDispatcher, Container $container) { $this->dic = $container; $this->view = $template; diff --git a/app/modules/web/Controllers/LoginController.php b/app/modules/web/Controllers/LoginController.php index 8e7a6a20..9ee5a555 100644 --- a/app/modules/web/Controllers/LoginController.php +++ b/app/modules/web/Controllers/LoginController.php @@ -24,9 +24,9 @@ namespace SP\Modules\Web\Controllers; +use SP\Core\Context\SessionContext; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; -use SP\Core\Session\Session; use SP\Core\SessionFactory; use SP\Core\SessionUtil; use SP\Http\Request; @@ -98,7 +98,7 @@ class LoginController extends ControllerBase SessionUtil::cleanSession(); - $this->session->setAppStatus(Session::APP_STATUS_LOGGEDOUT); + $this->session->setAppStatus(SessionContext::APP_STATUS_LOGGEDOUT); $layoutHelper = $this->dic->get(LayoutHelper::class); $layoutHelper->getCustomLayout('logout', 'logout'); diff --git a/app/modules/web/Controllers/SimpleControllerBase.php b/app/modules/web/Controllers/SimpleControllerBase.php index 2a984872..2b7180e1 100644 --- a/app/modules/web/Controllers/SimpleControllerBase.php +++ b/app/modules/web/Controllers/SimpleControllerBase.php @@ -31,8 +31,8 @@ use SP\Config\Config; use SP\Config\ConfigData; use SP\Core\Acl\Acl; use SP\Core\Acl\UnauthorizedPageException; +use SP\Core\Context\SessionContext; use SP\Core\Events\EventDispatcher; -use SP\Core\Session\Session; use SP\Core\UI\Theme; use SP\Mvc\Controller\ControllerTrait; @@ -58,7 +58,7 @@ abstract class SimpleControllerBase */ protected $config; /** - * @var Session + * @var SessionContext */ protected $session; /** @@ -103,7 +103,7 @@ abstract class SimpleControllerBase $this->config = $this->dic->get(Config::class); $this->configData = $this->config->getConfigData(); - $this->session = $this->dic->get(Session::class); + $this->session = $this->dic->get(SessionContext::class); $this->theme = $this->dic->get(Theme::class); $this->eventDispatcher = $this->dic->get(EventDispatcher::class); $this->router = $this->dic->get(Klein::class); diff --git a/app/modules/web/Controllers/TaskController.php b/app/modules/web/Controllers/TaskController.php index 7da8b8d5..5cbbe1f8 100644 --- a/app/modules/web/Controllers/TaskController.php +++ b/app/modules/web/Controllers/TaskController.php @@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers; use DI\Container; use Klein\Klein; -use SP\Core\Session\Session; +use SP\Core\Context\SessionContext; use SP\Core\Task; use SP\Core\TaskFactory; use SP\Services\ServiceException; @@ -63,7 +63,7 @@ class TaskController */ public function runTaskAction($taskId) { - Session::close(); + SessionContext::close(); $router = $this->container->get(Klein::class); $router->response()->header('Content-Type', 'text/event-stream'); diff --git a/app/modules/web/Forms/FormBase.php b/app/modules/web/Forms/FormBase.php index c3b49e99..ad12c32c 100644 --- a/app/modules/web/Forms/FormBase.php +++ b/app/modules/web/Forms/FormBase.php @@ -26,7 +26,7 @@ namespace SP\Modules\Web\Forms; use SP\Config\Config; use SP\Config\ConfigData; -use SP\Core\Session\Session; +use SP\Core\Context\SessionContext; use SP\Core\Traits\InjectableTrait; /** @@ -51,7 +51,7 @@ abstract class FormBase */ protected $configData; /** - * @var Session + * @var SessionContext */ protected $session; @@ -70,9 +70,9 @@ abstract class FormBase /** * @param Config $config - * @param Session $session + * @param SessionContext $session */ - public function inject(Config $config, Session $session) + public function inject(Config $config, SessionContext $session) { $this->config = $config; $this->configData = $config->getConfigData(); diff --git a/lib/Definitions.php b/lib/Definitions.php index db6949c8..01a380df 100644 --- a/lib/Definitions.php +++ b/lib/Definitions.php @@ -27,10 +27,10 @@ use function DI\object; return [ \Klein\Klein::class => object(\Klein\Klein::class), - \SP\Core\Session\Session::class => object(\SP\Core\Session\Session::class), + \SP\Core\Context\SessionContext::class => object(\SP\Core\Context\SessionContext::class), \SP\Config\Config::class => object(\SP\Config\Config::class) ->constructor(object(\SP\Storage\XmlHandler::class) - ->constructor(CONFIG_FILE), get(\SP\Core\Session\Session::class)), + ->constructor(CONFIG_FILE), get(\SP\Core\Context\SessionContext::class)), \SP\Core\Language::class => object(\SP\Core\Language::class), \SP\Config\ConfigData::class => function (\SP\Config\Config $config) { return $config->getConfigData(); @@ -46,9 +46,9 @@ return [ ->constructor(ACTIONS_FILE)), \SP\Core\Events\EventDispatcher::class => object(\SP\Core\Events\EventDispatcher::class), \SP\Core\Acl\Acl::class => object(\SP\Core\Acl\Acl::class) - ->constructor(get(\SP\Core\Session\Session::class), get(\SP\Core\Events\EventDispatcher::class), get(\SP\Core\Acl\Actions::class)), + ->constructor(get(\SP\Core\Context\SessionContext::class), get(\SP\Core\Events\EventDispatcher::class), get(\SP\Core\Acl\Actions::class)), \SP\Core\UI\Theme::class => object(\SP\Core\UI\Theme::class) - ->constructor(APP_MODULE, get(\SP\Config\Config::class), get(\SP\Core\Session\Session::class)), + ->constructor(APP_MODULE, get(\SP\Config\Config::class), get(\SP\Core\Context\SessionContext::class)), \PHPMailer\PHPMailer\PHPMailer::class => object(\PHPMailer\PHPMailer\PHPMailer::class) ->constructor(true) ]; \ No newline at end of file diff --git a/lib/SP/Account/AccountBase.php b/lib/SP/Account/AccountBase.php index ad8f6a67..f7f809df 100644 --- a/lib/SP/Account/AccountBase.php +++ b/lib/SP/Account/AccountBase.php @@ -24,7 +24,7 @@ namespace SP\Account; -use SP\Core\Session\Session; +use SP\Core\Context\SessionContext; use SP\Core\Traits\InjectableTrait; use SP\DataModel\AccountData; use SP\DataModel\AccountExtData; @@ -47,7 +47,7 @@ abstract class AccountBase * @var AccountData|AccountExtData|AccountHistoryData */ protected $accountData; - /** @var Session */ + /** @var SessionContext */ protected $session; /** * @var int Id de la cuenta padre. @@ -71,9 +71,9 @@ abstract class AccountBase } /** - * @param Session $session + * @param SessionContext $session */ - public function inject(Session $session) + public function inject(SessionContext $session) { $this->session = $session; } diff --git a/lib/SP/Account/AccountCrypt.php b/lib/SP/Account/AccountCrypt.php index 28f4cdfd..334bb1d3 100644 --- a/lib/SP/Account/AccountCrypt.php +++ b/lib/SP/Account/AccountCrypt.php @@ -27,11 +27,11 @@ namespace SP\Account; use Defuse\Crypto\Exception\CryptoException; use SP\Config\Config; use SP\Config\ConfigData; +use SP\Core\Context\SessionContext; use SP\Core\Crypt\Crypt; use SP\Core\Exceptions\QueryException; use SP\Core\Exceptions\SPException; use SP\Core\OldCrypt; -use SP\Core\Session\Session; use SP\Core\TaskFactory; use SP\Core\Traits\InjectableTrait; use SP\DataModel\AccountData; @@ -58,7 +58,7 @@ class AccountCrypt */ protected $configData; /** - * @var Session + * @var SessionContext */ protected $session; /** @@ -77,9 +77,9 @@ class AccountCrypt /** * @param Config $config * @param Log $log - * @param Session $session + * @param SessionContext $session */ - public function inject(Config $config, Log $log, Session $session) + public function inject(Config $config, Log $log, SessionContext $session) { $this->config = $config; $this->configData = $config->getConfigData(); diff --git a/lib/SP/Account/AccountHistoryUtil.php b/lib/SP/Account/AccountHistoryUtil.php index 2aaad896..e8fffb7d 100644 --- a/lib/SP/Account/AccountHistoryUtil.php +++ b/lib/SP/Account/AccountHistoryUtil.php @@ -24,7 +24,7 @@ namespace SP\Account; -use SP\Core\Session\Session; +use SP\Core\Context\SessionContext; use SP\DataModel\ItemSearchData; use SP\Storage\DbWrapper; use SP\Storage\QueryData; @@ -116,11 +116,11 @@ class AccountHistoryUtil * * @param $id int El Id del registro en el histórico * @param $accountId - * @param Session $session + * @param SessionContext $session * @return bool * @throws \SP\Core\Exceptions\SPException */ - public static function restoreFromHistory($id, $accountId, Session $session) + public static function restoreFromHistory($id, $accountId, SessionContext $session) { // Guardamos una copia de la cuenta en el histórico AccountHistory::addHistory($accountId, false); diff --git a/lib/SP/Account/AccountUtil.php b/lib/SP/Account/AccountUtil.php index 0169e629..3fb2bc49 100644 --- a/lib/SP/Account/AccountUtil.php +++ b/lib/SP/Account/AccountUtil.php @@ -24,8 +24,8 @@ namespace SP\Account; +use SP\Core\Context\SessionContext; use SP\Core\Exceptions\SPException; -use SP\Core\Session\Session; use SP\DataModel\ItemSearchData; use SP\Mvc\Model\QueryCondition; use SP\Storage\DbWrapper; @@ -210,10 +210,10 @@ class AccountUtil * Devolver las cuentas enlazadas * * @param $accountId - * @param Session $session + * @param SessionContext $session * @return array */ - public static function getLinkedAccounts($accountId, Session $session) + public static function getLinkedAccounts($accountId, SessionContext $session) { if ($accountId === 0) { return []; @@ -238,11 +238,11 @@ class AccountUtil /** * Devuelve el filtro para la consulta SQL de cuentas que un usuario puede acceder * - * @param Session $session + * @param SessionContext $session * @param bool $useGlobalSearch * @return QueryCondition */ - public static function getAccountFilterUser(Session $session, $useGlobalSearch = false) + public static function getAccountFilterUser(SessionContext $session, $useGlobalSearch = false) { $queryFilter = new QueryCondition(); @@ -282,11 +282,11 @@ class AccountUtil /** * Devuelve el filtro para la consulta SQL de cuentas que un usuario puede acceder * - * @param Session $session + * @param SessionContext $session * @param bool $useGlobalSearch * @return QueryCondition */ - public static function getAccountHistoryFilterUser(Session $session, $useGlobalSearch = false) + public static function getAccountHistoryFilterUser(SessionContext $session, $useGlobalSearch = false) { $queryFilter = new QueryCondition(); @@ -326,11 +326,11 @@ class AccountUtil /** * Obtiene los datos de las cuentas visibles por el usuario * - * @param Session $session + * @param SessionContext $session * @param int $accountId Cuenta actual * @return array */ - public static function getAccountsForUser(Session $session, $accountId = null) + public static function getAccountsForUser(SessionContext $session, $accountId = null) { $queryFilter = self::getAccountFilterUser($session); diff --git a/lib/SP/Bootstrap.php b/lib/SP/Bootstrap.php index ec183d6d..d8da2cff 100644 --- a/lib/SP/Bootstrap.php +++ b/lib/SP/Bootstrap.php @@ -33,6 +33,7 @@ use RuntimeException; use SP\Config\Config; use SP\Config\ConfigData; use SP\Config\ConfigUtil; +use SP\Core\Context\SessionContext; use SP\Core\Crypt\CryptSessionHandler; use SP\Core\Crypt\SecureKeyCookie; use SP\Core\Crypt\Session as CryptSession; @@ -42,7 +43,6 @@ use SP\Core\Exceptions\InitializationException; use SP\Core\Exceptions\SPException; use SP\Core\Language; use SP\Core\Plugin\PluginUtil; -use SP\Core\Session\Session; use SP\Core\UI\Theme; use SP\Core\Upgrade\Upgrade; use SP\Http\Request; @@ -103,7 +103,7 @@ class Bootstrap */ protected $upgrade; /** - * @var Session + * @var SessionContext */ protected $session; /** @@ -140,7 +140,7 @@ class Bootstrap $this->config = $container->get(Config::class); $this->configData = $this->config->getConfigData(); - $this->session = $container->get(Session::class); + $this->session = $container->get(SessionContext::class); $this->theme = $container->get(Theme::class); $this->router = $container->get(Klein::class); $this->language = $container->get(Language::class); @@ -209,7 +209,7 @@ class Bootstrap $this->initializeApp(); } else { // Do not keep the PHP's session opened - Session::close(); + SessionContext::close(); } debugLog('Routing call: ' . $controllerClass . '::' . $method . '::' . print_r($params, true)); @@ -282,7 +282,7 @@ class Bootstrap } else { debugLog('Browser reload'); - $this->session->setAppStatus(Session::APP_STATUS_RELOADED); + $this->session->setAppStatus(SessionContext::APP_STATUS_RELOADED); // Cargar la configuración $this->config->loadConfig(true); @@ -441,17 +441,18 @@ class Bootstrap */ private function initSession($encrypt = false) { - if ($encrypt === true) { - if (($key = SecureKeyCookie::getKey()) !== false && self::$checkPhpVersion) { - session_set_save_handler(new CryptSessionHandler($key), true); - } + if ($encrypt === true + && self::$checkPhpVersion + && ($key = SecureKeyCookie::getKey()) !== false) { + session_set_save_handler(new CryptSessionHandler($key), true); } - // Si la sesión no puede ser iniciada, devolver un error 500 - if (session_start() === false) { + try { + $this->session->initialize(); + } catch (InitializationException $e) { $this->router->response()->header('HTTP/1.1', '500 Internal Server Error'); - throw new InitializationException(__u('La sesión no puede ser inicializada')); + throw $e; } } @@ -496,7 +497,7 @@ class Bootstrap // Comprobar acciones en URL // $this->checkPreLoginActions(); - if ($this->session->isLoggedIn() && $this->session->getAppStatus() === Session::APP_STATUS_RELOADED) { + if ($this->session->isLoggedIn() && $this->session->getAppStatus() === SessionContext::APP_STATUS_RELOADED) { debugLog('Reload user profile'); // Recargar los permisos del perfil de usuario $this->session->setUserProfile(self::$container->get(UserProfileService::class)->getById($this->session->getUserData()->getUserProfileId())->getProfile()); @@ -595,7 +596,7 @@ class Bootstrap $this->router->response()->cookie(session_name(), '', time() - 42000); } - Session::restart(); + SessionContext::restart(); } else { $sidStartTime = $this->session->getSidStartTime(); @@ -619,7 +620,7 @@ class Bootstrap } catch (CryptoException $e) { debugLog($e->getMessage()); - Session::restart(); + SessionContext::restart(); return; } } @@ -652,7 +653,7 @@ class Bootstrap /** * @param Container $container - * @param string $module + * @param string $module * @throws InitializationException * @throws \DI\DependencyException * @throws \DI\NotFoundException diff --git a/lib/SP/Config/Config.php b/lib/SP/Config/Config.php index de0d39cf..e2035356 100644 --- a/lib/SP/Config/Config.php +++ b/lib/SP/Config/Config.php @@ -26,8 +26,8 @@ namespace SP\Config; use DI\Container; use ReflectionObject; +use SP\Core\Context\SessionContext; use SP\Core\Exceptions\ConfigException; -use SP\Core\Session\Session; use SP\Services\Config\ConfigBackupService; use SP\Storage\XmlFileStorageInterface; use SP\Storage\XmlHandler; @@ -52,7 +52,7 @@ class Config */ private $fileStorage; /** - * @var Session + * @var SessionContext */ private $session; /** @@ -64,13 +64,13 @@ class Config * Config constructor. * * @param XmlFileStorageInterface $fileStorage - * @param Session $session + * @param SessionContext $session * @param Container $dic * @throws ConfigException * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct(XmlFileStorageInterface $fileStorage, Session $session, Container $dic) + public function __construct(XmlFileStorageInterface $fileStorage, SessionContext $session, Container $dic) { $this->session = $session; $this->fileStorage = $fileStorage; diff --git a/lib/SP/Controller/Grids/GridBase.php b/lib/SP/Controller/Grids/GridBase.php index 1e654607..6bf69769 100644 --- a/lib/SP/Controller/Grids/GridBase.php +++ b/lib/SP/Controller/Grids/GridBase.php @@ -25,7 +25,7 @@ namespace SP\Controller\Grids; use SP\Config\ConfigData; -use SP\Core\Session\Session; +use SP\Core\Context\SessionContext; use SP\Core\UI\Theme; use SP\Core\UI\ThemeIcons; use SP\Html\DataGrid\DataGridActionSearch; @@ -66,9 +66,9 @@ abstract class GridBase /** * Grids constructor. * @param Theme $theme - * @param Session $session + * @param SessionContext $session */ - public function __construct(Theme $theme, Session $session) + public function __construct(Theme $theme, SessionContext $session) { $this->sk = $session->getSecurityKey(); $this->icons = $this->theme->getIcons(); diff --git a/lib/SP/Controller/RequestControllerTrait.php b/lib/SP/Controller/RequestControllerTrait.php index b82b9374..b937804c 100644 --- a/lib/SP/Controller/RequestControllerTrait.php +++ b/lib/SP/Controller/RequestControllerTrait.php @@ -26,8 +26,8 @@ namespace SP\Controller; use SP\Config\Config; use SP\Config\ConfigData; +use SP\Core\Context\SessionContext; use SP\Core\Messages\LogMessage; -use SP\Core\Session\Session; use SP\Core\SessionUtil; use SP\Core\Traits\InjectableTrait; use SP\Http\JsonResponse; @@ -69,7 +69,7 @@ trait RequestControllerTrait * @var LogMessage */ protected $LogMessage; - /** @var Session */ + /** @var SessionContext */ protected $session; /** @var Config */ protected $Config; @@ -77,10 +77,10 @@ trait RequestControllerTrait protected $ConfigData; /** - * @param Session $session + * @param SessionContext $session * @param Config $config */ - final public function inject(Session $session, Config $config) + final public function inject(SessionContext $session, Config $config) { $this->session = $session; $this->Config = $config; diff --git a/lib/SP/Core/Acl/Acl.php b/lib/SP/Core/Acl/Acl.php index 14517cae..f59a9de9 100644 --- a/lib/SP/Core/Acl/Acl.php +++ b/lib/SP/Core/Acl/Acl.php @@ -25,10 +25,10 @@ namespace SP\Core\Acl; +use SP\Core\Context\SessionContext; use SP\Core\Events\Event; use SP\Core\Events\EventDispatcher; use SP\Core\Events\EventMessage; -use SP\Core\Session\Session; defined('APP_ROOT') || die(); @@ -42,7 +42,7 @@ class Acl implements ActionsInterface */ protected static $action; /** - * @var Session + * @var SessionContext */ private $session; /** @@ -53,11 +53,11 @@ class Acl implements ActionsInterface /** * Acl constructor. * - * @param Session $session + * @param SessionContext $session * @param EventDispatcher $eventDispatcher * @param Actions|null $action */ - public function __construct(Session $session, EventDispatcher $eventDispatcher, Actions $action = null) + public function __construct(SessionContext $session, EventDispatcher $eventDispatcher, Actions $action = null) { $this->session = $session; $this->eventDispatcher = $eventDispatcher; diff --git a/lib/SP/Core/Context/ContextBase.php b/lib/SP/Core/Context/ContextBase.php new file mode 100644 index 00000000..64fe4133 --- /dev/null +++ b/lib/SP/Core/Context/ContextBase.php @@ -0,0 +1,88 @@ +. + */ + +namespace SP\Core\Context; + +/** + * Class ContextBase + * @package SP\Core\Session + */ +abstract class ContextBase implements ContextInterface +{ + const APP_STATUS_UPDATED = 'updated'; + const APP_STATUS_RELOADED = 'reloaded'; + const APP_STATUS_INSTALLED = 'installed'; + const APP_STATUS_LOGGEDOUT = 'loggedout'; + + /** + * @var array + */ + private $context = []; + + /** + * @param $context + */ + final protected function setContextReference(&$context) + { + $this->context =& $context; + } + + /** + * @param $context + */ + final protected function setContext($context) + { + $this->context = $context; + } + + /** + * Devolver una variable de contexto + * + * @param string $key + * @param mixed $default + * @return mixed + */ + protected function getContextKey($key, $default = null) + { + if (isset($this->context[$key])) { + return is_numeric($default) ? (int)$this->context[$key] : $this->context[$key]; + } + + return $default; + } + + /** + * Establecer una variable de contexto + * + * @param string $key El nombre de la variable + * @param mixed $value El valor de la variable + * @return mixed + */ + protected function setContextKey($key, $value) + { + $this->context[$key] = $value; + + return $value; + } +} \ No newline at end of file diff --git a/lib/SP/Core/Context/ContextInterface.php b/lib/SP/Core/Context/ContextInterface.php new file mode 100644 index 00000000..c20b8fc9 --- /dev/null +++ b/lib/SP/Core/Context/ContextInterface.php @@ -0,0 +1,143 @@ +. + */ + +namespace SP\Core\Context; + +use SP\Config\ConfigData; +use SP\Core\Exceptions\InitializationException; +use SP\DataModel\ProfileData; +use SP\Services\User\UserLoginResponse; + +/** + * Class ContextInterface + * @package SP\Core\Session + */ +interface ContextInterface +{ + /** + * @return void + * @throws InitializationException + */ + public function initialize(); + + /** + * Establecer la configuración + * + * @param ConfigData $config + */ + public function setConfig(ConfigData $config); + + /** + * Establece los datos del usuario en la sesión. + * + * @param UserLoginResponse $userLoginResponse + */ + public function setUserData(UserLoginResponse $userLoginResponse = null); + + /** + * Obtiene el objeto de perfil de usuario de la sesión. + * + * @return ProfileData + */ + public function getUserProfile(); + + /** + * Establece el objeto de perfil de usuario en la sesión. + * + * @param ProfileData $ProfileData + */ + public function setUserProfile(ProfileData $ProfileData); + + /** + * Returns if user is logged in + * + * @return bool + */ + public function isLoggedIn(); + + /** + * Devuelve los datos del usuario en la sesión. + * + * @return UserLoginResponse + */ + public function getUserData(); + + /** + * @return mixed + */ + public function getSecurityKey(); + + /** + * @return string + */ + public function generateSecurityKey(); + + /** + * @param $sk + * @return mixed + */ + public function setSecurityKey($sk); + + /** + * Devolver la configuración + * + * @return ConfigData + */ + public function getConfig(); + + /** + * Establecer el lenguaje de la sesión + * + * @param $locale + */ + public function setLocale($locale); + + /** + * Devuelve el lenguaje de la sesión + * + * @return string + */ + public function getLocale(); + + /** + * Devuelve el estado de la aplicación + * + * @return bool + */ + public function getAppStatus(); + + /** + * Establecer el estado de la aplicación + * + * @param string $status + */ + public function setAppStatus($status); + + /** + * Reset del estado de la aplicación + * + * @return bool + */ + public function resetAppStatus(); +} \ No newline at end of file diff --git a/lib/SP/Core/Session/Session.php b/lib/SP/Core/Context/SessionContext.php similarity index 74% rename from lib/SP/Core/Session/Session.php rename to lib/SP/Core/Context/SessionContext.php index f7eee7d7..52915002 100644 --- a/lib/SP/Core/Session/Session.php +++ b/lib/SP/Core/Context/SessionContext.php @@ -22,10 +22,11 @@ * along with sysPass. If not, see . */ -namespace SP\Core\Session; +namespace SP\Core\Context; use SP\Account\AccountSearchFilter; use SP\Config\ConfigData; +use SP\Core\Exceptions\InitializationException; use SP\DataModel\ProfileData; use SP\Services\User\UserLoginResponse; @@ -34,13 +35,8 @@ use SP\Services\User\UserLoginResponse; * * @package SP\Core\Session */ -class Session +class SessionContext extends ContextBase { - const APP_STATUS_UPDATED = 'updated'; - const APP_STATUS_RELOADED = 'reloaded'; - const APP_STATUS_INSTALLED = 'installed'; - const APP_STATUS_LOGGEDOUT = 'loggedout'; - private static $isReset = false; private static $isLocked = false; @@ -83,23 +79,19 @@ class Session */ public function getTheme() { - return $this->getSessionKey('theme'); + return $this->getContextKey('theme'); } /** * Devolver una variable de sesión * * @param string $key - * @param mixed $default + * @param mixed $default * @return mixed */ - protected function getSessionKey($key, $default = null) + protected function getContextKey($key, $default = null) { - if (isset($_SESSION[$key])) { - return is_numeric($default) ? (int)$_SESSION[$key] : $_SESSION[$key]; - } - - return $default; + return parent::getContextKey($key, $default); } /** @@ -109,22 +101,22 @@ class Session */ public function setTheme($theme) { - $this->setSessionKey('theme', $theme); + $this->setContextKey('theme', $theme); } /** * Establecer una variable de sesión * - * @param string $key El nombre de la variable - * @param mixed $value El valor de la variable + * @param string $key El nombre de la variable + * @param mixed $value El valor de la variable * @return mixed */ - protected function setSessionKey($key, $value) + protected function setContextKey($key, $value) { if (self::$isLocked) { debugLog('Session locked; key=' . $key); } else { - $_SESSION[$key] = $value; + parent::setContextKey($key, $value); } return $value; @@ -137,7 +129,7 @@ class Session */ public function setConfig(ConfigData $config) { - $this->setSessionKey('config', $config); + $this->setContextKey('config', $config); } /** @@ -147,7 +139,7 @@ class Session */ public function setConfigTime($time) { - $this->setSessionKey('configTime', $time); + $this->setContextKey('configTime', $time); } /** @@ -157,7 +149,7 @@ class Session */ public function getConfigTime() { - return $this->getSessionKey('configTime'); + return $this->getContextKey('configTime'); } /** @@ -167,7 +159,7 @@ class Session */ public function setUserData(UserLoginResponse $userLoginResponse = null) { - $this->setSessionKey('userData', $userLoginResponse); + $this->setContextKey('userData', $userLoginResponse); } /** @@ -177,7 +169,7 @@ class Session */ public function getUserProfile() { - return $this->getSessionKey('userProfile'); + return $this->getContextKey('userProfile'); } /** @@ -187,7 +179,7 @@ class Session */ public function setUserProfile(ProfileData $ProfileData) { - $this->setSessionKey('userProfile', $ProfileData); + $this->setContextKey('userProfile', $ProfileData); } /** @@ -195,7 +187,7 @@ class Session */ public function getSearchFilters() { - return $this->getSessionKey('searchFilters', null); + return $this->getContextKey('searchFilters', null); } /** @@ -203,12 +195,12 @@ class Session */ public function setSearchFilters(AccountSearchFilter $searchFilters) { - $this->setSessionKey('searchFilters', $searchFilters); + $this->setContextKey('searchFilters', $searchFilters); } public function resetAccountAcl() { - $this->setSessionKey('accountAcl', null); + $this->setContextKey('accountAcl', null); } /** @@ -229,7 +221,7 @@ class Session */ public function getUserData() { - return $this->getSessionKey('userData', new UserLoginResponse()); + return $this->getContextKey('userData', new UserLoginResponse()); } /** @@ -239,7 +231,7 @@ class Session */ public function setAuthCompleted($bool) { - $this->setSessionKey('authCompleted', (bool)$bool); + $this->setContextKey('authCompleted', (bool)$bool); } /** @@ -247,7 +239,7 @@ class Session */ public function getAuthCompleted() { - return $this->getSessionKey('authCompleted', false); + return $this->getContextKey('authCompleted', false); } /** @@ -257,7 +249,7 @@ class Session */ public function getTemporaryMasterPass() { - return $this->getSessionKey('tempmasterpass'); + return $this->getContextKey('tempmasterpass'); } /** @@ -267,7 +259,7 @@ class Session */ public function setTemporaryMasterPass($password) { - $this->setSessionKey('tempmasterpass', $password); + $this->setContextKey('tempmasterpass', $password); } /** @@ -275,7 +267,7 @@ class Session */ public function getSecurityKey() { - return $this->getSessionKey('sk'); + return $this->getContextKey('sk'); } /** @@ -292,7 +284,7 @@ class Session */ public function setSecurityKey($sk) { - return $this->setSessionKey('sk', $sk); + return $this->setContextKey('sk', $sk); } /** @@ -302,7 +294,7 @@ class Session */ public function getConfig() { - return $this->getSessionKey('config'); + return $this->getContextKey('config'); } /** @@ -312,7 +304,7 @@ class Session */ public function getPublicKey() { - return $this->getSessionKey('pubkey'); + return $this->getContextKey('pubkey'); } /** @@ -322,7 +314,7 @@ class Session */ public function setPublicKey($key) { - $this->setSessionKey('pubkey', $key); + $this->setContextKey('pubkey', $key); } /** @@ -332,7 +324,7 @@ class Session */ public function getSessionTimeout() { - return $this->getSessionKey('sessionTimeout'); + return $this->getContextKey('sessionTimeout'); } /** @@ -343,7 +335,7 @@ class Session */ public function setSessionTimeout($timeout) { - $this->setSessionKey('sessionTimeout', $timeout); + $this->setContextKey('sessionTimeout', $timeout); return $timeout; } @@ -355,7 +347,7 @@ class Session */ public function getLastActivity() { - return $this->getSessionKey('lastActivity', 0); + return $this->getContextKey('lastActivity', 0); } /** @@ -365,7 +357,7 @@ class Session */ public function setLastActivity($time) { - $this->setSessionKey('lastActivity', $time); + $this->setContextKey('lastActivity', $time); } /** @@ -375,7 +367,7 @@ class Session */ public function getSidStartTime() { - return $this->getSessionKey('sidStartTime', 0); + return $this->getContextKey('sidStartTime', 0); } /** @@ -386,7 +378,7 @@ class Session */ public function setSidStartTime($time) { - $this->setSessionKey('sidStartTime', $time); + $this->setContextKey('sidStartTime', $time); return $time; } @@ -398,7 +390,7 @@ class Session */ public function getStartActivity() { - return $this->getSessionKey('startActivity', 0); + return $this->getContextKey('startActivity', 0); } /** @@ -409,7 +401,7 @@ class Session */ public function setStartActivity($time) { - $this->setSessionKey('startActivity', $time); + $this->setContextKey('startActivity', $time); return $time; } @@ -421,7 +413,7 @@ class Session */ public function setLocale($locale) { - $this->setSessionKey('locale', $locale); + $this->setContextKey('locale', $locale); } /** @@ -431,7 +423,7 @@ class Session */ public function getLocale() { - return $this->getSessionKey('locale'); + return $this->getContextKey('locale'); } /** @@ -441,7 +433,7 @@ class Session */ public function getAccountColor() { - return $this->getSessionKey('accountcolor'); + return $this->getContextKey('accountcolor'); } /** @@ -451,7 +443,7 @@ class Session */ public function setAccountColor(array $color) { - $this->setSessionKey('accountcolor', $color); + $this->setContextKey('accountcolor', $color); } /** @@ -461,7 +453,7 @@ class Session */ public function getAppStatus() { - return $this->getSessionKey('status'); + return $this->getContextKey('status'); } /** @@ -471,7 +463,7 @@ class Session */ public function setAppStatus($status) { - $this->setSessionKey('status', $status); + $this->setContextKey('status', $status); } /** @@ -481,6 +473,20 @@ class Session */ public function resetAppStatus() { - return $this->setSessionKey('status', null); + return $this->setContextKey('status', null); + } + + /** + * @return void + * @throws InitializationException + */ + public function initialize() + { + // Si la sesión no puede ser iniciada, devolver un error 500 + if (session_start() === false) { + throw new InitializationException(__u('La sesión no puede ser inicializada')); + } + + $this->setContextReference($_SESSION); } } diff --git a/lib/SP/Core/Crypt/CryptSessionHandler.php b/lib/SP/Core/Crypt/CryptSessionHandler.php index a9d8473c..c69f5a37 100644 --- a/lib/SP/Core/Crypt/CryptSessionHandler.php +++ b/lib/SP/Core/Crypt/CryptSessionHandler.php @@ -27,7 +27,6 @@ namespace SP\Core\Crypt; use Defuse\Crypto\Exception\CryptoException; use Defuse\Crypto\Key; - /** * Class CryptSessionHandler * diff --git a/lib/SP/Core/Crypt/Session.php b/lib/SP/Core/Crypt/Session.php index d42ca407..9c5a31a3 100644 --- a/lib/SP/Core/Crypt/Session.php +++ b/lib/SP/Core/Crypt/Session.php @@ -60,10 +60,10 @@ class Session /** * Regenerar la clave de sesión * - * @param \SP\Core\Session\Session $session + * @param \SP\Core\Context\SessionContext $session * @throws \Defuse\Crypto\Exception\CryptoException */ - public static function reKey(\SP\Core\Session\Session $session) + public static function reKey(\SP\Core\Context\SessionContext $session) { debugLog(__METHOD__); diff --git a/lib/SP/Core/Language.php b/lib/SP/Core/Language.php index e2b053d7..b41280e0 100644 --- a/lib/SP/Core/Language.php +++ b/lib/SP/Core/Language.php @@ -26,7 +26,7 @@ namespace SP\Core; use SP\Config\Config; use SP\Config\ConfigData; -use SP\Core\Session\Session; +use SP\Core\Context\SessionContext; use SP\Http\Request; defined('APP_ROOT') || die(); @@ -82,17 +82,17 @@ class Language */ protected $configData; /** - * @var Session + * @var SessionContext */ protected $session; /** * Language constructor. * - * @param Session $session + * @param SessionContext $session * @param Config $config */ - public function __construct(Session $session, Config $config) + public function __construct(SessionContext $session, Config $config) { $this->session = $session; $this->configData = $config->getConfigData(); diff --git a/lib/SP/Core/SessionUtil.php b/lib/SP/Core/SessionUtil.php index 7ba13020..cbbfd742 100644 --- a/lib/SP/Core/SessionUtil.php +++ b/lib/SP/Core/SessionUtil.php @@ -28,8 +28,8 @@ use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use SP\Bootstrap; use SP\Config\ConfigData; +use SP\Core\Context\SessionContext; use SP\Core\Crypt\Session as CryptSession; -use SP\Core\Session\Session; use SP\DataModel\UserData; use SP\Mgmt\Profiles\Profile; @@ -46,9 +46,9 @@ class SessionUtil * Establece las variables de sesión del usuario. * * @param UserData $UserData - * @param Session $session + * @param SessionContext $session */ - public static function loadUserSession(UserData $UserData, Session $session) + public static function loadUserSession(UserData $UserData, SessionContext $session) { $session->setUserData($UserData); $session->setUserProfile(Profile::getItem()->getById($UserData->getUserProfileId())); @@ -136,9 +136,9 @@ class SessionUtil /** * Regenerad el ID de sesión * - * @param Session $session + * @param SessionContext $session */ - public static function regenerate(Session $session) + public static function regenerate(SessionContext $session) { debugLog(__METHOD__); diff --git a/lib/SP/Core/Task.php b/lib/SP/Core/Task.php index a81b2fe8..150416b1 100644 --- a/lib/SP/Core/Task.php +++ b/lib/SP/Core/Task.php @@ -24,8 +24,8 @@ namespace SP\Core; +use SP\Core\Context\SessionContext; use SP\Core\Messages\TaskMessage; -use SP\Core\Session\Session; use SP\Util\Util; /** @@ -296,7 +296,7 @@ class Task file_put_contents($this->fileTask, serialize($this)); if ($lockSession === true) { - Session::close(); + SessionContext::close(); } return $this; diff --git a/lib/SP/Core/UI/Theme.php b/lib/SP/Core/UI/Theme.php index 25754949..bf434b7d 100644 --- a/lib/SP/Core/UI/Theme.php +++ b/lib/SP/Core/UI/Theme.php @@ -27,8 +27,8 @@ namespace SP\Core\UI; use SP\Bootstrap; use SP\Config\Config; use SP\Config\ConfigData; +use SP\Core\Context\SessionContext; use SP\Core\Exceptions\InvalidClassException; -use SP\Core\Session\Session; use SP\Storage\FileCache; use SP\Storage\FileException; use Theme\Icons; @@ -76,7 +76,7 @@ class Theme implements ThemeInterface */ protected $configData; /** - * @var Session + * @var SessionContext */ protected $session; /** @@ -93,10 +93,10 @@ class Theme implements ThemeInterface * * @param string $module * @param Config $config - * @param Session $session + * @param SessionContext $session * @param FileCache $fileCache */ - public function __construct($module, Config $config, Session $session, FileCache $fileCache) + public function __construct($module, Config $config, SessionContext $session, FileCache $fileCache) { $this->configData = $config->getConfigData(); $this->session = $session; diff --git a/lib/SP/Crypt/TemporaryMasterPass.php b/lib/SP/Crypt/TemporaryMasterPass.php index cc85580a..4d192456 100644 --- a/lib/SP/Crypt/TemporaryMasterPass.php +++ b/lib/SP/Crypt/TemporaryMasterPass.php @@ -24,12 +24,12 @@ namespace SP\Crypt; +use SP\Core\Context\SessionContext; use SP\Core\Crypt\Crypt; use SP\Core\Crypt\Hash; use SP\Core\Crypt\Session as CryptSession; use SP\Core\Events\Event; use SP\Core\Events\EventDispatcher; -use SP\Core\Session\Session; use SP\Core\Traits\InjectableTrait; use SP\DataModel\Dto\ConfigRequest; use SP\Services\Config\ConfigService; @@ -53,7 +53,7 @@ class TemporaryMasterPass */ protected $configService; /** - * @var Session + * @var SessionContext */ protected $session; /** @@ -153,10 +153,10 @@ class TemporaryMasterPass /** * @param ConfigService $configService - * @param Session $session + * @param SessionContext $session * @param EventDispatcher $eventDispatcher */ - public function inject(ConfigService $configService, Session $session, EventDispatcher $eventDispatcher) + public function inject(ConfigService $configService, SessionContext $session, EventDispatcher $eventDispatcher) { $this->configService = $configService; $this->session = $session; diff --git a/lib/SP/Log/ActionLog.php b/lib/SP/Log/ActionLog.php index 101d6bce..7c42c9d1 100644 --- a/lib/SP/Log/ActionLog.php +++ b/lib/SP/Log/ActionLog.php @@ -26,9 +26,9 @@ namespace SP\Log; use SP\Config\Config; use SP\Config\ConfigData; +use SP\Core\Context\SessionContext; use SP\Core\Language; use SP\Core\Messages\LogMessage; -use SP\Core\Session\Session; use SP\Core\Traits\InjectableTrait; use SP\Storage\Database; @@ -69,7 +69,7 @@ abstract class ActionLog extends LogLevel * @var Language */ protected $language; - /** @var \SP\Core\Session\Session */ + /** @var \SP\Core\Context\SessionContext */ protected $session; /** * @var Database @@ -95,10 +95,10 @@ abstract class ActionLog extends LogLevel /** * @param Config $config * @param Language $language - * @param Session $session + * @param SessionContext $session * @param Database $database */ - public function inject(Config $config, Language $language, Session $session, Database $database) + public function inject(Config $config, Language $language, SessionContext $session, Database $database) { $this->config = $config; $this->configData = $config->getConfigData(); diff --git a/lib/SP/Mgmt/ItemBaseTrait.php b/lib/SP/Mgmt/ItemBaseTrait.php index 514b410b..f2cdda3a 100644 --- a/lib/SP/Mgmt/ItemBaseTrait.php +++ b/lib/SP/Mgmt/ItemBaseTrait.php @@ -25,10 +25,10 @@ namespace SP\Mgmt; use SP\Config\Config; +use SP\Core\Context\SessionContext; use SP\Core\DiFactory; use SP\Core\Exceptions\InvalidClassException; use SP\Core\Exceptions\SPException; -use SP\Core\Session\Session; use SP\Core\Traits\InjectableTrait; use SP\DataModel\DataModelInterface; use SP\Storage\Database; @@ -50,7 +50,7 @@ trait ItemBaseTrait * @var mixed|DataModelInterface */ protected $itemData; - /** @var Session */ + /** @var SessionContext */ protected $session; /** @@ -148,9 +148,9 @@ trait ItemBaseTrait /** * @param Config $config * @param Database $db - * @param Session $session + * @param SessionContext $session */ - public function inject(Config $config, Database $db, Session $session) + public function inject(Config $config, Database $db, SessionContext $session) { $this->ConfigData = $config->getConfigData(); $this->db = $db; diff --git a/lib/SP/Mvc/Controller/ControllerTrait.php b/lib/SP/Mvc/Controller/ControllerTrait.php index 1d8af60a..ef5d2083 100644 --- a/lib/SP/Mvc/Controller/ControllerTrait.php +++ b/lib/SP/Mvc/Controller/ControllerTrait.php @@ -25,7 +25,7 @@ namespace SP\Mvc\Controller; use Klein\Klein; -use SP\Core\Session\Session; +use SP\Core\Context\SessionContext; use SP\Http\JsonResponse; use SP\Http\Request; use SP\Util\Checks; @@ -53,10 +53,10 @@ trait ControllerTrait /** * Comprobar si la sesión está activa * - * @param Session $session + * @param SessionContext $session * @param Klein $router */ - protected function checkLoggedInSession(Session $session, Klein $router) + protected function checkLoggedInSession(SessionContext $session, Klein $router) { if (!$session->isLoggedIn()) { if (Checks::isJson($router)) { @@ -71,9 +71,9 @@ trait ControllerTrait } /** - * @param Session $session + * @param SessionContext $session */ - protected function checkSecurityToken(Session $session) + protected function checkSecurityToken(SessionContext $session) { $sk = Request::analyzeString('sk'); $sessionKey = $session->getSecurityKey(); diff --git a/lib/SP/Providers/Auth/AuthProvider.php b/lib/SP/Providers/Auth/AuthProvider.php index aef89211..75eb4efa 100644 --- a/lib/SP/Providers/Auth/AuthProvider.php +++ b/lib/SP/Providers/Auth/AuthProvider.php @@ -36,8 +36,6 @@ use SP\Providers\Auth\Ldap\LdapParams; use SP\Providers\Auth\Ldap\LdapStd; use SP\Providers\Provider; use SP\Services\Auth\AuthException; -use SP\Services\User\UserPassService; -use SP\Services\User\UserService; defined('APP_ROOT') || die(); @@ -137,8 +135,7 @@ class AuthProvider extends Provider */ public function authDatabase() { - return (new Database($this->dic->get(UserService::class), $this->dic->get(UserPassService::class))) - ->authenticate($this->userLoginData); + return $this->dic->get(Database::class)->authenticate($this->userLoginData); } /** @@ -148,7 +145,7 @@ class AuthProvider extends Provider */ public function authBrowser() { - return (new Browser($this->configData))->authenticate($this->userLoginData); + return $this->dic->get(Browser::class)->authenticate($this->userLoginData); } /** diff --git a/lib/SP/Providers/Auth/Database/Database.php b/lib/SP/Providers/Auth/Database/Database.php index 0243b440..96cc6726 100644 --- a/lib/SP/Providers/Auth/Database/Database.php +++ b/lib/SP/Providers/Auth/Database/Database.php @@ -2,7 +2,7 @@ /** * sysPass * - * @author nuxsmin + * @author nuxsmin * @link https://syspass.org * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org * @@ -56,7 +56,7 @@ class Database implements AuthInterface /** * Database constructor. * - * @param UserService $userService + * @param UserService $userService * @param UserPassService $userPassService */ public function __construct(UserService $userService, UserPassService $userPassService) @@ -116,12 +116,6 @@ class Database implements AuthInterface return Hash::checkHashKey($this->userLoginData->getLoginPass(), $userLoginResponse->getPass()); } catch (\Exception $e) { processException($e); -// $Log = new Log(); -// $LogMessage = $Log->getLogMessage(); -// $LogMessage->setAction(__FUNCTION__); -// $LogMessage->addDescription($e->getMessage()); -// $LogMessage->addDetails(__u('Login'), $this->userLoginData->getLoginUser()); -// $Log->writeLog(); return false; } diff --git a/lib/SP/Providers/Provider.php b/lib/SP/Providers/Provider.php index e6729684..c6e559e5 100644 --- a/lib/SP/Providers/Provider.php +++ b/lib/SP/Providers/Provider.php @@ -27,8 +27,8 @@ namespace SP\Providers; use DI\Container; use Psr\Container\ContainerInterface; use SP\Config\Config; +use SP\Core\Context\SessionContext; use SP\Core\Events\EventDispatcher; -use SP\Core\Session\Session; /** * Class Service @@ -44,7 +44,7 @@ abstract class Provider */ protected $config; /** - * @var Session + * @var SessionContext */ protected $session; /** @@ -67,7 +67,7 @@ abstract class Provider { $this->dic = $dic; $this->config = $dic->get(Config::class); - $this->session = $dic->get(Session::class); + $this->session = $dic->get(SessionContext::class); $this->eventDispatcher = $dic->get(EventDispatcher::class); if (method_exists($this, 'initialize')) { diff --git a/lib/SP/Repositories/Repository.php b/lib/SP/Repositories/Repository.php index 7869935f..1d8eaed8 100644 --- a/lib/SP/Repositories/Repository.php +++ b/lib/SP/Repositories/Repository.php @@ -25,9 +25,9 @@ namespace SP\Repositories; use SP\Config\Config; +use SP\Core\Context\SessionContext; use SP\Core\Dic\Container; use SP\Core\Events\EventDispatcher; -use SP\Core\Session\Session; use SP\Storage\Database; use SP\Storage\DatabaseInterface; @@ -43,7 +43,7 @@ abstract class Repository */ protected $config; /** - * @var Session + * @var SessionContext */ protected $session; /** @@ -65,12 +65,12 @@ abstract class Repository * @param Container $dic * @param Config $config * @param Database $database - * @param Session $session + * @param SessionContext $session * @param EventDispatcher $eventDispatcher * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - final public function __construct(Container $dic, Config $config, Database $database, Session $session, EventDispatcher $eventDispatcher) + final public function __construct(Container $dic, Config $config, Database $database, SessionContext $session, EventDispatcher $eventDispatcher) { $this->dic = $dic; $this->config = $config; diff --git a/lib/SP/Services/Service.php b/lib/SP/Services/Service.php index 8a1a1c5c..74a7d707 100644 --- a/lib/SP/Services/Service.php +++ b/lib/SP/Services/Service.php @@ -27,8 +27,8 @@ namespace SP\Services; use DI\Container; use Psr\Container\ContainerInterface; use SP\Config\Config; +use SP\Core\Context\SessionContext; use SP\Core\Events\EventDispatcher; -use SP\Core\Session\Session; /** * Class Service @@ -44,7 +44,7 @@ abstract class Service */ protected $config; /** - * @var Session + * @var SessionContext */ protected $session; /** @@ -67,7 +67,7 @@ abstract class Service { $this->dic = $dic; $this->config = $dic->get(Config::class); - $this->session = $dic->get(Session::class); + $this->session = $dic->get(SessionContext::class); $this->eventDispatcher = $dic->get(EventDispatcher::class); if (method_exists($this, 'initialize')) { diff --git a/lib/SP/Util/Util.php b/lib/SP/Util/Util.php index 2ef0853b..8dad47f6 100644 --- a/lib/SP/Util/Util.php +++ b/lib/SP/Util/Util.php @@ -28,10 +28,10 @@ use Defuse\Crypto\Core; use Defuse\Crypto\Encoding; use SP\Bootstrap; use SP\Config\ConfigData; +use SP\Core\Context\SessionContext; use SP\Core\Exceptions\SPException; use SP\Core\Init; use SP\Core\Install\Installer; -use SP\Core\Session\Session; use SP\Core\SessionFactory; use SP\Html\Html; use SP\Log\Log; @@ -760,11 +760,11 @@ class Util /** * Comprobar si el usuario está logado. * - * @param Session $session + * @param SessionContext $session * @return bool * @internal param Database $db */ - public static function isLoggedIn(Session $session) + public static function isLoggedIn(SessionContext $session) { $userData = $session->getUserData();