* [MOD] Improved plugins manager

* [MOD] Code refactoring and cleanup
* [MOD] Make classes final for performance improvements and avoid some side behaviours
This commit is contained in:
nuxsmin
2018-07-28 21:45:49 +02:00
parent 3e26a1df71
commit cd2c0379db
90 changed files with 517 additions and 1071 deletions

View File

@@ -38,7 +38,7 @@ use SP\Services\Api\ApiResponse;
*
* @package SP\Modules\Api\Controllers
*/
class AccountController extends ControllerBase
final class AccountController extends ControllerBase
{
/**
* @var AccountService

View File

@@ -35,9 +35,10 @@ use SP\Services\Category\CategoryService;
/**
* Class CategoryController
*
* @package SP\Modules\Api\Controllers
*/
class CategoryController extends ControllerBase
final class CategoryController extends ControllerBase
{
/**
* @var CategoryService

View File

@@ -34,9 +34,10 @@ use SP\Services\Client\ClientService;
/**
* Class ClientController
*
* @package SP\Modules\Api\Controllers
*/
class ClientController extends ControllerBase
final class ClientController extends ControllerBase
{
/**
* @var ClientService

View File

@@ -36,7 +36,7 @@ use SP\Services\Export\XmlExportService;
*
* @package SP\Modules\Api\Controllers
*/
class ConfigController extends ControllerBase
final class ConfigController extends ControllerBase
{
/**
* backupAction

View File

@@ -34,9 +34,10 @@ use SP\Services\Tag\TagService;
/**
* Class TagController
*
* @package SP\Modules\Api\Controllers
*/
class TagController extends ControllerBase
final class TagController extends ControllerBase
{
/**
* @var TagService

View File

@@ -42,7 +42,7 @@ use SP\Util\HttpUtil;
*
* @package api
*/
class Init extends ModuleBase
final class Init extends ModuleBase
{
/**
* @var StatelessContext

View File

@@ -40,7 +40,7 @@ use SP\Services\UserProfile\UserProfileService;
*
* @package SP\Modules\Web\Controllers
*/
class AccessManagerController extends ControllerBase
final class AccessManagerController extends ControllerBase
{
/**
* @var ItemSearchData

View File

@@ -59,7 +59,7 @@ use SP\Util\Util;
*
* @package SP\Modules\Web\Controllers
*/
class AccountController extends ControllerBase implements CrudControllerInterface
final class AccountController extends ControllerBase implements CrudControllerInterface
{
use JsonTrait, ItemTrait;
@@ -530,7 +530,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
* @param int $id Account's ID
* @param int $parentId
*/
public function viewPassAction($id, $parentId)
public function viewPassAction($id, $parentId = 0)
{
try {
$accountPassHelper = $this->dic->get(AccountPasswordHelper::class);
@@ -671,7 +671,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
public function saveCreateAction()
{
try {
$form = new AccountForm();
$form = new AccountForm($this->dic);
$form->validate(Acl::ACCOUNT_CREATE);
$itemData = $form->getItemData();
@@ -718,7 +718,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
public function saveEditAction($id)
{
try {
$form = new AccountForm($id);
$form = new AccountForm($this->dic, $id);
$form->validate(Acl::ACCOUNT_EDIT);
$itemData = $form->getItemData();
@@ -764,7 +764,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
public function saveEditPassAction($id)
{
try {
$form = new AccountForm($id);
$form = new AccountForm($this->dic, $id);
$form->validate(Acl::ACCOUNT_EDIT_PASS);
$this->accountService->editPassword($form->getItemData());

View File

@@ -33,7 +33,7 @@ use SP\Services\Account\AccountToFavoriteService;
*
* @package SP\Modules\Web\Controllers
*/
class AccountFavoriteController extends SimpleControllerBase
final class AccountFavoriteController extends SimpleControllerBase
{
use JsonTrait;

View File

@@ -46,7 +46,7 @@ use SP\Util\Util;
*
* @package SP\Modules\Web\Controllers
*/
class AccountFileController extends ControllerBase implements CrudControllerInterface
final class AccountFileController extends ControllerBase implements CrudControllerInterface
{
use JsonTrait, ItemTrait;

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -35,9 +35,10 @@ use SP\Services\Account\AccountHistoryService;
/**
* Class AccountHistoryManagerController
*
* @package SP\Modules\Web\Controllers
*/
class AccountHistoryManagerController extends ControllerBase
final class AccountHistoryManagerController extends ControllerBase
{
use JsonTrait, ItemTrait;

View File

@@ -38,7 +38,7 @@ use SP\Services\Account\AccountService;
*
* @package SP\Modules\Web\Controllers
*/
class AccountManagerController extends ControllerBase
final class AccountManagerController extends ControllerBase
{
use JsonTrait, ItemTrait;

View File

@@ -44,7 +44,7 @@ use SP\Services\User\UserService;
*
* @package SP\Modules\Web\Controllers
*/
class AuthTokenController extends ControllerBase implements CrudControllerInterface
final class AuthTokenController extends ControllerBase implements CrudControllerInterface
{
use JsonTrait, ItemTrait;
@@ -237,7 +237,7 @@ class AuthTokenController extends ControllerBase implements CrudControllerInterf
}
try {
$form = new AuthTokenForm();
$form = new AuthTokenForm($this->dic);
$form->validate(Acl::AUTHTOKEN_CREATE);
$apiTokenData = $form->getItemData();
@@ -273,7 +273,7 @@ class AuthTokenController extends ControllerBase implements CrudControllerInterf
}
try {
$form = new AuthTokenForm($id);
$form = new AuthTokenForm($this->dic, $id);
$form->validate(Acl::AUTHTOKEN_EDIT);
if ($form->isRefresh()) {

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -36,7 +36,7 @@ use SP\Providers\Auth\Browser\Browser;
*
* @package SP\Modules\Web\Controllers
*/
class BootstrapController extends SimpleControllerBase
final class BootstrapController extends SimpleControllerBase
{
/**
* Returns environment data
@@ -48,7 +48,7 @@ class BootstrapController extends SimpleControllerBase
{
$configData = $this->config->getConfigData();
$checkStatus= $this->session->getAuthCompleted() && ($this->session->getUserData()->getIsAdminApp() || $configData->isDemoEnabled());
$checkStatus = $this->session->getAuthCompleted() && ($this->session->getUserData()->getIsAdminApp() || $configData->isDemoEnabled());
$data = [
'lang' => require CONFIG_PATH . DIRECTORY_SEPARATOR . 'strings.js.inc',

View File

@@ -42,7 +42,7 @@ use SP\Services\Category\CategoryService;
*
* @package SP\Modules\Web\Controllers
*/
class CategoryController extends ControllerBase implements CrudControllerInterface
final class CategoryController extends ControllerBase implements CrudControllerInterface
{
use JsonTrait, ItemTrait;
@@ -236,7 +236,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa
}
try {
$form = new CategoryForm();
$form = new CategoryForm($this->dic);
$form->validate(Acl::CATEGORY_CREATE);
$itemData = $form->getItemData();
@@ -278,7 +278,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa
}
try {
$form = new CategoryForm($id);
$form = new CategoryForm($this->dic, $id);
$form->validate(Acl::CATEGORY_EDIT);
$itemData = $form->getItemData();

View File

@@ -43,7 +43,7 @@ use SP\Services\Client\ClientService;
*
* @package SP\Modules\Web\Controllers
*/
class ClientController extends ControllerBase implements CrudControllerInterface
final class ClientController extends ControllerBase implements CrudControllerInterface
{
use JsonTrait, ItemTrait;
@@ -232,7 +232,7 @@ class ClientController extends ControllerBase implements CrudControllerInterface
}
try {
$form = new ClientForm();
$form = new ClientForm($this->dic);
$form->validate(Acl::CLIENT_CREATE);
$itemData = $form->getItemData();
@@ -268,7 +268,7 @@ class ClientController extends ControllerBase implements CrudControllerInterface
}
try {
$form = new ClientForm($id);
$form = new ClientForm($this->dic, $id);
$form->validate(Acl::CLIENT_EDIT);
$this->clientService->update($form->getItemData());

View File

@@ -37,7 +37,7 @@ use SP\Modules\Web\Controllers\Traits\ConfigTrait;
*
* @package SP\Modules\Web\Controllers
*/
class ConfigAccountController extends SimpleControllerBase
final class ConfigAccountController extends SimpleControllerBase
{
use ConfigTrait;

View File

@@ -40,7 +40,7 @@ use SP\Services\Export\XmlVerifyService;
*
* @package SP\Modules\Web\Controllers
*/
class ConfigBackupController extends SimpleControllerBase
final class ConfigBackupController extends SimpleControllerBase
{
use ConfigTrait;

View File

@@ -44,7 +44,7 @@ use SP\Util\Util;
*
* @package SP\Modules\Web\Controllers
*/
class ConfigEncryptionController extends SimpleControllerBase
final class ConfigEncryptionController extends SimpleControllerBase
{
use JsonTrait;

View File

@@ -37,7 +37,7 @@ use SP\Modules\Web\Controllers\Traits\ConfigTrait;
*
* @package SP\Modules\Web\Controllers
*/
class ConfigGeneralController extends SimpleControllerBase
final class ConfigGeneralController extends SimpleControllerBase
{
use ConfigTrait;

View File

@@ -42,7 +42,7 @@ use SP\Services\Import\ImportService;
*
* @package SP\Modules\Web\Controllers
*/
class ConfigImportController extends SimpleControllerBase
final class ConfigImportController extends SimpleControllerBase
{
use JsonTrait;

View File

@@ -43,7 +43,7 @@ use SP\Services\Ldap\LdapImportService;
*
* @package SP\Modules\Web\Controllers
*/
class ConfigLdapController extends SimpleControllerBase
final class ConfigLdapController extends SimpleControllerBase
{
use ConfigTrait;

View File

@@ -39,7 +39,7 @@ use SP\Services\Mail\MailService;
*
* @package SP\Modules\Web\Controllers
*/
class ConfigMailController extends SimpleControllerBase
final class ConfigMailController extends SimpleControllerBase
{
use ConfigTrait;

View File

@@ -29,10 +29,10 @@ use SP\Core\Acl\Acl;
use SP\Core\Crypt\CryptSessionHandler;
use SP\Core\Events\Event;
use SP\Core\Language;
use SP\Core\Plugin\PluginUtil;
use SP\Modules\Web\Controllers\Helpers\TabsHelper;
use SP\Mvc\View\Components\DataTab;
use SP\Mvc\View\Components\SelectItemAdapter;
use SP\Plugin\PluginManager;
use SP\Providers\Log\DatabaseLogHandler;
use SP\Providers\Mail\MailHandler;
use SP\Services\Account\AccountService;
@@ -52,7 +52,7 @@ use SP\Util\Util;
*
* @package SP\Modules\Web\Controllers
*/
class ConfigManagerController extends ControllerBase
final class ConfigManagerController extends ControllerBase
{
/**
* @var TabsHelper
@@ -334,7 +334,7 @@ class ConfigManagerController extends ControllerBase
$template->assign('dbInfo', DatabaseUtil::getDBinfo($this->dic->get(MySQLHandler::class)));
$template->assign('dbName', $this->configData->getDbName() . '@' . $this->configData->getDbHost());
$template->assign('configBackupDate', date('r', $this->dic->get(ConfigService::class)->getByParam('config_backup_date', 0)));
$template->assign('plugins', PluginUtil::getLoadedPlugins());
$template->assign('plugins', $this->dic->get(PluginManager::class)->getLoadedPlugins());
$template->assign('locale', Language::$localeStatus ?: sprintf('%s (%s)', $this->configData->getSiteLang(), __('No instalado')));
$template->assign('securedSession', CryptSessionHandler::$isSecured);

View File

@@ -36,7 +36,7 @@ use SP\Modules\Web\Controllers\Traits\ConfigTrait;
*
* @package SP\Modules\Web\Controllers
*/
class ConfigWikiController extends SimpleControllerBase
final class ConfigWikiController extends SimpleControllerBase
{
use ConfigTrait;

View File

@@ -44,7 +44,7 @@ use SP\Services\CustomField\CustomFieldTypeService;
*
* @package SP\Modules\Web\Controllers
*/
class CustomFieldController extends ControllerBase implements CrudControllerInterface
final class CustomFieldController extends ControllerBase implements CrudControllerInterface
{
use JsonTrait, ItemTrait;
@@ -223,7 +223,7 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte
}
try {
$form = new CustomFieldDefForm();
$form = new CustomFieldDefForm($this->dic);
$form->validate(Acl::CUSTOMFIELD_CREATE);
$itemData = $form->getItemData();
@@ -258,7 +258,7 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte
}
try {
$form = new CustomFieldDefForm($id);
$form = new CustomFieldDefForm($this->dic, $id);
$form->validate(Acl::CUSTOMFIELD_EDIT);
$itemData = $form->getItemData();

View File

@@ -36,7 +36,7 @@ use SP\Mvc\View\Template;
*
* @package SP\Modules\Web\Controllers
*/
class ErrorController
final class ErrorController
{
/**
* @var Template
@@ -56,6 +56,7 @@ class ErrorController
*
* @param Container $container
* @param string $actionName
*
* @throws \DI\DependencyException
* @throws \DI\NotFoundException
*/

View File

@@ -38,7 +38,7 @@ use SP\Services\EventLog\EventlogService;
*
* @package SP\Modules\Web\Controllers
*/
class EventlogController extends ControllerBase
final class EventlogController extends ControllerBase
{
use JsonTrait, ItemTrait;

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -29,7 +29,7 @@ namespace SP\Modules\Web\Controllers\Helpers\Account;
*
* @package SP\Modules\Web\Controllers\Helpers\Account
*/
class AccountActionsDto
final class AccountActionsDto
{
/**
* @var int

View File

@@ -38,7 +38,7 @@ use SP\Services\Account\AccountSearchItem;
*
* @package SP\Modules\Web\Controllers\Helpers
*/
class AccountActionsHelper extends HelperBase
final class AccountActionsHelper extends HelperBase
{
/**
* @var ThemeIcons

View File

@@ -54,7 +54,7 @@ use SP\Services\UserGroup\UserGroupService;
*
* @package SP\Modules\Web\Controllers\Helpers
*/
class AccountHelper extends HelperBase
final class AccountHelper extends HelperBase
{
use ItemTrait;

View File

@@ -45,7 +45,7 @@ use SP\Services\User\UpdatedMasterPassException;
*
* @package SP\Modules\Web\Controllers\Helpers
*/
class AccountHistoryHelper extends HelperBase
final class AccountHistoryHelper extends HelperBase
{
/**
* @var Acl
@@ -81,6 +81,8 @@ class AccountHistoryHelper extends HelperBase
* @throws UpdatedMasterPassException
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
* @throws \SP\Repositories\NoSuchItemException
* @throws \SP\Services\ServiceException
*/
public function setView(AccountHistoryData $accountHistoryData, $actionId)
{

View File

@@ -39,7 +39,7 @@ use SP\Util\ImageUtil;
*
* @package SP\Modules\Web\Controllers\Helpers
*/
class AccountPasswordHelper extends HelperBase
final class AccountPasswordHelper extends HelperBase
{
const TYPE_NORMAL = 0;
const TYPE_FULL = 1;

View File

@@ -47,7 +47,7 @@ use SP\Services\Tag\TagService;
*
* @package SP\Modules\Web\Controllers\Helpers
*/
class AccountSearchHelper extends HelperBase
final class AccountSearchHelper extends HelperBase
{
/**
* @var bool Indica si el filtrado de cuentas está activo

View File

@@ -31,7 +31,7 @@ use Throwable;
* Class HelperException
* @package SP\Modules\Web\Controllers\Helpers
*/
class HelperException extends Exception
final class HelperException extends Exception
{
/**
* Construct the exception. Note: The message is NOT binary safe.

View File

@@ -49,7 +49,7 @@ use SP\Util\DateUtil;
*
* @package SP\Controller
*/
class ItemsGridHelper extends HelperBase
final class ItemsGridHelper extends HelperBase
{
/**
* @var float

View File

@@ -30,11 +30,11 @@ use SP\Core\Acl\ActionsInterface;
use SP\Core\Crypt\CryptPKI;
use SP\Core\Exceptions\SPException;
use SP\Core\Language;
use SP\Core\Plugin\PluginUtil;
use SP\Core\UI\Theme;
use SP\Core\UI\ThemeInterface;
use SP\Html\DataGrid\DataGridAction;
use SP\Http\Uri;
use SP\Plugin\PluginManager;
use SP\Services\Install\Installer;
use SP\Util\Util;
@@ -186,7 +186,7 @@ class LayoutHelper extends HelperBase
}
// Cargar los recursos de los plugins
foreach (PluginUtil::getLoadedPlugins() as $plugin) {
foreach ($this->dic->get(PluginManager::class)->getLoadedPlugins() as $plugin) {
$base = str_replace(BASE_PATH, '', $plugin->getBase());
$jsResources = $plugin->getJsResources();
$cssResources = $plugin->getCssResources();

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -31,7 +31,7 @@ use SP\Html\DataGrid\DataGridTab;
*
* @package SP\Modules\Web\Controllers\Helpers
*/
class TabsGridHelper extends HelperBase
final class TabsGridHelper extends HelperBase
{
/**
* Máximo numero de acciones antes de agrupar

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -31,7 +31,7 @@ use SP\Mvc\View\Components\DataTab;
*
* @package SP\Modules\Web\Controllers\Helpers
*/
class TabsHelper extends HelperBase
final class TabsHelper extends HelperBase
{
/**
* Máximo numero de acciones antes de agrupar

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -32,7 +32,7 @@ use SP\Modules\Web\Controllers\Helpers\LayoutHelper;
*
* @package SP\Modules\Web\Controllers
*/
class IndexController extends ControllerBase
final class IndexController extends ControllerBase
{
/**
* Index action

View File

@@ -41,7 +41,7 @@ use SP\Util\Checks;
*
* @package SP\Modules\Web\Controllers
*/
class InstallController extends ControllerBase
final class InstallController extends ControllerBase
{
use JsonTrait;

View File

@@ -43,7 +43,7 @@ use SP\Services\Tag\TagService;
*
* @package SP\Modules\Web\Controllers
*/
class ItemManagerController extends ControllerBase
final class ItemManagerController extends ControllerBase
{
/**
* @var ItemSearchData

View File

@@ -38,7 +38,7 @@ use SP\Util\Json;
*
* @package SP\Modules\Web\Controllers
*/
class ItemsController extends SimpleControllerBase
final class ItemsController extends SimpleControllerBase
{
/**
* Devolver las cuentas visibles por el usuario

View File

@@ -39,7 +39,7 @@ use SP\Services\Auth\LoginService;
*
* @package SP\Modules\Web\Controllers
*/
class LoginController extends ControllerBase
final class LoginController extends ControllerBase
{
use JsonTrait;

View File

@@ -45,7 +45,7 @@ use SP\Services\User\UserService;
*
* @package SP\Modules\Web\Controllers
*/
class NotificationController extends ControllerBase implements CrudControllerInterface
final class NotificationController extends ControllerBase implements CrudControllerInterface
{
use JsonTrait, ItemTrait;
@@ -315,7 +315,7 @@ class NotificationController extends ControllerBase implements CrudControllerInt
}
try {
$form = new NotificationForm();
$form = new NotificationForm($this->dic);
$form->validate(Acl::NOTIFICATION_CREATE);
$this->notificationService->create($form->getItemData());
@@ -346,7 +346,7 @@ class NotificationController extends ControllerBase implements CrudControllerInt
}
try {
$form = new NotificationForm($id);
$form = new NotificationForm($this->dic, $id);
$form->validate(Acl::NOTIFICATION_EDIT);
$this->notificationService->update($form->getItemData());

View File

@@ -41,7 +41,7 @@ use SP\Services\Plugin\PluginService;
*
* @package web\Controllers
*/
class PluginController extends ControllerBase
final class PluginController extends ControllerBase
{
use JsonTrait, ItemTrait;

View File

@@ -47,7 +47,7 @@ use SP\Util\Util;
*
* @package SP\Modules\Web\Controllers
*/
class PublicLinkController extends ControllerBase implements CrudControllerInterface
final class PublicLinkController extends ControllerBase implements CrudControllerInterface
{
use JsonTrait, ItemTrait;
@@ -266,7 +266,7 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter
}
try {
$form = new PublicLinkForm();
$form = new PublicLinkForm($this->dic);
$form->validate(Acl::PUBLICLINK_CREATE);
$this->publicLinkService->create($form->getItemData());

View File

@@ -32,7 +32,7 @@ use SP\Html\Minify;
*
* @package SP\Modules\Web\Controllers
*/
class ResourceController extends SimpleControllerBase
final class ResourceController extends SimpleControllerBase
{
/**
* @var Minify

View File

@@ -34,7 +34,7 @@ use SP\Util\Util;
*
* @package SP\Modules\Web\Controllers
*/
class StatusController extends SimpleControllerBase
final class StatusController extends SimpleControllerBase
{
use JsonTrait;

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -41,7 +41,7 @@ use SP\Services\Tag\TagService;
*
* @package SP\Modules\Web\Controllers
*/
class TagController extends ControllerBase implements CrudControllerInterface
final class TagController extends ControllerBase implements CrudControllerInterface
{
use JsonTrait, ItemTrait;
@@ -145,6 +145,7 @@ class TagController extends ControllerBase implements CrudControllerInterface
* Edit action
*
* @param $id
*
* @throws \Psr\Container\ContainerExceptionInterface
*/
public function editAction($id)
@@ -174,6 +175,7 @@ class TagController extends ControllerBase implements CrudControllerInterface
* Delete action
*
* @param $id
*
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
@@ -218,7 +220,7 @@ class TagController extends ControllerBase implements CrudControllerInterface
}
try {
$form = new TagForm();
$form = new TagForm($this->dic);
$form->validate(Acl::TAG_CREATE);
$this->tagService->create($form->getItemData());
@@ -247,7 +249,7 @@ class TagController extends ControllerBase implements CrudControllerInterface
}
try {
$form = new TagForm($id);
$form = new TagForm($this->dic, $id);
$form->validate(Acl::TAG_EDIT);
$this->tagService->update($form->getItemData());
@@ -268,6 +270,7 @@ class TagController extends ControllerBase implements CrudControllerInterface
* View action
*
* @param $id
*
* @throws \Psr\Container\ContainerExceptionInterface
*/
public function viewAction($id)

View File

@@ -37,7 +37,7 @@ use SP\Services\Task\TaskService;
*
* @package SP\Modules\Web\Controllers
*/
class TaskController
final class TaskController
{
/**
* @var Container

View File

@@ -37,7 +37,7 @@ use SP\Services\Upgrade\UpgradeUtil;
*
* @package SP\Modules\Web\Controllers
*/
class UpgradeController extends ControllerBase
final class UpgradeController extends ControllerBase
{
use JsonTrait;

View File

@@ -47,7 +47,7 @@ use SP\Services\UserProfile\UserProfileService;
*
* @package SP\Modules\Web\Controllers
*/
class UserController extends ControllerBase implements CrudControllerInterface
final class UserController extends ControllerBase implements CrudControllerInterface
{
use JsonTrait;
use ItemTrait;
@@ -299,7 +299,7 @@ class UserController extends ControllerBase implements CrudControllerInterface
}
try {
$form = new UserForm();
$form = new UserForm($this->dic);
$form->validate(Acl::USER_CREATE);
$itemData = $form->getItemData();
@@ -360,7 +360,7 @@ class UserController extends ControllerBase implements CrudControllerInterface
}
try {
$form = new UserForm($id);
$form = new UserForm($this->dic, $id);
$form->validate(Acl::USER_EDIT);
$itemData = $form->getItemData();
@@ -399,7 +399,7 @@ class UserController extends ControllerBase implements CrudControllerInterface
}
try {
$form = new UserForm($id);
$form = new UserForm($this->dic, $id);
$form->validate(Acl::USER_EDIT_PASS);
$itemData = $form->getItemData();

View File

@@ -45,7 +45,7 @@ use SP\Services\UserGroup\UserToUserGroupService;
*
* @package SP\Modules\Web\Controllers
*/
class UserGroupController extends ControllerBase implements CrudControllerInterface
final class UserGroupController extends ControllerBase implements CrudControllerInterface
{
use JsonTrait, ItemTrait;
@@ -239,7 +239,7 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf
}
try {
$form = new UserGroupForm();
$form = new UserGroupForm($this->dic);
$form->validate(Acl::GROUP_CREATE);
$groupData = $form->getItemData();
@@ -279,7 +279,7 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf
}
try {
$form = new UserGroupForm($id);
$form = new UserGroupForm($this->dic, $id);
$form->validate(Acl::GROUP_EDIT);
$groupData = $form->getItemData();

View File

@@ -43,7 +43,7 @@ use SP\Util\ErrorUtil;
*
* @package SP\Modules\Web\Controllers
*/
class UserPassResetController extends ControllerBase
final class UserPassResetController extends ControllerBase
{
use JsonTrait;
/**

View File

@@ -43,7 +43,7 @@ use SP\Services\UserProfile\UserProfileService;
*
* @package SP\Modules\Web\Controllers
*/
class UserProfileController extends ControllerBase implements CrudControllerInterface
final class UserProfileController extends ControllerBase implements CrudControllerInterface
{
use JsonTrait, ItemTrait;
@@ -234,7 +234,7 @@ class UserProfileController extends ControllerBase implements CrudControllerInte
}
try {
$form = new UserProfileForm();
$form = new UserProfileForm($this->dic);
$form->validate(Acl::PROFILE_CREATE);
$profileData = $form->getItemData();
@@ -270,7 +270,7 @@ class UserProfileController extends ControllerBase implements CrudControllerInte
}
try {
$form = new UserProfileForm($id);
$form = new UserProfileForm($this->dic, $id);
$form->validate(Acl::PROFILE_EDIT);
$profileData = $form->getItemData();

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -30,9 +30,10 @@ use SP\Services\User\UserService;
/**
* Class UserSettingsGeneralController
*
* @package SP\Modules\Web\Controllers
*/
class UserSettingsGeneralController extends SimpleControllerBase
final class UserSettingsGeneralController extends SimpleControllerBase
{
use JsonTrait;

View File

@@ -36,7 +36,7 @@ use SP\Mvc\View\Components\SelectItemAdapter;
*
* @package web\Controllers
*/
class UserSettingsManagerController extends ControllerBase
final class UserSettingsManagerController extends ControllerBase
{
/**
* @var TabsHelper

View File

@@ -33,7 +33,7 @@ use SP\Services\Account\AccountRequest;
*
* @package SP\Account
*/
class AccountForm extends FormBase implements FormInterface
final class AccountForm extends FormBase implements FormInterface
{
/**
* @var AccountRequest

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -33,7 +33,7 @@ use SP\DataModel\AuthTokenData;
*
* @package SP\Modules\Web\Forms
*/
class AuthTokenForm extends FormBase implements FormInterface
final class AuthTokenForm extends FormBase implements FormInterface
{
/**
* @var AuthTokenData
@@ -48,6 +48,7 @@ class AuthTokenForm extends FormBase implements FormInterface
* Validar el formulario
*
* @param $action
*
* @return AuthTokenForm
* @throws \SP\Core\Exceptions\ValidationException
*/

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -33,7 +33,7 @@ use SP\DataModel\CategoryData;
*
* @package SP\Modules\Web\Forms
*/
class CategoryForm extends FormBase implements FormInterface
final class CategoryForm extends FormBase implements FormInterface
{
/**
* @var CategoryData
@@ -44,6 +44,7 @@ class CategoryForm extends FormBase implements FormInterface
* Validar el formulario
*
* @param $action
*
* @return bool
* @throws \SP\Core\Exceptions\ValidationException
*/

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -33,7 +33,7 @@ use SP\DataModel\ClientData;
*
* @package SP\Modules\Web\Forms
*/
class ClientForm extends FormBase implements FormInterface
final class ClientForm extends FormBase implements FormInterface
{
/**
* @var ClientData
@@ -44,6 +44,7 @@ class ClientForm extends FormBase implements FormInterface
* Validar el formulario
*
* @param $action
*
* @return bool
* @throws \SP\Core\Exceptions\ValidationException
*/

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -33,7 +33,7 @@ use SP\DataModel\CustomFieldDefinitionData;
*
* @package SP\Modules\Web\Forms
*/
class CustomFieldDefForm extends FormBase implements FormInterface
final class CustomFieldDefForm extends FormBase implements FormInterface
{
/**
* @var CustomFieldDefinitionData
@@ -44,6 +44,7 @@ class CustomFieldDefForm extends FormBase implements FormInterface
* Validar el formulario
*
* @param $action
*
* @return bool
* @throws \SP\Core\Exceptions\ValidationException
*/

View File

@@ -24,11 +24,11 @@
namespace SP\Modules\Web\Forms;
use DI\Container;
use SP\Config\Config;
use SP\Config\ConfigData;
use SP\Core\Context\ContextInterface;
use SP\Core\Context\SessionContext;
use SP\Core\Dic\InjectableTrait;
use SP\Http\Request;
/**
@@ -38,8 +38,6 @@ use SP\Http\Request;
*/
abstract class FormBase
{
use InjectableTrait;
/**
* @var int
*/
@@ -64,31 +62,22 @@ abstract class FormBase
/**
* FormBase constructor.
*
* @param $itemId
* @param int $itemId
* @param Container $container
*
* @throws \SP\Core\Dic\ContainerException
* @throws \DI\DependencyException
* @throws \DI\NotFoundException
*/
public function __construct($itemId = null)
public function __construct(Container $container, $itemId = null)
{
// FIXME
$this->injectDependencies();
$this->config = $container->get(Config::class);
$this->configData = $this->config->getConfigData();
$this->context = $container->get(ContextInterface::class);
$this->request = $container->get(Request::class);
$this->itemId = $itemId;
}
/**
* @param Config $config
* @param ContextInterface $session
* @param Request $request
*/
public function inject(Config $config, ContextInterface $session, Request $request)
{
$this->config = $config;
$this->configData = $config->getConfigData();
$this->context = $session;
$this->request = $request;
}
/**
* Analizar los datos de la petición HTTP
*

View File

@@ -34,7 +34,7 @@ use SP\DataModel\NotificationData;
*
* @package SP\Modules\Web\Forms
*/
class NotificationForm extends FormBase implements FormInterface
final class NotificationForm extends FormBase implements FormInterface
{
/**
* @var NotificationData
@@ -45,6 +45,7 @@ class NotificationForm extends FormBase implements FormInterface
* Validar el formulario
*
* @param $action
*
* @return bool
* @throws \SP\Core\Exceptions\ValidationException
*/

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -27,7 +27,6 @@ namespace SP\Modules\Web\Forms;
use SP\Core\Acl\ActionsInterface;
use SP\Core\Exceptions\ValidationException;
use SP\DataModel\PublicLinkData;
use SP\Mgmt\PublicLinks\PublicLink;
use SP\Services\PublicLink\PublicLinkService;
/**
@@ -35,7 +34,7 @@ use SP\Services\PublicLink\PublicLinkService;
*
* @package SP\Modules\Web\Forms
*/
class PublicLinkForm extends FormBase implements FormInterface
final class PublicLinkForm extends FormBase implements FormInterface
{
/**
* @var PublicLinkData
@@ -46,9 +45,9 @@ class PublicLinkForm extends FormBase implements FormInterface
* Validar el formulario
*
* @param $action
*
* @return bool
* @throws ValidationException
* @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
*/
public function validate($action)
{

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -33,7 +33,7 @@ use SP\DataModel\TagData;
*
* @package SP\Modules\Web\Forms
*/
class TagForm extends FormBase implements FormInterface
final class TagForm extends FormBase implements FormInterface
{
/**
* @var TagData
@@ -44,6 +44,7 @@ class TagForm extends FormBase implements FormInterface
* Validar el formulario
*
* @param $action
*
* @return bool
* @throws \SP\Core\Exceptions\ValidationException
*/

View File

@@ -33,7 +33,7 @@ use SP\DataModel\UserData;
*
* @package SP\Modules\Web\Forms
*/
class UserForm extends FormBase implements FormInterface
final class UserForm extends FormBase implements FormInterface
{
/**
* @var UserData

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -33,7 +33,7 @@ use SP\DataModel\UserGroupData;
*
* @package SP\Modules\Web\Forms
*/
class UserGroupForm extends FormBase implements FormInterface
final class UserGroupForm extends FormBase implements FormInterface
{
/**
* @var UserGroupData
@@ -44,6 +44,7 @@ class UserGroupForm extends FormBase implements FormInterface
* Validar el formulario
*
* @param $action
*
* @return bool
* @throws \SP\Core\Exceptions\ValidationException
*/

View File

@@ -34,7 +34,7 @@ use SP\DataModel\UserProfileData;
*
* @package SP\Modules\Web\Forms
*/
class UserProfileForm extends FormBase implements FormInterface
final class UserProfileForm extends FormBase implements FormInterface
{
/**
* @var UserProfileData
@@ -45,6 +45,7 @@ class UserProfileForm extends FormBase implements FormInterface
* Validar el formulario
*
* @param $action
*
* @return bool
* @throws \SP\Core\Exceptions\ValidationException
*/

View File

@@ -36,6 +36,7 @@ use SP\Core\Crypt\UUIDCookie;
use SP\Core\Language;
use SP\Core\ModuleBase;
use SP\Core\UI\Theme;
use SP\Plugin\PluginManager;
use SP\Services\Crypt\SecureSessionService;
use SP\Services\Upgrade\UpgradeAppService;
use SP\Services\Upgrade\UpgradeDatabaseService;
@@ -50,7 +51,7 @@ use SP\Util\HttpUtil;
*
* @package SP\Modules\Web
*/
class Init extends ModuleBase
final class Init extends ModuleBase
{
/**
* List of controllers that don't need to perform fully initialization
@@ -61,19 +62,23 @@ class Init extends ModuleBase
/**
* @var SessionContext
*/
protected $context;
private $context;
/**
* @var Theme
*/
protected $theme;
private $theme;
/**
* @var Language
*/
protected $language;
private $language;
/**
* @var SecureSessionService
*/
protected $secureSessionService;
private $secureSessionService;
/**
* @var PluginManager
*/
private $pluginManager;
/**
* Init constructor.
@@ -91,6 +96,7 @@ class Init extends ModuleBase
$this->theme = $container->get(Theme::class);
$this->language = $container->get(Language::class);
$this->secureSessionService = $container->get(SecureSessionService::class);
$this->pluginManager = $container->get(PluginManager::class);
}
/**
@@ -176,10 +182,7 @@ class Init extends ModuleBase
$this->initUserSession();
// Load plugins
// PluginUtil::loadPlugins();
// Comprobar acciones en URL
// $this->checkPreLoginActions();
$this->pluginManager->loadPlugins();
if ($this->context->isLoggedIn() && $this->context->getAppStatus() === SessionContext::APP_STATUS_RELOADED) {
debugLog('Reload user profile');

View File

@@ -117,7 +117,7 @@
<div class="lowres-title"><?php echo __('Plugins Cargados'); ?></div>
<ul class="mdl-list">
<?php /** @var \SP\Core\Plugin\PluginInterface[] $plugins */
<?php /** @var \SP\Plugin\PluginInterface[] $plugins */
foreach ($plugins as $name => $plugin): ?>
<li class="mdl-list__item">
<span class="mdl-list__item-primary-content">

View File

@@ -1,6 +1,6 @@
<?php
/** @var \SP\DataModel\PluginData $plugin */
/** @var \SP\Core\Plugin\PluginInterface $pluginInfo */
/** @var \SP\Plugin\PluginInterface $pluginInfo */
/** @var \SP\Core\UI\ThemeIcons $icons */
?>
<div id="box-popup">

View File

@@ -33,11 +33,9 @@ use RuntimeException;
use SP\Config\Config;
use SP\Config\ConfigData;
use SP\Config\ConfigUtil;
use SP\Core\Context\ContextInterface;
use SP\Core\Exceptions\ConfigException;
use SP\Core\Exceptions\InitializationException;
use SP\Core\Language;
use SP\Core\UI\Theme;
use SP\Http\Request;
use SP\Modules\Api\Init as InitApi;
use SP\Modules\Web\Init as InitWeb;
@@ -46,6 +44,7 @@ use SP\Services\Api\JsonRpcResponse;
use SP\Services\Upgrade\UpgradeConfigService;
use SP\Services\Upgrade\UpgradeUtil;
use SP\Util\Checks;
use SP\Util\Filter;
use SP\Util\Util;
defined('APP_ROOT') || die();
@@ -57,10 +56,6 @@ defined('APP_ROOT') || die();
*/
final class Bootstrap
{
/**
* @var string The installation path on the server (e.g. /srv/www/syspass)
*/
public static $SERVERROOT = '';
/**
* @var string The current request path relative to the sysPass root (e.g. files/index.php)
*/
@@ -70,9 +65,9 @@ final class Bootstrap
*/
public static $WEBURI = '';
/**
* @var bool True if sysPass has been updated. Only for notices.
* @var string
*/
public static $UPDATED = false;
public static $SUBURI = '';
/**
* @var mixed
*/
@@ -81,34 +76,22 @@ final class Bootstrap
* @var bool Indica si la versión de PHP es correcta
*/
public static $checkPhpVersion;
/**
* @var string
*/
public static $SUBURI = '';
/**
* @var ContainerInterface|Container
*/
protected static $container;
/**
* @var ContextInterface
*/
protected $context;
/**
* @var Theme
*/
protected $theme;
private static $container;
/**
* @var Klein
*/
protected $router;
private $router;
/**
* @var Language
*/
protected $language;
private $language;
/**
* @var Request
*/
protected $request;
private $request;
/**
* @var Config
*/
@@ -146,9 +129,6 @@ final class Bootstrap
{
$oops = "Oops, it looks like this content doesn't exist...";
// Update request when we have a subdirectory
// $_SERVER['REQUEST_URI'] = self::$WEBROOT;
$this->router->onError(function ($router, $err_msg, $type, $err) {
debugLog('Routing error: ' . $err_msg);
@@ -201,26 +181,16 @@ final class Bootstrap
function ($request, $response, $service) use ($oops) {
try {
/** @var \Klein\Request $request */
$route = filter_var($request->param('r', 'index/index'), FILTER_SANITIZE_STRING);
$route = Filter::getString($request->param('r', 'index/index'));
if (!preg_match_all('#(?P<controller>[a-zA-Z]+)(?:/(?P<action>[a-zA-Z]+))?(?P<params>(/[a-zA-Z\d]+)+)?#', $route, $matches)) {
if (!preg_match_all('#(?P<controller>[a-zA-Z]+)(?:/(?P<action>[a-zA-Z]+))?(?P<params>/[a-zA-Z\d]+)?#', $route, $matches)) {
throw new RuntimeException($oops);
}
// $app = $matches['app'][0] ?: 'web';
$controller = $matches['controller'][0];
$method = !empty($matches['action'][0]) ? $matches['action'][0] . 'Action' : 'indexAction';
$params = [];
if (!empty($matches['params'][0])) {
foreach (explode('/', $matches['params'][0]) as $value) {
if (is_numeric($value)) {
$params[] = (int)filter_var($value, FILTER_SANITIZE_NUMBER_INT);
} elseif (!empty($value)) {
$params[] = filter_var($value, FILTER_SANITIZE_STRING);
}
}
}
$params = !empty($matches['params'][0]) ? Filter::getArray(explode('/', trim($matches['params'][0], '/'))) : [];
$controllerClass = 'SP\\Modules\\' . ucfirst(APP_MODULE) . '\\Controllers\\' . ucfirst($controller) . 'Controller';
@@ -326,7 +296,9 @@ final class Bootstrap
public function initPHPVars()
{
// Establecer el modo debug si una sesión de xdebug está activa
if (isset($_COOKIE['XDEBUG_SESSION']) && !defined('DEBUG')) {
if ($this->router->request()->cookies()->get('XDEBUG_SESSION')
&& !defined('DEBUG')
) {
define('DEBUG', true);
}
@@ -338,7 +310,10 @@ final class Bootstrap
ini_set('display_errors', 'Off');
}
if (!file_exists(LOG_FILE) && touch(LOG_FILE) && chmod(LOG_FILE, 0600)) {
if (!file_exists(LOG_FILE)
&& touch(LOG_FILE)
&& chmod(LOG_FILE, 0600)
) {
debugLog('Setup log file: ' . LOG_FILE);
}
@@ -358,14 +333,13 @@ final class Bootstrap
*/
private function initPaths()
{
self::$SERVERROOT = dirname(BASE_PATH);
self::$SUBURI = str_replace("\\", '/', substr(realpath($this->request->getServer('SCRIPT_FILENAME')), strlen(APP_ROOT)));
self::$SUBURI = str_replace("\\", '/', substr(realpath($_SERVER['SCRIPT_FILENAME']), strlen(self::$SERVERROOT)));
$scriptName = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
$scriptName = $this->request->getServer('REQUEST_URI');
if (substr($scriptName, -1) === '/') {
$scriptName .= 'index.php';
// Asegurar que suburi sigue las mismas reglas que scriptName
if (substr(self::$SUBURI, -9) !== 'index.php') {
if (substr(self::$SUBURI, -1) !== '/') {

View File

@@ -1,202 +0,0 @@
<?php
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, 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\Core\Dic;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use ReflectionMethod;
/**
* Class Dic
*
* @package SP\Core\Dic
*/
final class Container implements DicInterface
{
/**
* @var array Shared objects
*/
private $shared = [];
/**
* @var array Factory objects
*/
private $factory = [];
/**
* @var array Trasient objects (dinamically created and reusable)
*/
private $trasient = [];
/**
* Store shared object
*
* @param string $name
* @param callable $callable
*
* @internal param callable|string $class
*/
public function share($name, $callable = null)
{
$this->shared[$name] = $callable;
}
/**
* Store factory object
*
* @param string $name
* @param callable $callable
*
* @internal param callable|string $class
*/
public function add($name, $callable = null)
{
$this->factory[$name] = $callable;
}
/**
* Inject object
*
* @param $context
*
* @return mixed
* @throws \Psr\Container\ContainerExceptionInterface
*/
public function inject($context)
{
try {
$reflectionMethod = new ReflectionMethod($context, 'inject');
$methodParams = $reflectionMethod->getParameters();
$params = [];
if (!count($methodParams)) {
return false;
}
foreach ($methodParams as $key => $methodParam) {
if ($methodParam->getClass()) {
$className = $methodParam->getClass()->getName();
if ($this->has($className)) {
$params[$key] = $this->get($className);
} else {
$params[$key] = new $className;
}
} else {
$params[$key] = null;
}
}
return $reflectionMethod->invokeArgs($context, $params);
} catch (\ReflectionException $e) {
throw new ContainerException($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Returns true if the container can return an entry for the given identifier.
* Returns false otherwise.
*
* `has($id)` returning true does not mean that `get($id)` will not throw an exception.
* It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
*
* @param string $id Identifier of the entry to look for.
*
* @return bool
*/
public function has($id)
{
return array_key_exists($id, $this->shared) || array_key_exists($id, $this->factory);
}
/**
* Finds an entry of the container by its identifier and returns it.
*
* @param string $id Identifier of the entry to look for.
*
* @throws NotFoundExceptionInterface No entry was found for **this** identifier.
* @throws ContainerExceptionInterface Error while retrieving the entry.
*
* @return mixed Entry.
*/
public function get($id)
{
if (array_key_exists($id, $this->trasient)) {
return $this->trasient[$id];
}
if (array_key_exists($id, $this->factory)) {
return $this->getFactoryObject($id);
}
if (array_key_exists($id, $this->shared)) {
return $this->getSharedObject($id);
}
throw new NotFoundException(sprintf('Object not found (%s)', $id));
}
/**
* @param $id
*
* @return mixed
* @throws ContainerExceptionInterface
*/
private function getFactoryObject($id)
{
if (is_callable($this->factory[$id])) {
return $this->factory[$id]($this);
}
if (class_exists($id)) {
$trasient = new $id();
$this->trasient[$id] = $trasient;
return $trasient;
}
throw new ContainerException(sprintf('Invalid class (%s)', $id));
}
/**
* @param $id
*
* @return mixed
*/
private function getSharedObject($id)
{
if (get_class($this->shared[$id]) === $id) {
return $this->shared[$id];
}
if (is_callable($this->shared[$id])) {
$this->shared[$id] = $this->shared[$id]($this);
} elseif (class_exists($id)) {
$this->shared[$id] = new $id();
}
return $this->shared[$id];
}
}

View File

@@ -1,39 +0,0 @@
<?php
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, 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\Core\Dic;
use Exception;
use Psr\Container\ContainerExceptionInterface;
/**
* Class ContainerException
*
* @package SP\Core\Dic
*/
class ContainerException extends Exception implements ContainerExceptionInterface
{
}

View File

@@ -1,60 +0,0 @@
<?php
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, 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\Core\Dic;
use Psr\Container\ContainerInterface;
/**
* Interface DicInterface
*
* @package SP\Core\Dic
*/
interface DicInterface extends ContainerInterface
{
/**
* Store shared object
*
* @param string $name
* @param callable $callable
*/
public function share($name, $callable = null);
/**
* Store factory object
*
* @param string $name
* @param callable $callable
*/
public function add($name, $callable = null);
/**
* Inject object
*
* @param $context
*
* @return mixed
*/
public function inject($context);
}

View File

@@ -1,47 +0,0 @@
<?php
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, 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\Core\Dic;
use SP\Bootstrap;
/**
* Trait InjectTrait
*
* @package SP\Core\Traits
*/
trait InjectableTrait
{
/**
* Injects dependencies through the DI container
*
* @throws \SP\Core\Dic\ContainerException
*/
final protected function injectDependencies()
{
if (method_exists($this, 'inject')) {
Injector::inject(Bootstrap::getContainer(), $this);
}
}
}

View File

@@ -1,73 +0,0 @@
<?php
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, 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\Core\Dic;
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerExceptionInterface;
use ReflectionMethod;
/**
* Class Injector
*
* @package SP\Core\Dic
*/
class Injector
{
/**
* Inject object
*
* @param ContainerInterface $container
* @param $context
*
* @return mixed
* @throws ContainerException
*/
public static function inject(ContainerInterface $container, $context)
{
try {
$reflectionMethod = new ReflectionMethod($context, 'inject');
if ($reflectionMethod->getNumberOfParameters() === 0) {
return false;
}
$params = [];
foreach ($reflectionMethod->getParameters() as $key => $methodParam) {
if ($methodParam->getClass()) {
$params[$key] = $container->get($methodParam->getClass()->getName());
} else {
$params[$key] = null;
}
}
return $reflectionMethod->invokeArgs($context, $params);
} catch (\Exception $e) {
throw new ContainerException($e->getMessage(), $e->getCode(), $e);
} catch (ContainerExceptionInterface $e) {
throw new ContainerException($e->getMessage(), $e->getCode(), $e);
}
}
}

View File

@@ -1,38 +0,0 @@
<?php
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, 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\Core\Dic;
use Exception;
use Psr\Container\NotFoundExceptionInterface;
/**
* Class NotFoundException
*
* @package SP\Core\Dic
*/
class NotFoundException extends Exception implements NotFoundExceptionInterface
{
}

View File

@@ -1,93 +0,0 @@
<?php
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, 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\Core\Plugin;
use SP\DataModel\PluginData;
use SP\Log\Log;
use SP\Mgmt\Plugins\Plugin;
/**
* Class PluginDataStore
*
* @package SP\Core\Plugin
*/
class PluginDataStore
{
/**
* Guardar los datos de un plugin
*
* @param PluginInterface $Plugin
*
* @throws \SP\Core\Exceptions\SPException
*/
public static function save(PluginInterface $Plugin)
{
$PluginData = new PluginData();
$PluginData->setName($Plugin->getName());
$PluginData->setEnabled(1);
$PluginData->setData(serialize($Plugin->getData()));
Plugin::getItem($PluginData)->update();
}
/**
* Cargar los datos de un plugin
*
* @param PluginInterface $Plugin
*
* @return bool
* @throws \SP\Core\Exceptions\InvalidClassException
* @throws \SP\Core\Exceptions\SPException
*/
public static function load(PluginInterface $Plugin)
{
/** @var PluginData $PluginData */
$PluginData = Plugin::getItem()->getByName($Plugin->getName());
if (!is_object($PluginData)) {
$PluginData = new PluginData();
$PluginData->setName($Plugin->getName());
$PluginData->setEnabled(0);
Plugin::getItem($PluginData)->add();
$Log = new Log();
$Log->getLogMessage()
->setAction(__('Nuevo Plugin', false))
->addDetails(__('Nombre', false), $Plugin->getName());
$Log->writeLog();
return false;
}
$data = $PluginData->getData();
if ($data !== '') {
$Plugin->setData(unserialize($PluginData->getData()));
}
return (bool)$PluginData->getEnabled();
}
}

View File

@@ -1,245 +0,0 @@
<?php
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, 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\Core\Plugin;
use ReflectionClass;
use SP\Core\DiFactory;
use SP\Core\Exceptions\SPException;
use SP\Core\SessionFactory;
use SP\DataModel\PluginData;
use SP\Log\Log;
use SP\Mgmt\Plugins\Plugin;
/**
* Class PluginUtil
*
* @package SP\Core\Plugin
*/
class PluginUtil
{
/**
* @var array Plugins habilitados
*/
private static $enabledPlugins;
/**
* @var PluginInterface[] Plugins ya cargados
*/
private static $loadedPlugins = [];
/**
* @var array Plugins deshabilitados
*/
private static $disabledPlugins = [];
/**
* Devuelve la lista de Plugins disponibles
*
* @return array
*/
public static function getPlugins()
{
$pluginDirH = opendir(PLUGINS_PATH);
$plugins = [];
if ($pluginDirH) {
while (false !== ($entry = readdir($pluginDirH))) {
$pluginDir = PLUGINS_PATH . DIRECTORY_SEPARATOR . $entry;
if (strpos($entry, '.') === false
&& is_dir($pluginDir)
&& file_exists($pluginDir . DIRECTORY_SEPARATOR . $entry . 'Plugin.class.php')
) {
$plugins[] = $entry;
}
}
closedir($pluginDirH);
}
return $plugins;
}
/**
* Cargar un plugin
*
* @param string $name Nombre del plugin
*
* @return bool|PluginInterface
* @throws \SP\Core\Exceptions\SPException
*/
public static function loadPlugin($name)
{
$name = ucfirst($name);
if (in_array($name, SessionFactory::getPluginsDisabled(), true)) {
return false;
}
if (isset(self::$loadedPlugins[$name])) {
return self::$loadedPlugins[$name];
}
try {
$pluginClass = 'Plugins\\' . $name . '\\' . $name . 'Plugin';
$Reflection = new ReflectionClass($pluginClass);
/** @var PluginInterface $Plugin */
$Plugin = $Reflection->newInstance();
if (PluginDataStore::load($Plugin) === true) {
self::$loadedPlugins[$name] = $Plugin;
return $Plugin;
}
self::$disabledPlugins[] = $name;
} catch (\ReflectionException $e) {
Log::writeNewLog(__FUNCTION__,
sprintf(__('No es posible cargar el plugin "%s"'), $name));
} catch (SPException $e) {
Log::writeNewLog(__FUNCTION__,
sprintf(__('No es posible cargar el plugin "%s"'), $name));
}
return false;
}
/**
* Devolver los plugins cargados
*
* @return PluginInterface[]
*/
public static function getLoadedPlugins()
{
return self::$loadedPlugins;
}
/**
* Devolver los plugins deshabilidatos
*
* @return string[]
*/
public static function getDisabledPlugins()
{
return self::$disabledPlugins;
}
/**
* Obtener la información de un plugin
*
* @param string $name Nombre del plugin
*
* @return bool|PluginInterface
* @throws \SP\Core\Exceptions\SPException
*/
public static function getPluginInfo($name)
{
$name = ucfirst($name);
$pluginClass = 'Plugins\\' . $name . '\\' . $name . 'Plugin';
if (isset(self::$loadedPlugins[$name])) {
return self::$loadedPlugins[$name];
}
try {
$Reflection = new \ReflectionClass($pluginClass);
/** @var PluginBase $Plugin */
$Plugin = $Reflection->newInstance();
self::$loadedPlugins[$name] = $Plugin;
return $Plugin;
} catch (\ReflectionException $e) {
Log::writeNewLog(__FUNCTION__, sprintf(__('No es posible cargar el plugin "%s"'), $name));
}
return false;
}
/**
* Comprobar disponibilidad de plugins habilitados
*
* @throws \SP\Core\Exceptions\SPException
*/
public static function checkEnabledPlugins()
{
$PluginData = new PluginData();
$PluginData->setAvailable(false);
$PluginData->setEnabled(false);
foreach (self::getEnabledPlugins() as $plugin) {
if (!in_array($plugin, self::$loadedPlugins)) {
$PluginClone = clone $PluginData;
$PluginClone->setName($plugin);
Plugin::getItem($PluginClone)->toggleAvaliableByName();
}
}
}
/**
* Devolver los plugins habilitados
*
* @return PluginInterface[]
*/
public static function getEnabledPlugins()
{
if (self::$enabledPlugins !== null) {
return self::$enabledPlugins;
}
self::$enabledPlugins = [];
foreach (Plugin::getItem()->getEnabled() as $plugin) {
self::$enabledPlugins[] = $plugin->plugin_name;
}
return self::$enabledPlugins;
}
/**
* Cargar los Plugins disponibles
*
* @throws \SP\Core\Exceptions\SPException
*/
public static function loadPlugins()
{
$PluginsLoader = new \SplClassLoader('Plugins', PLUGINS_PATH);
$PluginsLoader->register();
foreach (self::getPlugins() as $plugin) {
$Plugin = self::loadPlugin($plugin);
if ($Plugin !== false) {
DiFactory::getEventDispatcher()->attach($Plugin);
}
}
SessionFactory::setPluginsLoaded(PluginUtil::getLoadedPlugins());
SessionFactory::setPluginsDisabled(PluginUtil::getDisabledPlugins());
}
}

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -22,12 +22,12 @@
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/
namespace SP\Core\Plugin;
namespace SP\Plugin;
/**
* Class PluginBase
*
* @package SP\Core\Plugin
* @package SP\Plugin
*/
abstract class PluginBase implements PluginInterface
{

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -22,7 +22,7 @@
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/
namespace SP\Core\Plugin;
namespace SP\Plugin;
use SP\Core\Events\Event;
use SplObserver;

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -22,12 +22,12 @@
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/
namespace SP\Core\Plugin;
namespace SP\Plugin;
/**
* Interface PluginInterface
*
* @package SP\Core\Plugin
* @package SP\Plugin
*/
interface PluginInterface extends PluginEventReceiver
{

View File

@@ -0,0 +1,282 @@
<?php
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, 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\Plugin;
use ReflectionClass;
use SP\Core\Context\ContextInterface;
use SP\Core\Events\Event;
use SP\Core\Events\EventDispatcher;
use SP\Core\Events\EventMessage;
use SP\DataModel\PluginData;
use SP\Repositories\NoSuchItemException;
use SP\Services\Plugin\PluginService;
/**
* Class PluginUtil
*
* @package SP\Plugin
*/
class PluginManager
{
/**
* @var array Plugins habilitados
*/
private $enabledPlugins;
/**
* @var PluginInterface[] Plugins ya cargados
*/
private $loadedPlugins = [];
/**
* @var array Plugins deshabilitados
*/
private $disabledPlugins = [];
/**
* @var PluginService
*/
private $pluginService;
/**
* @var ContextInterface
*/
private $context;
/**
* @var EventDispatcher
*/
private $eventDispatcher;
/**
* PluginManager constructor.
*
* @param PluginService $pluginService
* @param ContextInterface $context
* @param EventDispatcher $eventDispatcher
*/
public function __construct(PluginService $pluginService, ContextInterface $context, EventDispatcher $eventDispatcher)
{
$this->pluginService = $pluginService;
$this->context = $context;
$this->eventDispatcher = $eventDispatcher;
}
/**
* Obtener la información de un plugin
*
* @param string $name Nombre del plugin
*
* @return PluginInterface
*/
public function getPluginInfo($name)
{
$name = ucfirst($name);
$pluginClass = 'Plugins\\' . $name . '\\' . $name . 'Plugin';
if (isset($this->loadedPlugins[$name])) {
return $this->loadedPlugins[$name];
}
try {
$reflectionClass = new \ReflectionClass($pluginClass);
/** @var PluginBase $plugin */
$plugin = $reflectionClass->newInstance();
$this->loadedPlugins[$name] = $plugin;
return $plugin;
} catch (\ReflectionException $e) {
processException($e);
$this->eventDispatcher->notifyEvent('exception',
new Event($e, EventMessage::factory()
->addDescription(sprintf(__('No es posible cargar el plugin "%s"'), $name)))
);
}
return null;
}
/**
* Comprobar disponibilidad de plugins habilitados
*
* @throws \SP\Core\Exceptions\SPException
*/
public function checkEnabledPlugins()
{
foreach ($this->getEnabledPlugins() as $plugin) {
if (!in_array($plugin, $this->loadedPlugins)) {
$this->pluginService->toggleAvailableByName($plugin, false);
}
}
}
/**
* Devolver los plugins habilitados
*
* @return PluginInterface[]
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function getEnabledPlugins()
{
if ($this->enabledPlugins !== null) {
return $this->enabledPlugins;
}
$this->enabledPlugins = [];
foreach ($this->pluginService->getEnabled() as $plugin) {
$this->enabledPlugins[] = $plugin->getName();
}
return $this->enabledPlugins;
}
/**
* Cargar los Plugins disponibles
*/
public function loadPlugins()
{
$classLoader = new \SplClassLoader('Plugins', PLUGINS_PATH);
$classLoader->register();
foreach ($this->getPlugins() as $name) {
if (($plugin = $this->loadPlugin($name)) !== null) {
debugLog('Plugin loaded: ' . $name);
$this->eventDispatcher->attach($plugin);
}
}
}
/**
* Devuelve la lista de Plugins disponibles em el directorio
*
* @return array
*/
public function getPlugins()
{
$pluginDirH = opendir(PLUGINS_PATH);
$plugins = [];
if ($pluginDirH) {
while (false !== ($entry = readdir($pluginDirH))) {
$pluginDir = PLUGINS_PATH . DIRECTORY_SEPARATOR . $entry;
if (strpos($entry, '.') === false
&& is_dir($pluginDir)
&& file_exists($pluginDir . DIRECTORY_SEPARATOR . $entry . 'Plugin.php')
) {
$plugins[] = $entry;
}
}
closedir($pluginDirH);
}
return $plugins;
}
/**
* Cargar un plugin
*
* @param string $name Nombre del plugin
*
* @return PluginInterface
*/
public function loadPlugin($name)
{
$name = ucfirst($name);
if (isset($this->loadedPlugins[$name])) {
return $this->loadedPlugins[$name];
}
try {
$pluginClass = 'Plugins\\' . $name . '\\' . $name . 'Plugin';
$reflectionClass = new ReflectionClass($pluginClass);
/** @var PluginInterface $plugin */
$plugin = $reflectionClass->newInstance();
try {
$pluginData = $this->pluginService->getByName($plugin);
if ($pluginData->getEnabled() === 1) {
if (!empty($pluginData->getData())) {
$pluginData->setData(unserialize($pluginData->getData()));
}
return $plugin;
} else {
$this->disabledPlugins[] = $name;
}
} catch (NoSuchItemException $noSuchItemException) {
$pluginData = new PluginData();
$pluginData->setName($name);
$pluginData->setEnabled(0);
$this->pluginService->create($pluginData);
$this->eventDispatcher->notifyEvent('create.plugin',
new Event($this, EventMessage::factory()
->addDescription(__u('Nuevo Plugin'))
->addDetail(__u('Nombre'), $name)
));
$this->disabledPlugins[] = $name;
}
} catch (\Exception $e) {
processException($e);
$this->eventDispatcher->notifyEvent('exception',
new Event($e, EventMessage::factory()
->addDescription(sprintf(__('No es posible cargar el plugin "%s"'), $name)))
);
}
return null;
}
/**
* Devolver los plugins cargados
*
* @return PluginInterface[]
*/
public function getLoadedPlugins()
{
return $this->loadedPlugins;
}
/**
* Devolver los plugins deshabilidatos
*
* @return string[]
*/
public function getDisabledPlugins()
{
return $this->disabledPlugins;
}
}

View File

@@ -343,7 +343,7 @@ final class PluginRepository extends Repository implements RepositoryItemInterfa
{
$queryData = new QueryData();
$queryData->setQuery('UPDATE Plugin SET enabled = ? WHERE id = ? LIMIT 1');
$queryData->setParams([$enabled, $id]);
$queryData->setParams([(int)$enabled, $id]);
$queryData->setOnErrorMessage(__u('Error al actualizar el plugin'));
return $this->db->doQuery($queryData)->getAffectedNumRows();
@@ -363,7 +363,7 @@ final class PluginRepository extends Repository implements RepositoryItemInterfa
{
$queryData = new QueryData();
$queryData->setQuery('UPDATE Plugin SET enabled = ? WHERE name = ? LIMIT 1');
$queryData->setParams([$enabled, $name]);
$queryData->setParams([(int)$enabled, $name]);
$queryData->setOnErrorMessage(__u('Error al actualizar el plugin'));
return $this->db->doQuery($queryData)->getAffectedNumRows();
@@ -382,8 +382,8 @@ final class PluginRepository extends Repository implements RepositoryItemInterfa
public function toggleAvailable($id, $available)
{
$queryData = new QueryData();
$queryData->setQuery('UPDATE Plugin SET available = ? WHERE id = ? LIMIT 1');
$queryData->setParams([$available, $id]);
$queryData->setQuery('UPDATE Plugin SET available = ?, enabled = 0 WHERE id = ? LIMIT 1');
$queryData->setParams([(int)$available, $id]);
$queryData->setOnErrorMessage(__u('Error al actualizar el plugin'));
return $this->db->doQuery($queryData)->getAffectedNumRows();
@@ -402,8 +402,8 @@ final class PluginRepository extends Repository implements RepositoryItemInterfa
public function toggleAvailableByName($name, $available)
{
$queryData = new QueryData();
$queryData->setQuery('UPDATE Plugin SET available = ? WHERE `name` = ? LIMIT 1');
$queryData->setParams([$available, $name]);
$queryData->setQuery('UPDATE Plugin SET available = ?, enabled = 0 WHERE `name` = ? LIMIT 1');
$queryData->setParams([(int)$available, $name]);
$queryData->setOnErrorMessage(__u('Error al actualizar el plugin'));
return $this->db->doQuery($queryData)->getAffectedNumRows();
@@ -439,7 +439,7 @@ final class PluginRepository extends Repository implements RepositoryItemInterfa
{
$queryData = new QueryData();
$queryData->setMapClassName(ItemData::class);
$queryData->setQuery('SELECT id, `name` FROM Plugin WHERE enabled = 1 ORDER BY id');
$queryData->setQuery('SELECT id, `name` FROM Plugin WHERE available = 1 AND enabled = 1 ORDER BY id');
return $this->db->doSelect($queryData);
}

View File

@@ -245,8 +245,8 @@ final class PluginService extends Service
/**
* Cambiar el estado del plugin
*
* @param $name
* @param $available
* @param string $name
* @param int $available
*
* @throws NoSuchItemException
* @throws \SP\Core\Exceptions\ConstraintException

View File

@@ -50,9 +50,29 @@ final class Filter
*
* @return string
*/
public static function getString($value): string
public static function getEmail($value): string
{
return filter_var(trim($value), FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
return filter_var(trim($value), FILTER_SANITIZE_EMAIL);
}
/**
* @param array $array
*
* @return array
*/
public static function getArray(array $array): array
{
return array_map(function ($value) {
if ($value !== null) {
if (is_numeric($value)) {
return Filter::getInt($value);
} else {
return Filter::getString($value);
}
}
return null;
}, $array);
}
/**
@@ -70,8 +90,8 @@ final class Filter
*
* @return string
*/
public static function getEmail($value): string
public static function getString($value): string
{
return filter_var(trim($value), FILTER_SANITIZE_EMAIL);
return filter_var(trim($value), FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
}
}

View File

@@ -53,49 +53,6 @@ final class HttpUtil
}
}
/**
* Devolver las cabeceras enviadas desde el cliente.
*
* @param string $header nombre de la cabecera a devolver
*
* @return array|string
*/
public static function getRequestHeaders($header = '')
{
if (!empty($header)) {
$header = strpos($header, 'HTTP_') === false ? 'HTTP_' . str_replace('-', '_', strtoupper($header)) : $header;
return isset($_SERVER[$header]) ? $_SERVER[$header] : '';
}
return self::getApacheHeaders();
}
/**
* Función que sustituye a apache_request_headers
*
* @return array
*/
private static function getApacheHeaders()
{
if (function_exists('\apache_request_headers')) {
return apache_request_headers();
}
$headers = [];
foreach ($_SERVER as $key => $value) {
if (strpos($key, 'HTTP_') === 0) {
$key = ucwords(strtolower(str_replace('_', '-', substr($key, 5))), '-');
$headers[$key] = $value;
} else {
$headers[$key] = $value;
}
}
return $headers;
}
/**
* Comprobar si existen parámetros pasados por POST para enviarlos por GET
*/