chore: Bootstrap refactoring

Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
Rubén D
2024-04-20 11:59:23 +02:00
parent 03e4a57562
commit 4e346d9f1a
99 changed files with 645 additions and 1015 deletions

View File

@@ -37,7 +37,7 @@ use SP\Domain\Api\Services\JsonRpcResponse;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\Acl\AclInterface;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Exceptions\SPException;
use SP\Http\JsonResponse;
@@ -50,8 +50,8 @@ abstract class ControllerBase
{
protected const SEARCH_COUNT_ITEMS = 25;
protected string $controllerName;
protected ContextInterface $context;
protected string $controllerName;
protected Context $context;
protected EventDispatcher $eventDispatcher;
protected ApiService $apiService;
protected Klein $router;

View File

@@ -32,6 +32,7 @@ use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use RuntimeException;
use SP\Core\Bootstrap\BootstrapBase;
use SP\Core\Bootstrap\RouteContext;
use SP\Domain\Core\Bootstrap\BootstrapInterface;
use SP\Domain\Core\Bootstrap\ModuleInterface;
use SP\Domain\Core\Exceptions\SessionTimeout;
@@ -83,8 +84,6 @@ final class Bootstrap extends BootstrapBase
$routeContextData->getActionName()
);
$this->initializePluginClasses();
if (!method_exists($controllerClass, $routeContextData->getMethodName())) {
logger($controllerClass . '::' . $routeContextData->getMethodName());

View File

@@ -29,7 +29,6 @@ use Exception;
use JsonException;
use SP\Core\Acl\Acl;
use SP\Core\Application;
use SP\Core\Bootstrap\BootstrapBase;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Domain\Account\Ports\AccountService;
@@ -54,10 +53,10 @@ final class SaveRequestController extends AccountControllerBase
private UserService $userService;
public function __construct(
Application $application,
WebControllerHelper $webControllerHelper,
AccountService $accountService,
UserService $userService
Application $application,
WebControllerHelper $webControllerHelper,
AccountService $accountService,
UserService $userService
) {
parent::__construct(
$application,
@@ -71,7 +70,7 @@ final class SaveRequestController extends AccountControllerBase
/**
* Saves a request action
*
* @param int $id Account's ID
* @param int $id Account's ID
*
* @return bool
* @throws JsonException
@@ -85,12 +84,13 @@ final class SaveRequestController extends AccountControllerBase
throw new ValidationException(__u('A description is needed'));
}
$accountDetails = $this->accountService->getByIdEnriched($id)->getAccountVData();
$accountDetails = $this->accountService->getByIdEnriched($id);
$baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI).BootstrapBase::$SUBURI;
$baseUrl = ($this->configData->getApplicationUrl() ?: $this->uriContext->getWebUri()) .
$this->uriContext->getSubUri();
$deepLink = new Uri($baseUrl);
$deepLink->addParam('r', Acl::getActionRoute(AclActionsInterface::ACCOUNT_VIEW) . '/' . $id);
$deepLink->addParam('r', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_VIEW) . '/' . $id);
$usersId = [$accountDetails->userId, $accountDetails->userEditId];
@@ -106,7 +106,10 @@ final class SaveRequestController extends AccountControllerBase
->addDetail(__u('Account'), $accountDetails->getName())
->addDetail(__u('Client'), $accountDetails->getClientName())
->addDetail(__u('Description'), $description)
->addDetail(__u('Link'), $deepLink->getUriSigned($this->configData->getPasswordSalt()))
->addDetail(
__u('Link'),
$deepLink->getUriSigned($this->configData->getPasswordSalt())
)
->addExtra('accountId', $id)
->addExtra('whoId', $this->userData->getId())
->setExtra('userId', $usersId)
@@ -122,7 +125,7 @@ final class SaveRequestController extends AccountControllerBase
return $this->returnJsonResponseData(
[
'itemId' => $id,
'itemId' => $id,
'nextAction' => Acl::getActionRoute(AclActionsInterface::ACCOUNT),
],
JsonMessage::JSON_SUCCESS,

View File

@@ -28,7 +28,6 @@ namespace SP\Modules\Web\Controllers\Account;
use Exception;
use SP\Core\Acl\Acl;
use SP\Core\Application;
use SP\Core\Bootstrap\BootstrapBase;
use SP\Core\Crypt\Vault;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
@@ -57,11 +56,11 @@ final class ViewLinkController extends AccountControllerBase
private ImageUtil $imageUtil;
public function __construct(
Application $application,
Application $application,
WebControllerHelper $webControllerHelper,
AccountService $accountService,
PublicLinkService $publicLinkService,
ImageUtilInterface $imageUtil
AccountService $accountService,
PublicLinkService $publicLinkService,
ImageUtilInterface $imageUtil
) {
parent::__construct(
$application,
@@ -138,7 +137,8 @@ final class ViewLinkController extends AccountControllerBase
? '***'
: $this->request->getClientAddress(true);
$baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI) . BootstrapBase::$SUBURI;
$baseUrl = ($this->configData->getApplicationUrl() ?: $this->uriContext->getWebUri()) .
$this->uriContext->getSubUri();
$deepLink = new Uri($baseUrl);
$deepLink->addParam(

View File

@@ -27,17 +27,20 @@ namespace SP\Modules\Web\Controllers\Bootstrap;
use Exception;
use JsonException;
use SP\Core\Application;
use SP\Core\Bootstrap\BootstrapBase;
use SP\Core\Crypt\CryptPKI;
use SP\Domain\Core\Crypt\CryptPKIInterface;
use SP\Domain\Import\Services\ImportService;
use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Import\Services\ImportStrategy;
use SP\Domain\Plugin\Ports\PluginManagerService;
use SP\Infrastructure\File\FileException;
use SP\Modules\Web\Controllers\SimpleControllerBase;
use SP\Modules\Web\Controllers\Traits\JsonTrait;
use SP\Mvc\Controller\SimpleControllerHelper;
use SP\Plugin\PluginManager;
use SP\Providers\Auth\Browser\BrowserAuthService;
use function SP\logger;
use function SP\processException;
/**
* Class GetEnvironmentController
*
@@ -47,21 +50,13 @@ final class GetEnvironmentController extends SimpleControllerBase
{
use JsonTrait;
private CryptPKIInterface $cryptPKI;
private PluginManager $pluginManager;
private BrowserAuthService $browser;
public function __construct(
Application $application,
SimpleControllerHelper $simpleControllerHelper,
CryptPKIInterface $cryptPKI,
PluginManager $pluginManager,
BrowserAuthService $browser
Application $application,
SimpleControllerHelper $simpleControllerHelper,
private readonly CryptPKIInterface $cryptPKI,
private readonly BrowserAuthService $browser,
private readonly PluginManagerService $pluginManagerService
) {
$this->cryptPKI = $cryptPKI;
$this->pluginManager = $pluginManager;
$this->browser = $browser;
parent::__construct($application, $simpleControllerHelper);
}
@@ -70,6 +65,7 @@ final class GetEnvironmentController extends SimpleControllerBase
*
* @return bool
* @throws JsonException
* @throws SPException
*/
public function getEnvironmentAction(): bool
{
@@ -78,25 +74,25 @@ final class GetEnvironmentController extends SimpleControllerBase
|| $this->configData->isDemoEnabled());
$data = [
'lang' => $this->getJsLang(),
'locale' => $this->configData->getSiteLang(),
'app_root' => BootstrapBase::$WEBURI,
'max_file_size' => $this->configData->getFilesAllowedSize(),
'check_updates' => $checkStatus && $this->configData->isCheckUpdates(),
'check_notices' => $checkStatus && $this->configData->isCheckNotices(),
'lang' => $this->getJsLang(),
'locale' => $this->configData->getSiteLang(),
'app_root' => $this->uriContext->getWebUri(),
'max_file_size' => $this->configData->getFilesAllowedSize(),
'check_updates' => $checkStatus && $this->configData->isCheckUpdates(),
'check_notices' => $checkStatus && $this->configData->isCheckNotices(),
'check_notifications' => $this->getNotificationsEnabled(),
'timezone' => date_default_timezone_get(),
'debug' => DEBUG || $this->configData->isDebug(),
'cookies_enabled' => $this->getCookiesEnabled(),
'plugins' => $this->getPlugins(),
'loggedin' => $this->session->isLoggedIn(),
'timezone' => date_default_timezone_get(),
'debug' => DEBUG || $this->configData->isDebug(),
'cookies_enabled' => $this->getCookiesEnabled(),
'plugins' => $this->getPlugins(),
'loggedin' => $this->session->isLoggedIn(),
'authbasic_autologin' => $this->getAuthBasicAutologinEnabled(),
'pki_key' => $this->getPublicKey(),
'pki_max_size' => CryptPKI::getMaxDataSize(),
'import_allowed_mime' => ImportService::ALLOWED_MIME,
'files_allowed_mime' => $this->configData->getFilesAllowedMime(),
'session_timeout' => $this->configData->getSessionTimeout(),
'csrf' => $this->getCSRF(),
'pki_key' => $this->getPublicKey(),
'pki_max_size' => CryptPKI::getMaxDataSize(),
'import_allowed_mime' => ImportStrategy::ALLOWED_MIME,
'files_allowed_mime' => $this->configData->getFilesAllowedMime(),
'session_timeout' => $this->configData->getSessionTimeout(),
'csrf' => $this->getCSRF(),
];
return $this->returnJsonResponseData($data);
@@ -107,7 +103,7 @@ final class GetEnvironmentController extends SimpleControllerBase
*/
private function getJsLang(): array
{
return require RESOURCES_PATH.DIRECTORY_SEPARATOR.'strings.js.inc';
return require RESOURCES_PATH . DIRECTORY_SEPARATOR . 'strings.js.inc';
}
/**
@@ -139,7 +135,7 @@ final class GetEnvironmentController extends SimpleControllerBase
private function getPlugins(): array
{
try {
return $this->pluginManager->getEnabledPlugins();
return $this->pluginManagerService->getEnabled();
} catch (Exception $e) {
processException($e);
}

View File

@@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers\ConfigBackup;
use Exception;
use SP\Core\Context\SessionContext;
use SP\Core\Context\Session;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Domain\Core\Acl\AclActionsInterface;
@@ -55,7 +55,7 @@ final class DownloadBackupAppController extends SimpleControllerBase
}
try {
SessionContext::close();
Session::close();
$filePath = BackupFileHelper::getAppBackupFilename(
BACKUP_PATH,

View File

@@ -25,7 +25,7 @@
namespace SP\Modules\Web\Controllers\ConfigBackup;
use Exception;
use SP\Core\Context\SessionContext;
use SP\Core\Context\Session;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Domain\Core\Acl\AclActionsInterface;
@@ -56,7 +56,7 @@ final class DownloadBackupDbController extends SimpleControllerBase
}
try {
SessionContext::close();
Session::close();
$filePath = BackupFileHelper::getDbBackupFilename(
BACKUP_PATH,

View File

@@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers\ConfigBackup;
use Exception;
use SP\Core\Context\SessionContext;
use SP\Core\Context\Session;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Domain\Core\Acl\AclActionsInterface;
@@ -51,7 +51,7 @@ final class DownloadExportController extends SimpleControllerBase
public function downloadExportAction(): string
{
try {
SessionContext::close();
Session::close();
$filePath = XmlExport::buildFilename(
BACKUP_PATH,

View File

@@ -27,7 +27,7 @@ namespace SP\Modules\Web\Controllers\ConfigBackup;
use Exception;
use SP\Core\Application;
use SP\Core\Context\SessionContext;
use SP\Core\Context\Session;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Domain\Core\Acl\AclActionsInterface;
@@ -70,7 +70,7 @@ final class FileBackupController extends SimpleControllerBase
}
try {
SessionContext::close();
Session::close();
$this->fileBackupService->doBackup(BACKUP_PATH);

View File

@@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers\ConfigBackup;
use Exception;
use SP\Core\Application;
use SP\Core\Context\SessionContext;
use SP\Core\Context\Session;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Domain\Core\Acl\AclActionsInterface;
@@ -83,7 +83,7 @@ final class XmlExportController extends SimpleControllerBase
new Event($this, EventMessage::factory()->addDescription(__u('sysPass XML export')))
);
SessionContext::close();
Session::close();
$file = $this->xmlExportService->export(new DirectoryHandler(BACKUP_PATH), $exportPassword);

View File

@@ -27,7 +27,7 @@ namespace SP\Modules\Web\Controllers\ConfigGeneral;
use Exception;
use JsonException;
use SP\Core\Context\SessionContext;
use SP\Core\Context\Session;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Domain\Core\Acl\AclActionsInterface;
@@ -51,7 +51,7 @@ final class DownloadLogController extends SimpleControllerBase
}
try {
SessionContext::close();
Session::close();
$file = new FileHandler(LOG_FILE);
$file->checkFileExists();

View File

@@ -27,7 +27,7 @@ namespace SP\Modules\Web\Controllers\ConfigImport;
use Exception;
use JsonException;
use SP\Core\Application;
use SP\Core\Context\SessionContext;
use SP\Core\Context\Session;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Domain\Core\Acl\AclActionsInterface;
@@ -80,7 +80,7 @@ final class ImportController extends SimpleControllerBase
try {
$this->eventDispatcher->notify('run.import.start', new Event($this));
SessionContext::close();
Session::close();
$counter = $this->importService->doImport($this->getImportParams())->getCounter();

View File

@@ -36,7 +36,8 @@ use SP\Domain\Auth\Services\AuthException;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Config\Ports\ConfigFileService;
use SP\Domain\Core\Acl\AclInterface;
use SP\Domain\Core\Context\SessionContextInterface;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Core\Context\SessionContext;
use SP\Domain\Core\Exceptions\FileNotFoundException;
use SP\Domain\Core\Exceptions\SessionTimeout;
use SP\Domain\Core\Exceptions\SPException;
@@ -63,21 +64,22 @@ abstract class ControllerBase
protected const ERR_UNAVAILABLE = 0;
protected EventDispatcher $eventDispatcher;
protected ConfigFileService $config;
protected SessionContextInterface $session;
protected ThemeInterface $theme;
protected AclInterface $acl;
protected ConfigDataInterface $configData;
protected RequestInterface $request;
protected PhpExtensionCheckerService $extensionChecker;
protected TemplateInterface $view;
protected ?UserDataDto $userData = null;
protected ?ProfileData $userProfileData = null;
protected bool $isAjax;
protected LayoutHelper $layoutHelper;
protected string $actionName;
private BrowserAuthService $browser;
protected readonly EventDispatcher $eventDispatcher;
protected readonly ConfigFileService $config;
protected readonly SessionContext $session;
protected readonly ThemeInterface $theme;
protected readonly AclInterface $acl;
protected readonly ConfigDataInterface $configData;
protected readonly RequestInterface $request;
protected readonly PhpExtensionCheckerService $extensionChecker;
protected readonly TemplateInterface $view;
protected readonly LayoutHelper $layoutHelper;
protected readonly UriContextInterface $uriContext;
protected ?UserDataDto $userData = null;
protected ?ProfileData $userProfileData = null;
protected bool $isAjax;
protected string $actionName;
private readonly BrowserAuthService $browser;
public function __construct(
Application $application,
@@ -96,6 +98,7 @@ abstract class ControllerBase
$this->browser = $webControllerHelper->getBrowser();
$this->layoutHelper = $webControllerHelper->getLayoutHelper();
$this->view = $webControllerHelper->getTemplate();
$this->uriContext = $webControllerHelper->getUriContext();
$this->view->setBase($this->getViewBaseName());
$this->isAjax = $this->request->isAjax();

View File

@@ -26,7 +26,6 @@ namespace SP\Modules\Web\Controllers\Helpers\Account;
use SP\Core\Acl\Acl;
use SP\Core\Application;
use SP\Core\Bootstrap\BootstrapBase;
use SP\DataModel\ItemPreset\AccountPermission as AccountPermissionPreset;
use SP\DataModel\ItemPreset\AccountPrivate;
use SP\DataModel\ProfileData;
@@ -45,6 +44,7 @@ use SP\Domain\Core\Acl\AccountPermissionException;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Acl\AclInterface;
use SP\Domain\Core\Acl\UnauthorizedPageException;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\NoSuchPropertyException;
use SP\Domain\Core\Exceptions\QueryException;
@@ -73,39 +73,40 @@ final class AccountHelper extends AccountHelperBase
{
use ItemTrait;
private AccountService $accountService;
private AccountHistoryService $accountHistoryService;
private PublicLinkService $publicLinkService;
private ItemPresetService $itemPresetService;
private MasterPassService $masterPassService;
private AccountAclService $accountAclService;
private CategoryService $categoryService;
private ClientService $clientService;
private CustomFieldDataService $customFieldService;
private ?AccountPermission $accountAcl = null;
private ?int $accountId = null;
private UserService $userService;
private UserGroupService $userGroupService;
private TagService $tagService;
private AccountService $accountService;
private AccountHistoryService $accountHistoryService;
private PublicLinkService $publicLinkService;
private ItemPresetService $itemPresetService;
private MasterPassService $masterPassService;
private AccountAclService $accountAclService;
private CategoryService $categoryService;
private ClientService $clientService;
private CustomFieldDataService $customFieldService;
private ?AccountPermission $accountAcl = null;
private ?int $accountId = null;
private UserService $userService;
private UserGroupService $userGroupService;
private TagService $tagService;
public function __construct(
Application $application,
TemplateInterface $template,
RequestInterface $request,
AclInterface $acl,
AccountService $accountService,
AccountHistoryService $accountHistoryService,
PublicLinkService $publicLinkService,
ItemPresetService $itemPresetService,
MasterPassService $masterPassService,
AccountActionsHelper $accountActionsHelper,
AccountAclService $accountAclService,
CategoryService $categoryService,
ClientService $clientService,
CustomFieldDataService $customFieldService,
UserService $userService,
UserGroupService $userGroupService,
TagService $tagService
Application $application,
TemplateInterface $template,
RequestInterface $request,
AclInterface $acl,
AccountService $accountService,
AccountHistoryService $accountHistoryService,
PublicLinkService $publicLinkService,
ItemPresetService $itemPresetService,
MasterPassService $masterPassService,
AccountActionsHelper $accountActionsHelper,
AccountAclService $accountAclService,
CategoryService $categoryService,
ClientService $clientService,
CustomFieldDataService $customFieldService,
UserService $userService,
UserGroupService $userGroupService,
TagService $tagService,
private readonly UriContextInterface $uriContext
) {
parent::__construct($application, $template, $request, $acl, $accountActionsHelper, $masterPassService);
@@ -222,7 +223,8 @@ final class AccountHelper extends AccountHelperBase
$accountActionsDto->setPublicLinkId($publicLinkData->getId());
$accountActionsDto->setPublicLinkCreatorId($publicLinkData->getUserId());
$baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI) . BootstrapBase::$SUBURI;
$baseUrl = ($this->configData->getApplicationUrl() ?: $this->uriContext->getWebUri()) .
$this->uriContext->getSubUri();
$this->view->assign(
'publicLinkUrl',
@@ -375,9 +377,12 @@ final class AccountHelper extends AccountHelperBase
$this->view->assign('accountAcl', $this->accountAcl);
if ($this->accountId) {
$baseUrl = ($this->configData->getApplicationUrl() ?? $this->uriContext->getWebUri()) .
$this->uriContext->getSubUri();
$this->view->assign(
'deepLink',
Link::getDeepLink($this->accountId, $this->actionId, $this->configData)
Link::getDeepLink($this->accountId, $this->actionId, $this->configData, $baseUrl)
);
}
}

View File

@@ -28,7 +28,7 @@ use SP\Core\Application;
use SP\Core\Events\EventDispatcher;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Config\Services\ConfigFile;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Http\RequestInterface;
use SP\Http\Request;
use SP\Mvc\View\TemplateInterface;
@@ -42,7 +42,7 @@ abstract class HelperBase
{
protected TemplateInterface $view;
protected ConfigDataInterface $configData;
protected ContextInterface $context;
protected Context $context;
protected EventDispatcher $eventDispatcher;
protected ConfigFile $config;
protected Request $request;

View File

@@ -26,11 +26,11 @@ namespace SP\Modules\Web\Controllers\Helpers;
use SP\Core\Acl\Acl;
use SP\Core\Application;
use SP\Core\Bootstrap\BootstrapBase;
use SP\Core\Language;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Acl\AclInterface;
use SP\Domain\Core\AppInfoInterface;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Core\Crypt\CryptPKIInterface;
use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Core\UI\ThemeInterface;
@@ -43,6 +43,9 @@ use SP\Plugin\PluginManager;
use SP\Util\FileUtil;
use SP\Util\VersionUtil;
use function SP\__;
use function SP\processException;
/**
* Class LayoutHelper
*
@@ -52,22 +55,21 @@ final class LayoutHelper extends HelperBase
{
private ThemeInterface $theme;
private CryptPKIInterface $cryptPKI;
private PluginManager $pluginManager;
private bool $loggedIn;
public function __construct(
Application $application,
TemplateInterface $template,
RequestInterface $request,
ThemeInterface $theme,
CryptPKIInterface $cryptPKI,
PluginManager $pluginManager
Application $application,
TemplateInterface $template,
RequestInterface $request,
ThemeInterface $theme,
CryptPKIInterface $cryptPKI,
private readonly UriContextInterface $uriContext,
private readonly AclInterface $acl
) {
parent::__construct($application, $template, $request);
$this->theme = $theme;
$this->cryptPKI = $cryptPKI;
$this->pluginManager = $pluginManager;
$this->loggedIn = $this->context->isLoggedIn();
$this->view->assign('loggedIn', $this->loggedIn);
@@ -113,7 +115,7 @@ final class LayoutHelper extends HelperBase
*/
public function initBody(): void
{
$baseUrl = $this->configData->getApplicationUrl() ?? BootstrapBase::$WEBURI;
$baseUrl = $this->configData->getApplicationUrl() ?? $this->uriContext->getWebUri();
$this->view->assign('isInstalled', $this->configData->isInstalled());
$this->view->assign('app_name', AppInfoInterface::APP_NAME);
@@ -125,7 +127,7 @@ final class LayoutHelper extends HelperBase
$this->view->assign('logo_no_bg_color', $baseUrl . '/public/images/logo_full_nobg_outline_color.png');
$this->view->assign('logo_no_bg', $baseUrl . '/public/images/logo_full_nobg_outline.png');
$this->view->assign('httpsEnabled', $this->request->isHttps());
$this->view->assign('homeRoute', Acl::getActionRoute(AclActionsInterface::ACCOUNT));
$this->view->assign('homeRoute', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT));
$this->loggedIn = $this->context->isLoggedIn();
@@ -150,7 +152,8 @@ final class LayoutHelper extends HelperBase
protected function getResourcesLinks(): void
{
$version = VersionUtil::getVersionStringNormalized();
$baseUrl = ($this->configData->getApplicationUrl() ?? BootstrapBase::$WEBURI) . BootstrapBase::$SUBURI;
$baseUrl = ($this->configData->getApplicationUrl() ?? $this->uriContext->getWebUri()) .
$this->uriContext->getSubUri();
$jsUriApp = new Uri($baseUrl);
$jsUriApp->addParams(['_r' => 'resource/js', '_v' => sha1($version)]);
@@ -234,10 +237,11 @@ final class LayoutHelper extends HelperBase
if (count($cssResources) > 0) {
$cssUriPlugin = new Uri($baseUrl);
$cssUriPlugin->addParams([
'b' => FileUtil::buildPath($base, 'css'),
'f' => implode(',', $cssResources)
]
$cssUriPlugin->addParams(
[
'b' => FileUtil::buildPath($base, 'css'),
'f' => implode(',', $cssResources)
]
);
$this->view->append('cssLinks', $cssUriPlugin->getUriSigned($this->configData->getPasswordSalt()));

View File

@@ -27,7 +27,6 @@ namespace SP\Modules\Web\Controllers\Login;
use Exception;
use JsonException;
use SP\Core\Application;
use SP\Core\Bootstrap\BootstrapBase;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Domain\Auth\Ports\LoginService;
@@ -49,7 +48,7 @@ final class LoginController extends ControllerBase
private Login $loginService;
public function __construct(
Application $application,
Application $application,
WebControllerHelper $webControllerHelper,
LoginService $loginService
) {
@@ -74,7 +73,7 @@ final class LoginController extends ControllerBase
$this->checkForwarded();
$redirector = function ($route) use ($from) {
$uri = new Uri(ltrim(BootstrapBase::$SUBURI, '/'));
$uri = new Uri(ltrim($this->uriContext->getSubUri(), '/'));
$uri->addParam('r', $route);
if ($from !== null) {

View File

@@ -31,7 +31,8 @@ use SP\Core\PhpExtensionChecker;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Config\Services\ConfigFile;
use SP\Domain\Core\Acl\UnauthorizedPageException;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Exceptions\SessionTimeout;
use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Core\UI\ThemeInterface;
@@ -41,21 +42,20 @@ use SP\Mvc\Controller\SimpleControllerHelper;
/**
* Class SimpleControllerBase
*
* @package SP\Modules\Web\Controllers
*/
abstract class SimpleControllerBase
{
use WebControllerTrait;
protected EventDispatcher $eventDispatcher;
protected ConfigFile $config;
protected ContextInterface $session;
protected ThemeInterface $theme;
protected Acl $acl;
protected Request $request;
protected PhpExtensionChecker $extensionChecker;
protected ConfigDataInterface $configData;
protected readonly EventDispatcher $eventDispatcher;
protected readonly ConfigFile $config;
protected readonly Context $session;
protected readonly ThemeInterface $theme;
protected readonly Acl $acl;
protected readonly Request $request;
protected readonly PhpExtensionChecker $extensionChecker;
protected readonly ConfigDataInterface $configData;
protected readonly UriContextInterface $uriContext;
/**
* @throws SessionTimeout
@@ -69,6 +69,7 @@ abstract class SimpleControllerBase
$this->acl = $simpleControllerHelper->getAcl();
$this->request = $simpleControllerHelper->getRequest();
$this->extensionChecker = $simpleControllerHelper->getExtensionChecker();
$this->uriContext = $simpleControllerHelper->getUriContext();
$this->controllerName = $this->getControllerName();
$this->config = $application->getConfig();
$this->configData = $this->config->getConfigData();
@@ -94,7 +95,6 @@ abstract class SimpleControllerBase
throw new SessionTimeout();
}
// $this->checkSecurityToken($this->session, $this->request);
}

View File

@@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers\Traits;
use Exception;
use Klein\Klein;
use SP\Core\Context\SessionContext;
use SP\Core\Context\Session;
use SP\Domain\Core\Exceptions\SPException;
use SP\Http\JsonMessage;
use SP\Http\JsonResponse;
@@ -34,7 +34,7 @@ use SP\Http\JsonResponse;
/**
* Trait JsonTrait
*
* @property SessionContext $session
* @property Session $session
* @property Klein $router
*/
trait JsonTrait

View File

@@ -29,7 +29,7 @@ use JsonException;
use SP\Core\Application;
use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Core\Exceptions\ValidationException;
use SP\Domain\Persistence\Ports\UpgradeDatabaseService;
use SP\Domain\Persistence\Ports\UpgradeServiceDatabaseService;
use SP\Domain\Upgrade\Services\UpgradeAppService;
use SP\Domain\Upgrade\Services\UpgradeDatabaseService;
use SP\Domain\Upgrade\Services\UpgradeException;
@@ -48,14 +48,14 @@ final class UpgradeController extends ControllerBase
{
use JsonTrait;
private UpgradeDatabaseService $upgradeDatabaseService;
private UpgradeAppService $upgradeAppService;
private UpgradeServiceDatabaseService $upgradeDatabaseService;
private UpgradeAppService $upgradeAppService;
public function __construct(
Application $application,
WebControllerHelper $webControllerHelper,
UpgradeDatabaseService $upgradeDatabaseService,
UpgradeAppService $upgradeAppService
Application $application,
WebControllerHelper $webControllerHelper,
UpgradeServiceDatabaseService $upgradeDatabaseService,
UpgradeAppService $upgradeAppService
) {
parent::__construct($application, $webControllerHelper);
@@ -114,7 +114,7 @@ final class UpgradeController extends ControllerBase
$dbVersion = $this->configData->getDatabaseVersion();
$dbVersion = empty($dbVersion) ? '0.0' : $dbVersion;
if (UpgradeDatabaseService::needsUpgrade($dbVersion)) {
if (UpgradeServiceDatabaseService::needsUpgrade($dbVersion)) {
$this->upgradeDatabaseService->upgrade($dbVersion, $this->configData);
}
}

View File

@@ -27,7 +27,7 @@ namespace SP\Modules\Web\Forms;
use SP\Core\Application;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Config\Services\ConfigFile;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Http\RequestInterface;
/**
@@ -39,7 +39,7 @@ abstract class FormBase
{
protected ConfigFile $config;
protected ConfigDataInterface $configData;
protected ContextInterface $context;
protected Context $context;
/**
* FormBase constructor.

View File

@@ -31,7 +31,7 @@ use Klein\Klein;
use SP\Core\Application;
use SP\Core\Bootstrap\BootstrapBase;
use SP\Core\Context\ContextBase;
use SP\Core\Context\SessionContext;
use SP\Core\Context\Session;
use SP\Core\Crypt\CryptSessionHandler;
use SP\Core\Crypt\Csrf;
use SP\Core\Crypt\Session as CryptSession;
@@ -54,8 +54,6 @@ use SP\Domain\Crypt\Services\SecureSession;
use SP\Domain\Http\RequestInterface;
use SP\Domain\ItemPreset\Ports\ItemPresetInterface;
use SP\Domain\ItemPreset\Services\ItemPreset;
use SP\Domain\Upgrade\Services\UpgradeAppService;
use SP\Domain\Upgrade\Services\UpgradeDatabaseService;
use SP\Domain\Upgrade\Services\UpgradeUtil;
use SP\Domain\User\Ports\UserProfileService;
use SP\Domain\User\Services\UserProfile;
@@ -82,7 +80,6 @@ use SP\Modules\Web\Controllers\Status\StatusController;
use SP\Modules\Web\Controllers\Task\TrackStatusController;
use SP\Modules\Web\Controllers\Upgrade\IndexController as UpgradeIndexController;
use SP\Modules\Web\Controllers\Upgrade\UpgradeController;
use SP\Plugin\PluginManager;
use SP\Util\HttpUtil;
use function SP\logger;
@@ -136,14 +133,14 @@ final class Init extends HttpModuleBase
public const ROUTE_UPGRADE = 'upgrade';
private Csrf $csrf;
private Csrf $csrf;
private Language $language;
private SecureSession $secureSessionService;
private PluginManager $pluginManager;
private ItemPreset $itemPresetService;
private DatabaseUtil $databaseUtil;
private UserProfile $userProfileService;
private bool $isIndex = false;
private UserProfile $userProfileService;
private bool $isIndex = false;
public function __construct(
Application $application,
@@ -298,7 +295,7 @@ final class Init extends HttpModuleBase
// Do not keep the PHP's session opened
if (!in_array($controller, self::NO_SESSION_CLOSE, true)) {
SessionContext::close();
Session::close();
}
}
@@ -373,7 +370,7 @@ final class Init extends HttpModuleBase
$this->router->response()->cookie(session_name(), '', time() - 42000);
}
SessionContext::restart();
Session::restart();
} else {
$sidStartTime = $this->context->getSidStartTime();
@@ -382,7 +379,7 @@ final class Init extends HttpModuleBase
// Try to set PHP's session lifetime
@ini_set('session.gc_maxlifetime', $this->getSessionLifeTime());
} elseif (!$inMaintenance
&& time() > ($sidStartTime + SessionContext::MAX_SID_TIME)
&& time() > ($sidStartTime + Session::MAX_SID_TIME)
&& $this->context->isLoggedIn()
) {
try {
@@ -390,7 +387,7 @@ final class Init extends HttpModuleBase
} catch (CryptException $e) {
logger($e->getMessage());
SessionContext::restart();
Session::restart();
return;
}

View File

@@ -31,7 +31,7 @@ use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Acl\AclInterface;
use SP\Domain\Core\Acl\ActionNotFoundException;
use SP\Domain\Core\Acl\ActionsInterface;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Events\EventDispatcherInterface;
use function SP\__;
@@ -50,9 +50,9 @@ final class Acl implements AclActionsInterface, AclInterface
private ActionsInterface $actions;
public function __construct(
private readonly ContextInterface $context,
private readonly Context $context,
private readonly EventDispatcherInterface $eventDispatcher,
ActionsInterface $actions
ActionsInterface $actions
) {
self::$actionsStatic = $actions;
$this->actions = $actions;

View File

@@ -25,26 +25,26 @@
namespace SP\Core;
use SP\Domain\Config\Ports\ConfigFileService;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\SessionContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Context\SessionContext;
use SP\Domain\Core\Events\EventDispatcherInterface;
/**
* The Application helper class. It holds all the needed dependencies for the application
*/
final class Application
final readonly class Application
{
/**
* Module constructor.
*
* @param ConfigFileService $config
* @param EventDispatcherInterface $eventDispatcher
* @param SessionContextInterface|ContextInterface $context
* @param SessionContext|Context $context
*/
public function __construct(
private readonly ConfigFileService $config,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly SessionContextInterface|ContextInterface $context
private ConfigFileService $config,
private EventDispatcherInterface $eventDispatcher,
private SessionContext|Context $context
) {
}
@@ -58,7 +58,7 @@ final class Application
return $this->eventDispatcher;
}
public function getContext(): ContextInterface|SessionContextInterface
public function getContext(): Context|SessionContext
{
return $this->context;
}

View File

@@ -24,7 +24,6 @@
namespace SP\Core\Bootstrap;
use Closure;
use Klein\Klein;
use Klein\Request;
use Klein\Response;
@@ -39,16 +38,12 @@ use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Config\Services\ConfigUtil;
use SP\Domain\Core\Bootstrap\BootstrapInterface;
use SP\Domain\Core\Bootstrap\ModuleInterface;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Exceptions\CheckException;
use SP\Domain\Core\Exceptions\ConfigException;
use SP\Domain\Core\Exceptions\InitializationException;
use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Http\RequestInterface;
use SP\Domain\Upgrade\Services\UpgradeException;
use SP\Infrastructure\File\FileException;
use SP\Plugin\PluginManager;
use SP\Util\Checks;
use Symfony\Component\Debug\Debug;
use Throwable;
@@ -66,38 +61,17 @@ abstract class BootstrapBase implements BootstrapInterface
public const CONTEXT_ACTION_NAME = "_actionName";
protected const OOPS_MESSAGE = "Oops, it looks like this content does not exist...";
/**
* @deprecated Use {@see UriContextInterface::getWebRoot()} instead
* @var string The current request path relative to the sysPass root (e.g. files/index.php)
*/
public static string $WEBROOT = '';
/**
* @deprecated Use {@see UriContextInterface::getWebUri()} instead
* @var string The full URL to reach sysPass (e.g. https://sub.example.com/syspass/)
*/
public static string $WEBURI = '';
/**
* @deprecated Use {@see UriContextInterface::getSubUri()} instead
*/
public static string $SUBURI = '';
/**
* @var mixed
*/
public static $LOCK;
public static bool $checkPhpVersion = false;
public static mixed $LOCK;
public static bool $checkPhpVersion = false;
/**
* Bootstrap constructor.
*/
final public function __construct(
protected readonly ConfigDataInterface $configData,
protected readonly Klein $router,
protected readonly RequestInterface $request,
private readonly UpgradeConfigChecker $upgradeConfigChecker,
protected readonly PhpExtensionChecker $extensionChecker,
protected readonly ContextInterface $context,
protected readonly Context $context,
private readonly ContainerInterface $container,
protected readonly UriContextInterface $uriContext,
protected readonly Response $response,
) {
// Set the default language
@@ -118,17 +92,16 @@ abstract class BootstrapBase implements BootstrapInterface
);
// Manage requests for options
$this->router->respond('OPTIONS', null, $this->manageCorsRequest());
}
$this->router->respond(
'OPTIONS',
null,
function ($request, $response) {
/** @var Request $request */
/** @var Response $response */
private function manageCorsRequest(): Closure
{
return function ($request, $response) {
/** @var Request $request */
/** @var Response $response */
$this->setCors($response);
};
$this->setCors($response);
}
);
}
final protected function setCors(Response $response): void
@@ -148,15 +121,6 @@ abstract class BootstrapBase implements BootstrapInterface
abstract public static function run(BootstrapInterface $bootstrap, ModuleInterface $initModule): void;
/**
* @deprecated
* FIXME: delete
*/
public static function getContainer()
{
return null;
}
final protected static function getClassFor(string $controllerName, string $actionName): string
{
return sprintf(
@@ -180,8 +144,8 @@ abstract class BootstrapBase implements BootstrapInterface
/**
* @throws CheckException
* @throws ConfigException
* @throws FileException
* @throws InitializationException
* @throws UpgradeException
*/
final protected function initializeCommon(): void
{
@@ -198,9 +162,8 @@ abstract class BootstrapBase implements BootstrapInterface
$this->extensionChecker->checkMandatory();
if (!self::$checkPhpVersion) {
throw new InitializationException(
sprintf(__('Required PHP version >= %s <= %s'), '8.1', '8.2'),
SPException::ERROR,
throw InitializationException::error(
sprintf(__('Required PHP version >= %s <= %s'), '8.2', '8.3'),
__u('Please update the PHP version to run sysPass')
);
}
@@ -217,32 +180,16 @@ abstract class BootstrapBase implements BootstrapInterface
$server = $this->router->request()->server();
// Copiar la cabecera http de autentificación para apache+php-fcgid
if ($server->get('HTTP_XAUTHORIZATION') !== null
&& $server->get('HTTP_AUTHORIZATION') === null
) {
if ($server->get('HTTP_XAUTHORIZATION') !== null && $server->get('HTTP_AUTHORIZATION') === null) {
$server->set('HTTP_AUTHORIZATION', $server->get('HTTP_XAUTHORIZATION'));
}
// Establecer las cabeceras de autentificación para apache+php-cgi
// Establecer las cabeceras de autentificación para que apache+php-cgi funcione si la variable es renombrada por apache
if (($server->get('HTTP_AUTHORIZATION') !== null
&& preg_match(
'/Basic\s+(.*)$/i',
$server->get('HTTP_AUTHORIZATION'),
$matches
))
|| ($server->get('REDIRECT_HTTP_AUTHORIZATION') !== null
&& preg_match(
'/Basic\s+(.*)$/i',
$server->get('REDIRECT_HTTP_AUTHORIZATION'),
$matches
))
) {
[$name, $password] = explode(
':',
base64_decode($matches[1]),
2
);
// Establecer las cabeceras de autentificación para que apache+php-cgi funcione si la variable
// es renombrada por apache
$authorization = $server->get('HTTP_AUTHORIZATION') ?? $server->get('REDIRECT_HTTP_AUTHORIZATION', '');
if (preg_match('/Basic\s+(.*)$/i', $authorization, $matches)) {
[$name, $password] = explode(':', base64_decode($matches[1]), 2);
$server->set('PHP_AUTH_USER', strip_tags($name));
$server->set('PHP_AUTH_PW', strip_tags($password));
@@ -296,11 +243,6 @@ abstract class BootstrapBase implements BootstrapInterface
ConfigUtil::checkConfigDir();
}
final protected function initializePluginClasses(): void
{
PluginManager::getPlugins();
}
/**
* @deprecated
* FIXME: delete

View File

@@ -30,11 +30,11 @@ use SP\Domain\Http\RequestInterface;
/**
* Class UriContext
*/
final class UriContext implements UriContextInterface
final readonly class UriContext implements UriContextInterface
{
private readonly string $subUri;
private readonly string $webRoot;
private readonly string $webUri;
private string $subUri;
private string $webRoot;
private string $webUri;
public function __construct(RequestInterface $request)
{

View File

@@ -24,7 +24,7 @@
namespace SP\Core\Context;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use function SP\__u;
@@ -33,7 +33,7 @@ use function SP\__u;
*
* @package SP\Core\Session
*/
abstract class ContextBase implements ContextInterface
abstract class ContextBase implements Context
{
public const APP_STATUS_RELOADED = 'reloaded';
public const APP_STATUS_LOGGEDOUT = 'loggedout';

View File

@@ -24,18 +24,18 @@
namespace SP\Core\Context;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\SessionContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Context\SessionContext;
/**
* ContextFactory
*/
final class ContextFactory
{
public static function getForModule(string $module): ContextInterface|SessionContextInterface
public static function getForModule(string $module): Context|SessionContext
{
if ($module === 'web') {
return new SessionContext();
return new Session();
}
return new StatelessContext();

View File

@@ -27,7 +27,7 @@ namespace SP\Core\Context;
use SP\DataModel\ProfileData;
use SP\Domain\Account\Dtos\AccountCacheDto;
use SP\Domain\Account\Dtos\AccountSearchFilterDto;
use SP\Domain\Core\Context\SessionContextInterface;
use SP\Domain\Core\Context\SessionContext;
use SP\Domain\Core\Crypt\VaultInterface;
use SP\Domain\User\Dtos\UserDataDto;
@@ -38,10 +38,8 @@ use function SP\processException;
/**
* Class Session
*
* @package SP\Core\Session
*/
class SessionContext extends ContextBase implements SessionContextInterface
class Session extends ContextBase implements SessionContext
{
public const MAX_SID_TIME = 120;

View File

@@ -24,26 +24,21 @@
namespace SP\Core\Crypt;
use SP\Core\Bootstrap\BootstrapBase;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Http\RequestInterface;
use function SP\logger;
/**
* Class Cookie
*
* @package SP\Core\Crypt
*/
abstract class Cookie
{
/**
* Cookie constructor.
*
* @param string $cookieName
* @param RequestInterface $request
*/
protected function __construct(private readonly string $cookieName, protected readonly RequestInterface $request)
{
protected function __construct(
private readonly string $cookieName,
protected readonly RequestInterface $request,
private readonly UriContextInterface $uriContext
) {
}
/**
@@ -106,6 +101,6 @@ abstract class Cookie
return false;
}
return setcookie($this->cookieName, $data, 0, BootstrapBase::$WEBROOT);
return setcookie($this->cookieName, $data, 0, $this->uriContext->getWebRoot());
}
}

View File

@@ -25,7 +25,7 @@
namespace SP\Core\Crypt;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\Context\SessionContextInterface;
use SP\Domain\Core\Context\SessionContext;
use SP\Domain\Core\Crypt\CsrfInterface;
use SP\Domain\Http\Method;
use SP\Domain\Http\RequestInterface;
@@ -41,9 +41,9 @@ class Csrf implements CsrfInterface
{
public function __construct(
private readonly SessionContextInterface $context,
private readonly RequestInterface $request,
private readonly ConfigDataInterface $configData
private readonly SessionContext $context,
private readonly RequestInterface $request,
private readonly ConfigDataInterface $configData
) {
}

View File

@@ -24,7 +24,7 @@
namespace SP\Core\Crypt;
use SP\Domain\Core\Context\SessionContextInterface;
use SP\Domain\Core\Context\SessionContext;
use SP\Domain\Core\Exceptions\CryptException;
use function SP\logger;
@@ -41,12 +41,12 @@ class Session
*
* @throws CryptException
*/
public static function getSessionKey(SessionContextInterface $sessionContext): string
public static function getSessionKey(SessionContext $sessionContext): string
{
return $sessionContext->getVault()->getData(self::getKey($sessionContext));
}
private static function getKey(SessionContextInterface $sessionContext): string
private static function getKey(SessionContext $sessionContext): string
{
return session_id() . $sessionContext->getSidStartTime();
}
@@ -56,7 +56,7 @@ class Session
*
* @throws CryptException
*/
public static function saveSessionKey(string $data, SessionContextInterface $sessionContext): void
public static function saveSessionKey(string $data, SessionContext $sessionContext): void
{
$sessionContext->setVault(Vault::factory(new Crypt())->saveData($data, self::getKey($sessionContext)));
}
@@ -66,7 +66,7 @@ class Session
*
* @throws CryptException
*/
public static function reKey(SessionContextInterface $sessionContext): void
public static function reKey(SessionContext $sessionContext): void
{
logger(__METHOD__);

View File

@@ -24,13 +24,12 @@
namespace SP\Core\Crypt;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Core\Crypt\UuidCookieInterface;
use SP\Domain\Http\RequestInterface;
/**
* Class UuidCookie
*
* @package SP\Core\Crypt
*/
class UuidCookie extends Cookie implements UuidCookieInterface
{
@@ -39,9 +38,9 @@ class UuidCookie extends Cookie implements UuidCookieInterface
*/
public const COOKIE_NAME = 'SYSPASS_UUID';
public static function factory(RequestInterface $request): UuidCookie
public static function factory(RequestInterface $request, UriContextInterface $uriContext): UuidCookie
{
return new self(self::COOKIE_NAME, $request);
return new self(self::COOKIE_NAME, $request, $uriContext);
}
/**

View File

@@ -55,7 +55,7 @@ use SP\Domain\Config\Services\ConfigBackup;
use SP\Domain\Config\Services\ConfigFile;
use SP\Domain\Core\Acl\ActionsInterface;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Crypt\CryptInterface;
use SP\Domain\Core\Crypt\CryptPKIInterface;
use SP\Domain\Core\Crypt\RequestBasedPasswordInterface;
@@ -129,14 +129,14 @@ final class CoreDefinitions
KleinResponse::class => create(KleinResponse::class),
RequestInterface::class => autowire(Request::class),
UriContextInterface::class => autowire(UriContext::class),
ContextInterface::class =>
Context::class =>
static fn() => ContextFactory::getForModule(APP_MODULE),
ConfigFileService::class => create(ConfigFile::class)
->constructor(
create(XmlFileStorage::class)
->constructor(create(FileHandler::class)->constructor(CONFIG_FILE)),
create(FileCache::class)->constructor(ConfigFile::CONFIG_CACHE_FILE),
get(ContextInterface::class),
get(Context::class),
autowire(ConfigBackup::class)
),
ConfigDataInterface::class => factory([ConfigFileService::class, 'getConfigData']),

View File

@@ -25,7 +25,7 @@
namespace SP\Core;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\LanguageInterface;
use SP\Domain\Http\RequestInterface;
@@ -77,7 +77,7 @@ final class Language implements LanguageInterface
];
public function __construct(
private readonly ContextInterface $context,
private readonly Context $context,
private readonly ConfigDataInterface $configData,
private readonly RequestInterface $request
) {

View File

@@ -26,7 +26,6 @@ namespace SP\Core;
use SP\Domain\Core\File\MimeType;
use SP\Domain\Core\File\MimeTypesService;
use SP\Domain\Storage\Ports\FileCacheInterface;
use SP\Domain\Storage\Ports\FileCacheService;
use SP\Domain\Storage\Ports\XmlFileStorageService;
use SP\Infrastructure\File\FileException;

View File

@@ -27,7 +27,7 @@ namespace SP\Core;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Config\Services\ConfigFile;
use SP\Domain\Core\Bootstrap\ModuleInterface;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Events\EventDispatcherInterface;
/**
@@ -37,7 +37,7 @@ abstract class ModuleBase implements ModuleInterface
{
protected ConfigFile $config;
protected ConfigDataInterface $configData;
protected ContextInterface $context;
protected Context $context;
private EventDispatcherInterface $eventDispatcher;
/**

View File

@@ -24,7 +24,6 @@
namespace SP\Core;
use SP\Providers\Acl\AclHandler;
use SP\Providers\Log\DatabaseLogHandler;
use SP\Providers\Log\FileLogHandler;
@@ -37,17 +36,17 @@ use SP\Providers\ProviderInterface;
/**
* The Provider helper class will have oll the providers availabe in the application
*/
final class ProvidersHelper
final readonly class ProvidersHelper
{
public function __construct(
private readonly FileLogHandler $fileLogHandler,
private readonly ?DatabaseLogHandler $databaseLogHandler = null,
private readonly ?MailHandler $mailHandler = null,
private readonly ?SyslogHandler $syslogHandler = null,
private readonly ?RemoteSyslogHandler $remoteSyslogHandler = null,
private readonly ?AclHandler $aclHandler = null,
private readonly ?NotificationHandler $notificationHandler = null
private FileLogHandler $fileLogHandler,
private ?DatabaseLogHandler $databaseLogHandler = null,
private ?MailHandler $mailHandler = null,
private ?SyslogHandler $syslogHandler = null,
private ?RemoteSyslogHandler $remoteSyslogHandler = null,
private ?AclHandler $aclHandler = null,
private ?NotificationHandler $notificationHandler = null
) {
}

View File

@@ -25,7 +25,7 @@
namespace SP\Core\UI;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Exceptions\InvalidClassException;
use SP\Domain\Core\UI\ThemeContextInterface;
use SP\Domain\Core\UI\ThemeIconsInterface;
@@ -48,7 +48,7 @@ final class Theme implements ThemeInterface
) {
}
public static function getThemeName(ConfigDataInterface $configData, ContextInterface $context): ?string
public static function getThemeName(ConfigDataInterface $configData, Context $context): ?string
{
$name = $configData->getSiteTheme();

View File

@@ -25,7 +25,7 @@
namespace SP\Core\UI;
use SP\Core\Context\ContextBase;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Exceptions\InvalidClassException;
use SP\Domain\Core\UI\ThemeContextInterface;
use SP\Domain\Core\UI\ThemeIconsInterface;
@@ -53,7 +53,7 @@ final class ThemeIcons implements ThemeIconsInterface
private array $icons = [];
/**
* @param ContextInterface $context
* @param Context $context
* @param FileCacheService $cache
* @param ThemeContextInterface $themeContext
* @return ThemeIconsInterface
@@ -61,7 +61,7 @@ final class ThemeIcons implements ThemeIconsInterface
* @throws FileException
*/
public static function loadIcons(
ContextInterface $context,
Context $context,
FileCacheService $cache,
ThemeContextInterface $themeContext
): ThemeIconsInterface {

View File

@@ -54,10 +54,11 @@ final class Account extends Adapter implements AccountAdapter
public function __construct(
ConfigDataInterface $configData,
string $baseUrl,
private readonly CustomFieldDataService $customFieldService,
private readonly ActionsInterface $actions
) {
parent::__construct($configData);
parent::__construct($configData, $baseUrl);
}
/**
@@ -74,7 +75,7 @@ final class Account extends Adapter implements AccountAdapter
$accountEnrichedDto->getId(),
$this->customFieldService
),
new CustomField($this->configData)
new CustomField($this->configData, $this->baseUrl)
);
}
@@ -127,7 +128,7 @@ final class Account extends Adapter implements AccountAdapter
$account->getId(),
$actionRoute,
$this->configData,
true
$this->baseUrl
),
],
],

View File

@@ -24,12 +24,12 @@
namespace SP\Domain\Account\Adapters;
use SP\Core\Bootstrap\BootstrapBase;
use SP\DataModel\Item;
use SP\Domain\Account\Models\AccountSearchView;
use SP\Domain\Account\Services\PublicLink;
use SP\Domain\Common\Dtos\ItemDataTrait;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Html\Html;
/**
@@ -53,11 +53,12 @@ final class AccountSearchItem
protected AccountSearchView $accountSearchView,
private readonly AccountPermission $accountAcl,
private readonly ConfigDataInterface $configData,
private readonly UriContextInterface $uriContext,
private array $tags,
private int $textMaxLength = 0,
private bool $favorite = false,
private ?array $users = null,
private ?array $userGroups = null,
private readonly ?array $users = null,
private readonly ?array $userGroups = null,
private ?string $color = null,
private ?string $link = null,
) {
@@ -137,7 +138,8 @@ final class AccountSearchItem
if (self::$publicLinkEnabled
&& $this->accountSearchView->getPublicLinkHash() !== null
) {
$baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI) . BootstrapBase::$SUBURI;
$baseUrl = ($this->configData->getApplicationUrl() ?: $this->uriContext->getWebUri()) .
$this->uriContext->getSubUri();
return PublicLink::getLinkForHash($baseUrl, $this->accountSearchView->getPublicLinkHash());
}

View File

@@ -30,7 +30,7 @@ use SP\DataModel\ProfileData;
use SP\Domain\Account\Ports\AccountFilterBuilder;
use SP\Domain\Account\Ports\AccountSearchConstants;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\User\Dtos\UserDataDto;
/**
@@ -40,7 +40,7 @@ final class AccountFilter implements AccountFilterBuilder
{
public function __construct(
private readonly ContextInterface $context,
private readonly Context $context,
private readonly ConfigDataInterface $configData,
private readonly QueryFactory $queryFactory
) {

View File

@@ -36,6 +36,7 @@ use SP\Domain\Account\Ports\AccountToTagRepository;
use SP\Domain\Common\Services\Service;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
use SP\Domain\Core\Exceptions\SPException;
@@ -82,7 +83,8 @@ final class AccountSearchData extends Service implements AccountSearchDataBuilde
private readonly AccountToFavoriteService $accountToFavoriteService,
private readonly AccountCacheService $accountCacheService,
private readonly FileCacheService $fileCache,
private readonly ConfigDataInterface $configData
private readonly ConfigDataInterface $configData,
private readonly UriContextInterface $uriContext,
) {
parent::__construct($application);
@@ -156,6 +158,7 @@ final class AccountSearchData extends Service implements AccountSearchDataBuilde
$accountSearchView,
$accountAcl,
$this->configData,
$this->uriContext,
$tags,
$maxTextLength,
isset($favorites[$accountSearchView->getId()]),

View File

@@ -38,7 +38,7 @@ use SP\Domain\Auth\Ports\AuthTokenService;
use SP\Domain\Auth\Services\AuthToken;
use SP\Domain\Common\Services\Service;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Crypt\VaultInterface;
use SP\Domain\Core\Exceptions\CryptException;
use SP\Domain\Core\Exceptions\InvalidArgumentException;
@@ -235,7 +235,7 @@ final class Api extends Service implements ApiService
*/
public function requireMasterPass(): void
{
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, $this->getMasterPassFromVault());
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, $this->getMasterPassFromVault());
}
/**

View File

@@ -53,10 +53,11 @@ final class Category extends Adapter implements CategoryAdapter
public function __construct(
ConfigDataInterface $configData,
string $baseUrl,
private readonly CustomFieldDataService $customFieldService,
private readonly ActionsInterface $actions
) {
parent::__construct($configData);
parent::__construct($configData, $baseUrl);
}
/**
@@ -69,7 +70,7 @@ final class Category extends Adapter implements CategoryAdapter
{
return $this->collection(
$this->getCustomFieldsForItem(AclActionsInterface::CATEGORY, $data->id, $this->customFieldService),
new CustomField($this->configData)
new CustomField($this->configData, $this->baseUrl)
);
}
@@ -92,7 +93,7 @@ final class Category extends Adapter implements CategoryAdapter
$data->getId(),
$actionRoute,
$this->configData,
true
$this->baseUrl
),
],
],

View File

@@ -58,7 +58,7 @@ final class Client extends Adapter implements ClientAdapter
{
return $this->collection(
$this->getCustomFieldsForItem(AclActionsInterface::CLIENT, $client->getId(), $customFieldService),
new CustomField($this->configData)
new CustomField($this->configData, $this->baseUrl)
);
}
@@ -77,7 +77,7 @@ final class Client extends Adapter implements ClientAdapter
$data->getId(),
AclActionsInterface::CLIENT_VIEW,
$this->configData,
true
$this->baseUrl
),
],
],

View File

@@ -34,8 +34,10 @@ use SP\Domain\Config\Ports\ConfigDataInterface;
*/
abstract class Adapter extends TransformerAbstract
{
public function __construct(protected readonly ConfigDataInterface $configData)
{
public function __construct(
protected readonly ConfigDataInterface $configData,
protected readonly string $baseUrl
) {
}
abstract public function transform(Model&Dto $data);

View File

@@ -27,10 +27,10 @@ namespace SP\Domain\Common\Services;
use Defuse\Crypto\Exception\CryptoException;
use SP\Core\Application;
use SP\Core\Context\ContextException;
use SP\Core\Context\SessionContext;
use SP\Core\Crypt\Session;
use SP\Core\Context\Session as SessionContext;
use SP\Core\Crypt\Session as CryptSession;
use SP\Domain\Config\Ports\ConfigFileService;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Events\EventDispatcherInterface;
use SP\Domain\Core\Exceptions\CryptException;
@@ -47,7 +47,7 @@ abstract class Service
protected const STATUS_INTERNAL_ERROR = 1000;
protected readonly ConfigFileService $config;
protected readonly ContextInterface $context;
protected readonly Context $context;
protected readonly EventDispatcherInterface $eventDispatcher;
public function __construct(Application $application)
@@ -65,9 +65,9 @@ abstract class Service
{
try {
if ($this->context instanceof SessionContext) {
$key = Session::getSessionKey($this->context);
$key = CryptSession::getSessionKey($this->context);
} else {
$key = $this->context->getTrasientKey(ContextInterface::MASTER_PASSWORD_KEY);
$key = $this->context->getTrasientKey(Context::MASTER_PASSWORD_KEY);
}
if (empty($key)) {
@@ -90,7 +90,7 @@ abstract class Service
{
try {
if ($this->context instanceof SessionContext) {
Session::saveSessionKey($masterPass, $this->context);
CryptSession::saveSessionKey($masterPass, $this->context);
} else {
$this->context->setTrasientKey('_masterpass', $masterPass);
}

View File

@@ -24,11 +24,11 @@
namespace SP\Domain\Config\Ports;
use SP\Domain\Upgrade\Ports\Upgrade;
use SP\Domain\Upgrade\Ports\UpgradeService;
/**
* Interface UpgradeConfigService
*/
interface UpgradeConfigService extends Upgrade
interface UpgradeConfigService extends UpgradeService
{
}

View File

@@ -31,7 +31,7 @@ use SP\Domain\Config\Ports\ConfigBackupService;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Config\Ports\ConfigFileService;
use SP\Domain\Core\AppInfoInterface;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Exceptions\ConfigException;
use SP\Domain\Storage\Ports\FileCacheService;
use SP\Domain\Storage\Ports\XmlFileStorageService;
@@ -57,7 +57,7 @@ class ConfigFile implements ConfigFileService
public function __construct(
private readonly XmlFileStorageService $fileStorage,
private readonly FileCacheService $fileCache,
private readonly ContextInterface $context,
private readonly Context $context,
private readonly ConfigBackupService $configBackupService,
private ?ConfigDataInterface $configData = null
) {

View File

@@ -25,228 +25,37 @@
namespace SP\Domain\Config\Services;
use SP\Core\Application;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Domain\Common\Services\Service;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Config\Ports\UpgradeConfigService;
use SP\Domain\Core\File\MimeType;
use SP\Domain\Core\File\MimeTypesService;
use SP\Domain\Providers\FileLogHandlerProvider;
use SP\Infrastructure\File\FileException;
use SP\Providers\Auth\Ldap\LdapTypeEnum;
use SP\Util\VersionUtil;
use function SP\__u;
use SP\Domain\Upgrade\Services\UpgradeBase;
/**
* Class UpgradeService
*
* @package SP\Domain\Upgrade\Services
* Class UpgradeConfig
*/
final class UpgradeConfig extends Service implements UpgradeConfigService
final class UpgradeConfig extends UpgradeBase implements UpgradeConfigService
{
/**
* @var array Versiones actualizables
*/
private const UPGRADES = [
'200.17011202',
'300.18111001',
'300.18112501',
'320.20062801',
];
private ?ConfigDataInterface $configData = null;
public function __construct(
Application $application,
FileLogHandlerProvider $fileLogHandlerProvider,
private readonly MimeTypesService $mimeTypes
Application $application,
FileLogHandlerProvider $fileLogHandlerProvider
) {
parent::__construct($application);
parent::__construct($application, $fileLogHandlerProvider);
$this->eventDispatcher->attach($fileLogHandlerProvider);
}
public static function needsUpgrade(string $version): bool
protected static function getUpgrades(): array
{
return VersionUtil::checkVersion($version, self::UPGRADES);
return [];
}
/**
* Migrar valores de configuración.
* @throws FileException
*/
public function upgrade(string $version, ConfigDataInterface $configData): void
protected function commitVersion(string $version): void
{
$this->configData = $configData;
$message = EventMessage::factory()->addDescription(__u('Update Configuration'));
$this->eventDispatcher->notify('upgrade.config.start', new Event($this, $message));
$upgradeable = array_filter(
self::UPGRADES,
static fn(string $upgradeVersion) => VersionUtil::checkVersion($version, $upgradeVersion)
);
foreach ($upgradeable as $upgradeVersion) {
$this->applyUpgrade($upgradeVersion);
}
$this->eventDispatcher->notify('upgrade.config.end', new Event($this, $message));
}
/**
* @throws FileException
*/
private function applyUpgrade(string $version): void
{
switch ($version) {
case '200.17011202':
$this->upgradeV200B17011202($version);
break;
case '300.18111001':
$this->upgradeV300B18111001($version);
break;
case '300.18112501':
$this->upgradeV300B18112501($version);
break;
case '320.20062801':
$this->upgradeV320B20062801($version);
break;
}
}
/**
* @throws FileException
*/
private function upgradeV200B17011202(string $version): void
{
$this->configData->setSiteTheme('material-blue');
$this->configData->setConfigVersion($version);
$this->config->save($this->configData, false);
$this->eventDispatcher->notify(
'upgrade.config.process',
new Event(
$this,
EventMessage::factory()
->addDescription(__u('Update Configuration'))
->addDetail(__u('Version'), $version)
)
);
}
/**
* @throws FileException
*/
private function upgradeV300B18111001(string $version): void
protected function applyUpgrade(string $version): bool
{
$extensions = array_map('strtolower', $this->configData->getFilesAllowedExts());
$configMimeTypes = [];
foreach ($extensions as $extension) {
$match = array_filter(
$this->mimeTypes->getMimeTypes(),
static fn(MimeType $mimeType) => strcasecmp($mimeType->getExtension(), $extension) === 0
);
if (count($match) > 0) {
$mimeType = array_shift($match);
$configMimeTypes[] = $mimeType->getType();
$this->eventDispatcher->notify(
'upgrade.config.process',
new Event(
$this,
EventMessage::factory()
->addDescription(__u('MIME type set for this extension'))
->addDetail(__u('MIME type'), $mimeType->getType())
->addDetail(__u('Extension'), $extension)
)
);
} else {
$this->eventDispatcher->notify(
'upgrade.config.process',
new Event(
$this,
EventMessage::factory()
->addDescription(__u('MIME type not found for this extension'))
->addDetail(__u('Extension'), $extension)
)
);
}
}
$this->configData->setFilesAllowedMime($configMimeTypes);
$this->configData->setConfigVersion($version);
$this->config->save($this->configData, false);
$this->eventDispatcher->notify(
'upgrade.config.process',
new Event(
$this,
EventMessage::factory()
->addDescription(__u('Update Configuration'))
->addDetail(__u('Version'), $version)
)
);
}
/**
* @throws FileException
*/
private function upgradeV300B18112501(string $version): void
{
if ($this->configData->isLdapEnabled()) {
$attributes = $this->configData->getAttributes();
if (isset($attributes['ldapAds']) && $attributes['ldapAds']) {
$this->configData->setLdapType(LdapTypeEnum::ADS->value);
} else {
$this->configData->setLdapType(LdapTypeEnum::STD->value);
}
$this->configData->setConfigVersion($version);
$this->config->save($this->configData, false);
$this->eventDispatcher->notify(
'upgrade.config.process',
new Event(
$this,
EventMessage::factory()
->addDescription(__u('Update Configuration'))
->addDetail(__u('Version'), $version)
)
);
}
}
/**
* @throws FileException
*/
private function upgradeV320B20062801(string $version): void
{
if ($this->configData->isLdapEnabled()) {
if ($this->configData->getLdapType() === LdapTypeEnum::AZURE->value) {
$this->configData->setLdapType(LdapTypeEnum::ADS->value);
}
$this->configData->setConfigVersion($version);
$this->config->save($this->configData, false);
$this->eventDispatcher->notify(
'upgrade.config.process',
new Event(
$this,
EventMessage::factory()
->addDescription(__u('Update Configuration'))
->addDetail(__u('Version'), $version)
)
);
}
return true;
}
}

View File

@@ -28,14 +28,11 @@ use SP\Core\Context\ContextException;
use SP\DataModel\ProfileData;
use SP\Domain\Account\Dtos\AccountCacheDto;
use SP\Domain\User\Dtos\UserDataDto;
use SP\Domain\User\Services\UserData;
/**
* Class ContextInterface
*
* @package SP\Core\Session
* Class Context
*/
interface ContextInterface
interface Context
{
public const MASTER_PASSWORD_KEY = '_masterpass';
@@ -114,7 +111,7 @@ interface ContextInterface
/**
* Establece la cache de cuentas
*
* @param array $accountsCache
* @param array $accountsCache
*/
public function setAccountsCache(array $accountsCache): void;
@@ -122,8 +119,8 @@ interface ContextInterface
* Sets an arbitrary key in the trasient collection.
* This key is not bound to any known method or type
*
* @param string $key
* @param mixed $value
* @param string $key
* @param mixed $value
*
* @throws ContextException
*/
@@ -133,8 +130,8 @@ interface ContextInterface
* Gets an arbitrary key from the trasient collection.
* This key is not bound to any known method or type
*
* @param string $key
* @param mixed|null $default
* @param string $key
* @param mixed|null $default
*
* @return mixed
*/
@@ -146,9 +143,9 @@ interface ContextInterface
public function setTemporaryMasterPass(string $password);
/**
* @param string $pluginName
* @param string $key
* @param mixed $value
* @param string $pluginName
* @param string $key
* @param mixed $value
*/
public function setPluginKey(string $pluginName, string $key, mixed $value);

View File

@@ -30,7 +30,7 @@ use SP\Domain\Core\Crypt\VaultInterface;
/**
* Class Session
*/
interface SessionContextInterface extends ContextInterface
interface SessionContext extends Context
{
/**
* Devuelve el tema visual utilizado en sysPass

View File

@@ -24,7 +24,7 @@
namespace SP\Domain\Core\UI;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Html\Assets\IconInterface;
use SP\Infrastructure\File\FileCache;
@@ -74,7 +74,7 @@ use SP\Infrastructure\File\FileCache;
interface ThemeIconsInterface
{
public static function loadIcons(
ContextInterface $context,
Context $context,
FileCache $cache,
ThemeContextInterface $themeContext
): ThemeIconsInterface;

View File

@@ -26,7 +26,6 @@ namespace SP\Domain\Notification\Services;
use Exception;
use SP\Core\Application;
use SP\Core\Bootstrap\BootstrapBase;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Core\Messages\MailMessage;
@@ -34,6 +33,7 @@ use SP\Domain\Common\Services\Service;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\AppInfoInterface;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Notification\Ports\MailService;
use SP\Domain\Providers\MailerInterface;
use SP\Html\Html;
@@ -48,8 +48,9 @@ use function SP\processException;
final class Mail extends Service implements MailService
{
public function __construct(
Application $application,
private readonly MailerInterface $mailer,
Application $application,
private readonly MailerInterface $mailer,
private readonly UriContextInterface $uriContext
) {
parent::__construct($application);
}
@@ -107,7 +108,7 @@ final class Mail extends Service implements MailService
'',
'--',
sprintf('%s - %s', AppInfoInterface::APP_NAME, AppInfoInterface::APP_DESC),
Html::anchorText(BootstrapBase::$WEBURI),
Html::anchorText($this->uriContext->getWebUri()),
];
}

View File

@@ -24,13 +24,13 @@
namespace SP\Domain\Persistence\Ports;
use SP\Domain\Upgrade\Ports\Upgrade;
use SP\Domain\Upgrade\Ports\UpgradeService;
/**
* Class UpgradeDatabaseService
*
* @package SP\Domain\Upgrade\Services
*/
interface UpgradeDatabaseService extends Upgrade
interface UpgradeServiceDatabaseService extends UpgradeService
{
}

View File

@@ -45,7 +45,7 @@ final class PluginCompatility extends Service implements PluginCompatilityServic
{
public function __construct(
Application $application,
Application $application,
private readonly PluginManagerService $pluginService
) {
parent::__construct($application);

View File

@@ -37,11 +37,11 @@ use SP\Infrastructure\Common\Repositories\NoSuchItemException;
/**
* Class PluginOperation
*/
final class PluginOperation implements PluginOperationInterface
final readonly class PluginOperation implements PluginOperationInterface
{
public function __construct(
private readonly PluginDataService $pluginDataService,
private readonly string $pluginName
private PluginDataService $pluginDataService,
private string $pluginName
) {
}

View File

@@ -25,7 +25,7 @@
namespace SP\Domain\Task\Services;
use JsonException;
use SP\Core\Context\SessionContext;
use SP\Core\Context\Session;
use SP\Core\Messages\TaskMessage;
use SP\Domain\Task\Ports\TaskInterface;
use SP\Infrastructure\File\FileException;
@@ -239,7 +239,7 @@ final class Task implements TaskInterface
$this->fileTask->save(serialize($this));
SessionContext::close();
Session::close();
return $this;
}

View File

@@ -1,34 +0,0 @@
<?php
/*
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/
namespace SP\Domain\Upgrade\Ports;
/**
* Class UpgradeAppService
*
* @package SP\Domain\Upgrade\Services
*/
interface UpgradeAppService extends Upgrade
{
}

View File

@@ -27,9 +27,9 @@ namespace SP\Domain\Upgrade\Ports;
use SP\Domain\Config\Ports\ConfigDataInterface;
/**
* Interface Upgrade
* Interface UpgradeService
*/
interface Upgrade
interface UpgradeService
{
/**
* Check if it needs to be upgraded

View File

@@ -25,95 +25,20 @@
namespace SP\Domain\Upgrade\Services;
use Exception;
use SP\Core\Application;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Domain\Common\Services\Service;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Upgrade\Ports\UpgradeAppService;
use SP\Infrastructure\File\FileException;
use SP\Providers\Log\FileLogHandler;
use SP\Util\VersionUtil;
use function SP\__u;
use function SP\logger;
use function SP\processException;
/**
* Class UpgradeApp
*/
final class UpgradeApp extends Service implements UpgradeAppService
final class UpgradeApp extends UpgradeBase
{
private const UPGRADES = [
'300.18010101',
'300.18072901',
'300.18072902',
'310.19012201',
'310.19042701',
];
public function __construct(
Application $application,
FileLogHandler $fileLogHandler,
) {
parent::__construct($application);
$this->eventDispatcher->attach($fileLogHandler);
}
public static function needsUpgrade(string $version): bool
protected static function getUpgrades(): array
{
return empty($version) || VersionUtil::checkVersion($version, self::UPGRADES);
return [];
}
/**
* @throws UpgradeException
* @throws FileException
*/
public function upgrade(
string $version,
ConfigDataInterface $configData
): void {
$this->eventDispatcher->notify(
'upgrade.app.start',
new Event(
$this,
EventMessage::factory()->addDescription(__u('Update Application'))
)
);
foreach (self::UPGRADES as $appVersion) {
if (VersionUtil::checkVersion($version, $appVersion)) {
if ($this->applyUpgrade($appVersion) === false) {
throw new UpgradeException(
__u('Error while applying the application update'),
SPException::CRITICAL,
__u('Please, check the event log for more details')
);
}
logger('APP Upgrade: ' . $appVersion);
$configData->setAppVersion($appVersion);
$this->config->save($configData, false);
}
}
$this->eventDispatcher->notify(
'upgrade.app.end',
new Event(
$this,
EventMessage::factory()->addDescription(__u('Update Application'))
)
);
}
/**
* Actualizaciones de la aplicación
*/
private function applyUpgrade(string $version): bool
protected function applyUpgrade(string $version): bool
{
try {
return true;
@@ -123,4 +48,9 @@ final class UpgradeApp extends Service implements UpgradeAppService
return false;
}
protected function commitVersion(string $version): void
{
$this->configData->setAppVersion($version);
}
}

View File

@@ -0,0 +1,115 @@
<?php
/*
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/
namespace SP\Domain\Upgrade\Services;
use SP\Core\Application;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Domain\Common\Services\Service;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Providers\FileLogHandlerProvider;
use SP\Domain\Upgrade\Ports\UpgradeService;
use SP\Infrastructure\File\FileException;
use SP\Util\VersionUtil;
use function SP\__u;
use function SP\logger;
/**
* Class UpgradeBase
*/
abstract class UpgradeBase extends Service implements UpgradeService
{
protected ?ConfigDataInterface $configData = null;
public function __construct(Application $application, FileLogHandlerProvider $fileLogHandler)
{
parent::__construct($application);
$this->eventDispatcher->attach($fileLogHandler);
}
/**
* @inheritDoc
*/
final public static function needsUpgrade(string $version): bool
{
return !empty($version) && VersionUtil::checkVersion($version, static::getUpgrades());
}
abstract protected static function getUpgrades(): array;
/**
* @inheritDoc
* @throws UpgradeException
* @throws FileException
*/
final public function upgrade(string $version, ConfigDataInterface $configData): void
{
$this->configData = $configData;
$class = get_class();
$this->eventDispatcher->notify(
sprintf('upgrade.%s.start', $class),
new Event(
$this,
EventMessage::factory()->addDescription(__u('Update'))->addDetail('type', $class)
)
);
$upgradeVersions = array_filter(
static::getUpgrades(),
static fn(string $appVersion) => VersionUtil::checkVersion($version, $appVersion)
);
foreach ($upgradeVersions as $upgradeVersion) {
if ($this->applyUpgrade($upgradeVersion) === false) {
throw UpgradeException::critical(
__u('Error while applying the update'),
__u('Please, check the event log for more details')
);
}
logger('Upgrade: ' . $upgradeVersion);
$this->commitVersion($upgradeVersion);
$this->config->save($configData, false);
}
$this->eventDispatcher->notify(
sprintf('upgrade.%s.end', $class),
new Event(
$this,
EventMessage::factory()->addDescription(__u('Update'))->addDetail('type', $class)
)
);
}
abstract protected function applyUpgrade(string $version): bool;
abstract protected function commitVersion(string $version): void;
}

View File

@@ -28,127 +28,53 @@ use Exception;
use SP\Core\Application;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Domain\Common\Services\Service;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Persistence\Ports\UpgradeDatabaseService;
use SP\Infrastructure\Database\DatabaseInterface;
use SP\Infrastructure\Database\MysqlFileParser;
use SP\Infrastructure\File\FileException;
use SP\Infrastructure\File\FileHandler;
use SP\Providers\Log\FileLogHandler;
use SP\Util\VersionUtil;
use function SP\__;
use function SP\__u;
use function SP\logger;
use function SP\processException;
/**
* Class UpgradeDatabase
*/
final class UpgradeDatabase extends Service implements UpgradeDatabaseService
final class UpgradeDatabase extends UpgradeBase
{
/**
* @var array Versiones actualizables
*/
private const UPGRADES = [
'300.18010101',
'300.18072302',
'300.18072501',
'300.18083001',
'300.18083002',
'300.18091101',
'300.18092401',
'300.18093001',
'300.18111801',
'300.18111901',
'310.19012201',
'310.19042701',
];
private DatabaseInterface $database;
public function __construct(Application $application, DatabaseInterface $database, FileLogHandler $fileLogHandler)
{
parent::__construct($application);
$this->database = $database;
$this->eventDispatcher->attach($fileLogHandler);
public function __construct(
Application $application,
FileLogHandler $fileLogHandler,
private readonly DatabaseInterface $database,
) {
parent::__construct($application, $fileLogHandler);
}
/**
* Check if it needs to be upgraded
*/
public static function needsUpgrade(string $version): bool
protected static function getUpgrades(): array
{
return empty($version) || VersionUtil::checkVersion($version, self::UPGRADES);
return [
'400.24210101',
];
}
protected function commitVersion(string $version): void
{
$this->configData->setDatabaseVersion($version);
}
/**
* Inicia el proceso de actualización de la BBDD.
*
* @throws FileException
* @throws UpgradeException
*/
public function upgrade(string $version, ConfigDataInterface $configData): bool
{
$this->eventDispatcher->notify(
'upgrade.db.start',
new Event($this, EventMessage::factory()->addDescription(__u('Update DB')))
);
foreach (self::UPGRADES as $upgradeVersion) {
if (VersionUtil::checkVersion($version, $upgradeVersion)) {
if ($this->applyPreUpgrade() === false) {
throw new UpgradeException(
__u('Error while applying an auxiliary update'),
SPException::CRITICAL,
__u('Please, check the event log for more details')
);
}
if ($this->applyUpgrade($upgradeVersion) === false) {
throw new UpgradeException(
__u('Error while updating the database'),
SPException::CRITICAL,
__u('Please, check the event log for more details')
);
}
logger('DB Upgrade: ' . $upgradeVersion);
$configData->setDatabaseVersion($upgradeVersion);
$this->config->save($configData, false);
}
}
$this->eventDispatcher->notify(
'upgrade.db.end',
new Event($this, EventMessage::factory()->addDescription(__u('Update DB')))
);
return true;
}
/**
* Aplicar actualizaciones auxiliares antes de actualizar la BBDD
*/
private function applyPreUpgrade(): bool
{
return true;
}
/**
* Actualiza la BBDD según la versión.
*
* @throws UpgradeException
*/
private function applyUpgrade(string $version): bool
protected function applyUpgrade(string $version): bool
{
$queries = $this->getQueriesFromFile($version);
if (count($queries) === 0) {
logger(__('Update file does not contain data'), 'ERROR');
throw new UpgradeException(__u('Update file does not contain data'), SPException::ERROR, $version);
throw UpgradeException::error(__u('Update file does not contain data'), $version);
}
foreach ($queries as $query) {
@@ -175,7 +101,7 @@ final class UpgradeDatabase extends Service implements UpgradeDatabaseService
)
);
throw new UpgradeException(__u('Error while updating the database'));
throw UpgradeException::error(__u('Error while updating the database'));
}
}
@@ -191,11 +117,9 @@ final class UpgradeDatabase extends Service implements UpgradeDatabaseService
}
/**
* Obtener las consultas de actualización desde un archivo
*
* @throws UpgradeException
*/
private function getQueriesFromFile(string $filename): array
private function getQueriesFromFile(string $filename): iterable
{
$fileName = SQL_PATH .
DIRECTORY_SEPARATOR .
@@ -207,7 +131,7 @@ final class UpgradeDatabase extends Service implements UpgradeDatabaseService
} catch (FileException $e) {
processException($e);
throw new UpgradeException($e->getMessage());
throw UpgradeException::error($e->getMessage());
}
}
}

View File

@@ -31,8 +31,6 @@ use SP\Util\VersionUtil;
/**
* Class UpgradeUtil
*
* @package SP\Domain\Upgrade\Services
*/
final class UpgradeUtil
{
@@ -41,12 +39,12 @@ final class UpgradeUtil
*/
public static function fixVersionNumber(string $version): string
{
if (strpos($version, '.') === false) {
if (!str_contains($version, '.')) {
if (strlen($version) === 10) {
return substr($version, 0, 2).'0.'.substr($version, 2);
return substr($version, 0, 2) . '0.' . substr($version, 2);
}
return substr($version, 0, 3).'.'.substr($version, 3);
return substr($version, 0, 3) . '.' . substr($version, 3);
}
return $version;
@@ -60,9 +58,7 @@ final class UpgradeUtil
// Fixes bug in 3.0.X version where some updates weren't applied
// when upgrading from v2
// $dbVersion is always '' when upgrading from v2
if (!empty($configData->getDatabaseVersion())
&& empty($configData->getAppVersion())
) {
if (!empty($configData->getDatabaseVersion()) && empty($configData->getAppVersion())) {
$configData->setAppVersion(VersionUtil::getVersionStringNormalized());
$config->save($configData, false);
}

View File

@@ -32,7 +32,7 @@ use SP\Domain\Account\Models\AccountSearchView as AccountSearchViewModel;
use SP\Domain\Account\Models\AccountView as AccountViewModel;
use SP\Domain\Account\Ports\AccountFilterBuilder;
use SP\Domain\Account\Ports\AccountRepository;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Events\EventDispatcherInterface;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
@@ -55,7 +55,7 @@ final class Account extends BaseRepository implements AccountRepository
public function __construct(
DatabaseInterface $database,
ContextInterface $session,
Context $session,
QueryFactory $queryFactory,
EventDispatcherInterface $eventDispatcher,
private readonly AccountFilterBuilder $accountFilterUser

View File

@@ -31,7 +31,7 @@ use SP\Domain\Account\Models\AccountSearchView;
use SP\Domain\Account\Ports\AccountFilterBuilder;
use SP\Domain\Account\Ports\AccountSearchConstants;
use SP\Domain\Account\Ports\AccountSearchRepository;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Events\EventDispatcherInterface;
use SP\Infrastructure\Common\Repositories\BaseRepository;
use SP\Infrastructure\Database\DatabaseInterface;
@@ -48,7 +48,7 @@ final class AccountSearch extends BaseRepository implements AccountSearchReposit
public function __construct(
DatabaseInterface $database,
ContextInterface $session,
Context $session,
EventDispatcherInterface $eventDispatcher,
QueryFactory $queryFactory,
private readonly AccountFilterBuilder $accountFilterUser

View File

@@ -31,7 +31,7 @@ use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Domain\Common\Ports\Repository;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Events\EventDispatcherInterface;
use SP\Domain\Core\Exceptions\SPException;
use SP\Infrastructure\Database\DatabaseInterface;
@@ -50,7 +50,7 @@ abstract class BaseRepository implements Repository
{
public function __construct(
protected readonly DatabaseInterface $db,
protected readonly ContextInterface $context,
protected readonly Context $context,
protected readonly EventDispatcherInterface $eventDispatcher,
protected readonly QueryFactory $queryFactory
) {

View File

@@ -26,7 +26,6 @@ namespace SP\Mvc\Controller;
use Closure;
use Klein\Klein;
use SP\Core\Bootstrap\BootstrapBase;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Http\RequestInterface;
@@ -35,11 +34,11 @@ use SP\Http\JsonResponse;
use SP\Http\Uri;
use SP\Util\Util;
use function SP\__u;
use function SP\processException;
/**
* Trait ControllerTrait
*
* @package SP\Mvc\Controller
*/
trait ControllerTrait
{
@@ -72,7 +71,7 @@ trait ControllerTrait
protected function sessionLogout(
RequestInterface $request,
ConfigDataInterface $configData,
Closure $onRedirect
Closure $onRedirect
): void {
if ($request->isJson()) {
$jsonResponse = new JsonMessage(__u('Session not started or timed out'));
@@ -89,7 +88,7 @@ trait ControllerTrait
$route = $request->analyzeString('r');
$hash = $request->analyzeString('h');
$uri = new Uri(BootstrapBase::$WEBROOT.BootstrapBase::$SUBURI);
$uri = new Uri($this->uriContext->getWebRoot() . $this->uriContext->getSubUri());
$uri->addParam('_r', 'login');
if ($route && $hash) {
@@ -123,7 +122,7 @@ trait ControllerTrait
* @deprecated
*/
protected function checkSecurityToken(
string $previousToken,
string $previousToken,
RequestInterface $request,
ConfigDataInterface $configData
): void {
@@ -133,7 +132,7 @@ trait ControllerTrait
$sk = $request->analyzeString('sk');
if (!$sk || $previousToken !== $sk) {
throw new SPException(__u('Invalid Action'), SPException::ERROR, null, 1);
throw SPException::error(__u('Invalid Action'), null, 1);
}
}
}

View File

@@ -24,36 +24,27 @@
namespace SP\Mvc\Controller;
use Klein\Klein;
use SP\Core\PhpExtensionChecker;
use SP\Domain\Core\Acl\AclInterface;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Core\UI\ThemeInterface;
use SP\Domain\Http\RequestInterface;
/**
* Class SimpleControllerHelper
*/
final class SimpleControllerHelper
final readonly class SimpleControllerHelper
{
private ThemeInterface $theme;
private Klein $router;
private AclInterface $acl;
private RequestInterface $request;
private PhpExtensionChecker $extensionChecker;
public function __construct(
ThemeInterface $theme,
Klein $router,
AclInterface $acl,
RequestInterface $request,
PhpExtensionChecker $extensionChecker
private ThemeInterface $theme,
private Klein $router,
private AclInterface $acl,
private RequestInterface $request,
private PhpExtensionChecker $extensionChecker,
private UriContextInterface $uriContext
) {
$this->theme = $theme;
$this->router = $router;
$this->acl = $acl;
$this->request = $request;
$this->extensionChecker = $extensionChecker;
}
public function getTheme(): ThemeInterface
@@ -80,4 +71,9 @@ final class SimpleControllerHelper
{
return $this->extensionChecker;
}
public function getUriContext(): UriContextInterface
{
return $this->uriContext;
}
}

View File

@@ -24,10 +24,10 @@
namespace SP\Mvc\Controller;
use Klein\Klein;
use SP\Core\PhpExtensionChecker;
use SP\Domain\Core\Acl\AclInterface;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Core\UI\ThemeInterface;
use SP\Domain\Http\RequestInterface;
use SP\Modules\Web\Controllers\Helpers\LayoutHelper;
@@ -37,31 +37,27 @@ use SP\Providers\Auth\Browser\BrowserAuthService;
/**
* Class WebControllerHelper
*/
final class WebControllerHelper
final readonly class WebControllerHelper
{
private ThemeInterface $theme;
private Klein $router;
private AclInterface $acl;
private RequestInterface $request;
private PhpExtensionChecker $extensionChecker;
private TemplateInterface $template;
private BrowserAuthService $browser;
private LayoutHelper $layoutHelper;
private ThemeInterface $theme;
private Klein $router;
private AclInterface $acl;
private RequestInterface $request;
private PhpExtensionChecker $extensionChecker;
private UriContextInterface $uriContext;
public function __construct(
SimpleControllerHelper $simpleControllerHelper,
TemplateInterface $template,
BrowserAuthService $browser,
LayoutHelper $layoutHelper
SimpleControllerHelper $simpleControllerHelper,
private TemplateInterface $template,
private BrowserAuthService $browser,
private LayoutHelper $layoutHelper
) {
$this->theme = $simpleControllerHelper->getTheme();
$this->router = $simpleControllerHelper->getRouter();
$this->acl = $simpleControllerHelper->getAcl();
$this->request = $simpleControllerHelper->getRequest();
$this->extensionChecker = $simpleControllerHelper->getExtensionChecker();
$this->template = $template;
$this->browser = $browser;
$this->layoutHelper = $layoutHelper;
$this->uriContext = $simpleControllerHelper->getUriContext();
}
public function getTheme(): ThemeInterface
@@ -89,6 +85,11 @@ final class WebControllerHelper
return $this->extensionChecker;
}
public function getUriContext(): UriContextInterface
{
return $this->uriContext;
}
public function getTemplate(): TemplateInterface
{
return $this->template;

View File

@@ -47,7 +47,7 @@ interface BrowserAuthService extends AuthService
/**
* Devolver el nombre del usuario autentificado por el servidor web
*
* @return string
* @return string|null
*/
public function getServerAuthUser(): ?string;
}

View File

@@ -26,7 +26,7 @@ namespace SP\Providers;
use SP\Core\Application;
use SP\Domain\Config\Ports\ConfigFileService;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Events\EventDispatcherInterface;
/**
@@ -37,7 +37,7 @@ use SP\Domain\Core\Events\EventDispatcherInterface;
abstract class Provider implements ProviderInterface
{
protected readonly ConfigFileService $config;
protected readonly ContextInterface $context;
protected readonly Context $context;
protected readonly EventDispatcherInterface $eventDispatcher;
protected bool $initialized = false;

View File

@@ -31,8 +31,8 @@ namespace SP\Util;
*/
final class Checks
{
private const MIN_PHP_VERSION = 81000;
private const MAX_PHP_VERSION = 82000;
private const MIN_PHP_VERSION = 82000;
private const MAX_PHP_VERSION = 83000;
/**
* Comprobar si sysPass se ejecuta en W$indows.

View File

@@ -24,14 +24,11 @@
namespace SP\Util;
use SP\Core\Bootstrap\BootstrapBase;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Http\Uri;
/**
* Class Link
*
* @package SP\Util
*/
final class Link
{
@@ -39,19 +36,10 @@ final class Link
int $itemId,
string $actionRoute,
ConfigDataInterface $configData,
bool $useUI = false
string $baseUrl
): string {
$route = sprintf('%s/%d', $actionRoute, $itemId);
if ($useUI) {
$baseUrl = ($configData->getApplicationUrl() ?? BootstrapBase::$WEBURI) . '/index.php';
} else {
$baseUrl = ($configData->getApplicationUrl() ?? BootstrapBase::$WEBURI) . BootstrapBase::$SUBURI;
}
$uri = new Uri($baseUrl);
$uri->addParam('r', $route);
return $uri->getUriSigned($configData->getPasswordSalt());
return (new Uri($baseUrl))
->addParam('r', sprintf('%s/%d', $actionRoute, $itemId))
->getUriSigned($configData->getPasswordSalt());
}
}

View File

@@ -78,11 +78,11 @@ final class VersionUtil
/**
* Return a normalized version string to be compared
*
* @param array|string $versionIn
* @param array|string|null $versionIn
*
* @return string|null
*/
public static function normalizeVersionForCompare(array|string $versionIn): ?string
public static function normalizeVersionForCompare(array|string|null $versionIn): ?string
{
if (!empty($versionIn)) {
if (is_string($versionIn)) {

View File

@@ -26,7 +26,7 @@ namespace SPT\Core\Context;
use PHPUnit\Framework\Attributes\Group;
use SP\Core\Context\ContextFactory;
use SP\Core\Context\SessionContext;
use SP\Core\Context\Session;
use SP\Core\Context\StatelessContext;
use SPT\UnitaryTestCase;
@@ -40,7 +40,7 @@ class ContextFactoryTest extends UnitaryTestCase
{
$out = ContextFactory::getForModule('web');
$this->assertInstanceOf(SessionContext::class, $out);
$this->assertInstanceOf(Session::class, $out);
}
public function testGetForModuleWithOther()

View File

@@ -30,7 +30,7 @@ use PHPUnit\Framework\MockObject\MockObject;
use SP\Core\Crypt\Csrf;
use SP\Core\Crypt\Hash;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\Context\SessionContextInterface;
use SP\Domain\Core\Context\SessionContext;
use SP\Domain\Http\Method;
use SP\Domain\Http\RequestInterface;
use SPT\UnitaryTestCase;
@@ -43,8 +43,8 @@ use SPT\UnitaryTestCase;
class CsrfTest extends UnitaryTestCase
{
private SessionContextInterface|MockObject $sessionContext;
private RequestInterface|MockObject $requestInterface;
private SessionContext|MockObject $sessionContext;
private RequestInterface|MockObject $requestInterface;
private ConfigDataInterface|MockObject $configData;
private Csrf $csrf;
@@ -277,7 +277,7 @@ class CsrfTest extends UnitaryTestCase
{
parent::setUp();
$this->sessionContext = $this->createMock(SessionContextInterface::class);
$this->sessionContext = $this->createMock(SessionContext::class);
$this->requestInterface = $this->createMock(RequestInterface::class);
$this->configData = $this->createMock(ConfigDataInterface::class);

View File

@@ -28,7 +28,7 @@ use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use SP\Core\Crypt\Session;
use SP\Domain\Core\Context\SessionContextInterface;
use SP\Domain\Core\Context\SessionContext;
use SP\Domain\Core\Crypt\VaultInterface;
use SP\Domain\Core\Exceptions\CryptException;
use SPT\UnitaryTestCase;
@@ -41,7 +41,7 @@ use SPT\UnitaryTestCase;
class SessionTest extends UnitaryTestCase
{
private SessionContextInterface|MockObject $sessionContext;
private SessionContext|MockObject $sessionContext;
/**
* @throws Exception
@@ -130,7 +130,7 @@ class SessionTest extends UnitaryTestCase
{
parent::setUp();
$this->sessionContext = $this->createMock(SessionContextInterface::class);
$this->sessionContext = $this->createMock(SessionContext::class);
}
}

View File

@@ -26,13 +26,14 @@ namespace SPT\Core\Crypt;
use Klein\DataCollection\DataCollection;
use Klein\Request;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use SP\Core\Crypt\Hash;
use SP\Core\Crypt\UuidCookie;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Http\RequestInterface;
use SPT\UnitaryTestCase;
use PHPUnit\Framework\Attributes\Group;
/**
* Class UuidCookieTest
@@ -42,7 +43,8 @@ use PHPUnit\Framework\Attributes\Group;
class UuidCookieTest extends UnitaryTestCase
{
private RequestInterface|MockObject $requestInterface;
private RequestInterface|MockObject $requestInterface;
private UriContextInterface|MockObject $uriContext;
/**
@@ -70,7 +72,7 @@ class UuidCookieTest extends UnitaryTestCase
->method('getRequest')
->willReturn($request);
$cookie = UuidCookie::factory($this->requestInterface);
$cookie = UuidCookie::factory($this->requestInterface, $this->uriContext);
self::assertEquals('test', $cookie->load($key));
}
@@ -98,7 +100,7 @@ class UuidCookieTest extends UnitaryTestCase
->method('getRequest')
->willReturn($request);
$cookie = UuidCookie::factory($this->requestInterface);
$cookie = UuidCookie::factory($this->requestInterface, $this->uriContext);
self::assertFalse($cookie->load($key));
}
@@ -127,7 +129,7 @@ class UuidCookieTest extends UnitaryTestCase
->method('getRequest')
->willReturn($request);
$cookie = UuidCookie::factory($this->requestInterface);
$cookie = UuidCookie::factory($this->requestInterface, $this->uriContext);
self::assertFalse($cookie->load($key));
}
@@ -156,14 +158,14 @@ class UuidCookieTest extends UnitaryTestCase
->method('getRequest')
->willReturn($request);
$cookie = UuidCookie::factory($this->requestInterface);
$cookie = UuidCookie::factory($this->requestInterface, $this->uriContext);
self::assertFalse($cookie->load($key));
}
public function testCreate()
{
$uuidCookie = UuidCookie::factory($this->requestInterface);
$uuidCookie = UuidCookie::factory($this->requestInterface, $this->uriContext);
$key = self::$faker->sha1;
$cookie = $uuidCookie->create($key);
@@ -174,7 +176,7 @@ class UuidCookieTest extends UnitaryTestCase
public function testSign()
{
$key = self::$faker->sha1;
$uuidCookie = UuidCookie::factory($this->requestInterface);
$uuidCookie = UuidCookie::factory($this->requestInterface, $this->uriContext);
$cookieData = $uuidCookie->sign('test', $key);
$out = $uuidCookie->getCookieData($cookieData, $key);
@@ -186,5 +188,6 @@ class UuidCookieTest extends UnitaryTestCase
parent::setUp();
$this->requestInterface = $this->createMock(RequestInterface::class);
$this->uriContext = $this->createMock(UriContextInterface::class);
}
}

View File

@@ -27,7 +27,7 @@ namespace SPT\Core\UI;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\Exception;
use SP\Core\UI\ThemeIcons;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Exceptions\InvalidClassException;
use SP\Domain\Core\UI\ThemeContextInterface;
use SP\Domain\Storage\Ports\FileCacheService;
@@ -85,7 +85,7 @@ class ThemeIconsTest extends UnitaryTestCase
*/
public function testLoadIconsWithCache()
{
$context = $this->createMock(ContextInterface::class);
$context = $this->createMock(Context::class);
$fileCache = $this->createMock(FileCacheService::class);
$themeContext = $this->createMock(ThemeContextInterface::class);

View File

@@ -30,7 +30,7 @@ use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use SP\Core\Context\ContextException;
use SP\Core\UI\Theme;
use SP\Domain\Core\Context\SessionContextInterface;
use SP\Domain\Core\Context\SessionContext;
use SP\Domain\Core\UI\ThemeContextInterface;
use SP\Domain\Core\UI\ThemeIconsInterface;
use SP\Domain\User\Dtos\UserDataDto;
@@ -62,7 +62,7 @@ class ThemeTest extends UnitaryTestCase
*/
public function testGetThemeNameUnathenticated()
{
$context = $this->createMock(SessionContextInterface::class);
$context = $this->createMock(SessionContext::class);
$context->expects(self::once())
->method('isLoggedIn')
->willReturn(false);
@@ -83,7 +83,7 @@ class ThemeTest extends UnitaryTestCase
*/
public function testGetThemeNameAuthenticated()
{
$context = $this->createMock(SessionContextInterface::class);
$context = $this->createMock(SessionContext::class);
$context->expects(self::once())
->method('isLoggedIn')
->willReturn(true);

View File

@@ -68,6 +68,7 @@ class AccountAdapterTest extends UnitaryTestCase
$adapter = new Account(
$this->config->getConfigData(),
'testUrl',
$this->createStub(CustomFieldDataService::class),
$actions
);
@@ -150,7 +151,7 @@ class AccountAdapterTest extends UnitaryTestCase
);
$adapter = new Account($this->config->getConfigData(), $customFieldsService, $actions);
$adapter = new Account($this->config->getConfigData(), 'testUrl', $customFieldsService, $actions);
$fractal = new Manager();
$fractal->parseIncludes('customFields');

View File

@@ -25,12 +25,14 @@
namespace SPT\Domain\Account\Services\Builders;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use SP\Domain\Account\Ports\AccountAclService;
use SP\Domain\Account\Ports\AccountCacheService;
use SP\Domain\Account\Ports\AccountToFavoriteService;
use SP\Domain\Account\Ports\AccountToTagRepository;
use SP\Domain\Account\Services\Builders\AccountSearchData;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
use SP\Domain\Core\Exceptions\SPException;
@@ -135,6 +137,9 @@ class AccountSearchDataTest extends UnitaryTestCase
$this->accountSearchDataBuilder->buildFrom($queryResult);
}
/**
* @throws Exception
*/
public function testInitializeWithException(): void
{
$fileCache = $this->createMock(FileCacheService::class);
@@ -151,7 +156,8 @@ class AccountSearchDataTest extends UnitaryTestCase
$this->accountToFavoriteService,
$this->accountCacheService,
$fileCache,
$this->config->getConfigData()
$this->config->getConfigData(),
$this->createStub(UriContextInterface::class)
);
}
@@ -168,6 +174,8 @@ class AccountSearchDataTest extends UnitaryTestCase
->expects(self::once())
->method('load');
$uriContext = $this->createStub(UriContextInterface::class);
$this->accountSearchDataBuilder =
new AccountSearchData(
$this->application,
@@ -176,7 +184,8 @@ class AccountSearchDataTest extends UnitaryTestCase
$this->accountToFavoriteService,
$this->accountCacheService,
$this->fileCache,
$this->config->getConfigData()
$this->config->getConfigData(),
$uriContext
);
}

View File

@@ -36,7 +36,7 @@ use SP\Domain\Account\Ports\PublicLinkRepository;
use SP\Domain\Account\Services\PublicLink;
use SP\Domain\Common\Models\Simple;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Crypt\CryptInterface;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
@@ -355,7 +355,7 @@ class PublicLinkTest extends UnitaryTestCase
->with(
$passData['pass'],
$passData['key'],
$this->context->getTrasientKey(ContextInterface::MASTER_PASSWORD_KEY)
$this->context->getTrasientKey(Context::MASTER_PASSWORD_KEY)
)
->willReturn(self::$faker->password);
@@ -545,7 +545,7 @@ class PublicLinkTest extends UnitaryTestCase
->with(
$passData['pass'],
$passData['key'],
$this->context->getTrasientKey(ContextInterface::MASTER_PASSWORD_KEY)
$this->context->getTrasientKey(Context::MASTER_PASSWORD_KEY)
)
->willReturn(self::$faker->password);
@@ -577,7 +577,7 @@ class PublicLinkTest extends UnitaryTestCase
$this->accountService = $this->createMock(AccountService::class);
$this->crypt = $this->createMock(CryptInterface::class);
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, self::$faker->password);
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, self::$faker->password);
$this->publicLink =
new PublicLink(

View File

@@ -40,7 +40,7 @@ use SP\Domain\Auth\Models\AuthToken;
use SP\Domain\Auth\Ports\AuthTokenService;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Exceptions\CryptException;
use SP\Domain\Core\Exceptions\InvalidArgumentException;
use SP\Domain\Core\Exceptions\InvalidClassException;
@@ -602,7 +602,7 @@ class ApiTest extends UnitaryTestCase
$this->apiService->setup($actionId);
$this->apiService->requireMasterPass();
$this->assertEquals($masterPass, $this->context->getTrasientKey(ContextInterface::MASTER_PASSWORD_KEY));
$this->assertEquals($masterPass, $this->context->getTrasientKey(Context::MASTER_PASSWORD_KEY));
}
/**
@@ -666,7 +666,7 @@ class ApiTest extends UnitaryTestCase
$this->assertEquals(
$this->apiService->getMasterPass(),
$this->context->getTrasientKey(ContextInterface::MASTER_PASSWORD_KEY)
$this->context->getTrasientKey(Context::MASTER_PASSWORD_KEY)
);
}
}

View File

@@ -40,8 +40,8 @@ use SP\Domain\Auth\Services\AuthException;
use SP\Domain\Auth\Services\Login;
use SP\Domain\Auth\Services\LoginStatus;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\SessionContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Context\SessionContext;
use SP\Domain\Core\Exceptions\InvalidArgumentException;
use SP\Domain\Core\LanguageInterface;
use SP\Domain\Http\RequestInterface;
@@ -65,7 +65,7 @@ use SPT\UnitaryTestCase;
/**
* Class LoginTest
*
* @property SessionContextInterface|MockObject $context
* @property SessionContext|MockObject $context
*/
#[Group('unitary')]
class LoginTest extends UnitaryTestCase
@@ -480,9 +480,9 @@ class LoginTest extends UnitaryTestCase
/**
* @throws Exception
*/
protected function buildContext(): ContextInterface
protected function buildContext(): Context
{
return $this->createMock(SessionContextInterface::class);
return $this->createMock(SessionContext::class);
}
/**

View File

@@ -32,11 +32,9 @@ use SP\Core\Application;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Config\Ports\ConfigFileService;
use SP\Domain\Config\Services\UpgradeConfig;
use SP\Domain\Core\File\MimeType;
use SP\Domain\Core\File\MimeTypesService;
use SP\Domain\Providers\FileLogHandlerProvider;
use SP\Domain\Upgrade\Services\UpgradeException;
use SP\Infrastructure\File\FileException;
use SP\Providers\Auth\Ldap\LdapTypeEnum;
use SPT\UnitaryTestCase;
/**
@@ -46,15 +44,11 @@ use SPT\UnitaryTestCase;
#[Group('unitary')]
class UpgradeConfigTest extends UnitaryTestCase
{
private MimeTypesService|MockObject $mimeTypeService;
private FileLogHandlerProvider|MockObject $fileLogHandlerProvider;
public static function versionDataProvider(): array
{
return [
['200.00000000', true],
['300.00000000', true],
['320.20062801', false],
['340.00000000', false]
];
@@ -63,6 +57,7 @@ class UpgradeConfigTest extends UnitaryTestCase
/**
* @throws Exception
* @throws FileException
* @throws UpgradeException
*/
public function testUpgrade()
{
@@ -75,64 +70,18 @@ class UpgradeConfigTest extends UnitaryTestCase
$this->application->getContext()
);
$this->checkUpgradeV200B17011202($configData);
$this->checkUpgradeV300B18111001($configData);
$this->checkUpgradeLdap($configData);
$configData->expects(self::exactly(4))
$configData->expects(self::never())
->method('setConfigVersion')
->with(self::anything());
$configFileService->expects(self::exactly(4))
$configFileService->expects(self::never())
->method('save')
->with($configData, false);
$upgradeConfig = new UpgradeConfig($application, $this->fileLogHandlerProvider, $this->mimeTypeService);
$upgradeConfig = new UpgradeConfig($application, $this->fileLogHandlerProvider);
$upgradeConfig->upgrade($version, $configData);
}
private function checkUpgradeV200B17011202(ConfigDataInterface|MockObject $configData): void
{
$configData->expects(self::once())
->method('setSiteTheme')
->with('material-blue');
}
private function checkUpgradeV300B18111001(ConfigDataInterface|MockObject $configData): void
{
$configData->expects(self::once())
->method('getFilesAllowedExts')
->willReturn(['testA', 'testB']);
$this->mimeTypeService
->expects(self::exactly(2))
->method('getMimeTypes')
->willReturn([new MimeType('application/test', '', 'testA')]);
$configData->expects(self::once())
->method('setFilesAllowedMime')
->with(['application/test']);
}
private function checkUpgradeLdap(ConfigDataInterface|MockObject $configData): void
{
$configData->expects(self::exactly(2))
->method('isLdapEnabled')
->willReturn(true);
$configData->expects(self::once())
->method('getAttributes')
->willReturn(['ldapAds' => 'test']);
$configData->expects(self::exactly(2))
->method('setLdapType')
->with(LdapTypeEnum::ADS->value);
$configData->expects(self::once())
->method('getLdapType')
->willReturn(LdapTypeEnum::AZURE->value);
}
/**
* @return void
*/
@@ -147,8 +96,5 @@ class UpgradeConfigTest extends UnitaryTestCase
parent::setUp();
$this->fileLogHandlerProvider = $this->createMock(FileLogHandlerProvider::class);
$this->mimeTypeService = $this->createMock(MimeTypesService::class);
}
}

View File

@@ -33,7 +33,7 @@ use SP\Core\Context\ContextException;
use SP\DataModel\Dto\ConfigRequest;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Config\Ports\ConfigService;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Crypt\CryptInterface;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\CryptException;
@@ -316,7 +316,7 @@ class TemporaryMasterPassTest extends UnitaryTestCase
*/
public function testCreate()
{
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'test_master_pass');
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, 'test_master_pass');
$this->crypt
->expects(self::once())
@@ -353,7 +353,7 @@ class TemporaryMasterPassTest extends UnitaryTestCase
*/
public function testCreateWithError()
{
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'test_master_pass');
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, 'test_master_pass');
$this->crypt
->expects(self::once())

View File

@@ -31,7 +31,7 @@ use PHPUnit\Framework\MockObject\MockObject;
use RuntimeException;
use SP\Core\Context\ContextException;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Crypt\CryptInterface;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
@@ -130,7 +130,7 @@ class CustomFieldDataTest extends UnitaryTestCase
->with($customFieldData->getDefinitionId())
->willReturn(new QueryResult([$customFieldDefinition]));
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'secret');
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, 'secret');
$this->crypt
->expects(self::once())
@@ -213,7 +213,7 @@ class CustomFieldDataTest extends UnitaryTestCase
->with($customFieldData->getDefinitionId())
->willReturn(new QueryResult([$customFieldDefinition]));
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'secret');
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, 'secret');
$this->crypt
->expects(self::once())
@@ -303,7 +303,7 @@ class CustomFieldDataTest extends UnitaryTestCase
->with($customFieldData->getDefinitionId())
->willReturn(new QueryResult([$customFieldDefinition]));
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'secret');
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, 'secret');
$this->crypt
->expects(self::once())
@@ -359,7 +359,7 @@ class CustomFieldDataTest extends UnitaryTestCase
->with($customFieldData->getDefinitionId())
->willReturn(new QueryResult([$customFieldDefinition]));
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'secret');
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, 'secret');
$this->crypt
->expects(self::once())
@@ -410,7 +410,7 @@ class CustomFieldDataTest extends UnitaryTestCase
->with($customFieldData->getDefinitionId())
->willReturn(new QueryResult([$customFieldDefinition]));
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'secret');
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, 'secret');
$this->crypt
->expects(self::once())
@@ -466,7 +466,7 @@ class CustomFieldDataTest extends UnitaryTestCase
->with($customFieldData->getDefinitionId())
->willReturn(new QueryResult([$customFieldDefinition]));
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'secret');
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, 'secret');
$this->crypt
->expects(self::once())
@@ -500,7 +500,7 @@ class CustomFieldDataTest extends UnitaryTestCase
$data = self::$faker->text();
$key = self::$faker->password();
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'secret');
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, 'secret');
$this->crypt
->expects(self::once())

View File

@@ -32,6 +32,7 @@ use SP\Core\Context\ContextException;
use SP\Core\Messages\MailMessage;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Config\Ports\ConfigFileService;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Notification\Services\Mail;
use SP\Domain\Providers\MailerInterface;
use SP\Providers\Mail\MailParams;
@@ -324,6 +325,7 @@ class MailTest extends UnitaryTestCase
parent::setUp();
$this->mailer = $this->createMock(MailerInterface::class);
$this->mail = new Mail($this->application, $this->mailer);
$uriContext = $this->createMock(UriContextInterface::class);
$this->mail = new Mail($this->application, $this->mailer, $uriContext);
}
}

View File

@@ -28,7 +28,7 @@ use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\MockObject;
use SP\Core\Context\ContextException;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Crypt\CryptInterface;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\CryptException;
@@ -132,7 +132,7 @@ class PluginDataTest extends UnitaryTestCase
*/
public function testUpdate()
{
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'super_secret');
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, 'super_secret');
$pluginData = PluginDataGenerator::factory()->buildPluginData();
@@ -167,7 +167,7 @@ class PluginDataTest extends UnitaryTestCase
*/
public function testCreate()
{
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'super_secret');
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, 'super_secret');
$pluginData = PluginDataGenerator::factory()->buildPluginData();
@@ -203,7 +203,7 @@ class PluginDataTest extends UnitaryTestCase
*/
public function testGetByItemId()
{
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'super_secret');
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, 'super_secret');
$pluginData = PluginDataGenerator::factory()->buildPluginData();
@@ -259,7 +259,7 @@ class PluginDataTest extends UnitaryTestCase
*/
public function testGetByName()
{
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'super_secret');
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, 'super_secret');
$pluginData = PluginDataGenerator::factory()->buildPluginData();
@@ -319,7 +319,7 @@ class PluginDataTest extends UnitaryTestCase
*/
public function testGetAll()
{
$this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'super_secret');
$this->context->setTrasientKey(Context::MASTER_PASSWORD_KEY, 'super_secret');
$pluginData = PluginDataGenerator::factory()->buildPluginData();

View File

@@ -28,7 +28,7 @@ use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\Exception;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
use SP\Domain\Plugin\Models\Plugin;
use SP\Domain\Plugin\Models\Plugin as PluginModel;
use SP\Domain\Plugin\Ports\Plugin;
use SP\Domain\Plugin\Ports\PluginManagerService;
use SP\Domain\Plugin\Services\PluginLoader;
@@ -52,7 +52,7 @@ class PluginLoaderTest extends UnitaryTestCase
$plugin = $this->createStub(Plugin::class);
$plugin->method('getName')->willReturn('test_plugin');
$pluginModel = new Plugin(['enabled' => true]);
$pluginModel = new PluginModel(['enabled' => true]);
$pluginManagerService
->expects($this->once())
@@ -75,7 +75,7 @@ class PluginLoaderTest extends UnitaryTestCase
$plugin = $this->createStub(Plugin::class);
$plugin->method('getName')->willReturn('test_plugin');
$pluginModel = new Plugin(['enabled' => false]);
$pluginModel = new PluginModel(['enabled' => false]);
$pluginManagerService
->expects($this->once())

View File

@@ -28,7 +28,7 @@ use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\Exception;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
use SP\Domain\Plugin\Models\Plugin;
use SP\Domain\Plugin\Models\Plugin as PluginModel;
use SP\Domain\Plugin\Ports\Plugin;
use SP\Domain\Plugin\Ports\PluginManagerService;
use SP\Domain\Plugin\Services\PluginRegister;
@@ -60,7 +60,7 @@ class PluginRegisterTest extends UnitaryTestCase
$pluginManagerService->expects($this->once())
->method('create')
->with(new Plugin(['name' => 'test_plugin', 'enabled' => false]));
->with(new PluginModel(['name' => 'test_plugin', 'enabled' => false]));
$pluginRegister = new PluginRegister($this->application, $pluginManagerService);

View File

@@ -44,7 +44,7 @@ use SP\Domain\Auth\Services\AuthToken;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Config\Ports\ConfigFileService;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
use SP\Domain\Core\Exceptions\SPException;
@@ -185,7 +185,7 @@ abstract class ApiTestCase extends TestCase
)
->build();
$context = $dic->get(ContextInterface::class);
$context = $dic->get(Context::class);
$context->initialize();
$context->setTrasientKey('_masterpass', '12345678900');

View File

@@ -30,7 +30,7 @@ use DI\NotFoundException;
use Exception;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Infrastructure\Database\DbStorageHandler;
use Symfony\Component\Console\Tester\CommandTester;
@@ -68,7 +68,7 @@ abstract class CliTestCase extends TestCase
self::$dic = $builder->build();
$context = self::$dic->get(ContextInterface::class);
$context = self::$dic->get(Context::class);
$context->initialize();
}

View File

@@ -34,7 +34,7 @@ use SP\Core\Context\ContextException;
use SP\Core\Context\StatelessContext;
use SP\DataModel\ProfileData;
use SP\Domain\Config\Ports\ConfigFileService;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Events\EventDispatcherInterface;
use SP\Domain\User\Dtos\UserDataDto;
use SP\Domain\User\Models\User;
@@ -50,8 +50,8 @@ abstract class UnitaryTestCase extends TestCase
protected static Generator $faker;
protected readonly ConfigFileService|Stub $config;
protected readonly Application $application;
protected readonly ContextInterface $context;
protected readonly Application $application;
protected readonly Context $context;
public static function setUpBeforeClass(): void
{
@@ -111,7 +111,7 @@ abstract class UnitaryTestCase extends TestCase
/**
* @throws ContextException
*/
protected function buildContext(): ContextInterface
protected function buildContext(): Context
{
$context = new StatelessContext();
$context->initialize();

View File

@@ -30,7 +30,7 @@ use Exception;
use RuntimeException;
use SP\Core\Context\ContextException;
use SP\DataModel\ProfileData;
use SP\Domain\Core\Context\ContextInterface;
use SP\Domain\Core\Context\Context;
use SP\Domain\Core\Exceptions\FileNotFoundException;
use SP\Domain\User\Dtos\UserDataDto;
use SP\Infrastructure\Database\DatabaseConnectionData;
@@ -122,7 +122,7 @@ function setupContext(): Container
->build();
// Inicializar el contexto
$context = $dic->get(ContextInterface::class);
$context = $dic->get(Context::class);
$context->initialize();
$context->setTrasientKey('_masterpass', '12345678900');