chore: Refactor EventDispatcher and observer pattern

Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
Rubén D
2023-11-03 12:15:48 +01:00
parent 0692487f37
commit dd43b9842f
218 changed files with 1070 additions and 931 deletions

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -53,7 +53,7 @@ final class CreateController extends AccountBase
$accountDetails = $this->accountService->getByIdEnriched($accountId)->getAccountVData();
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'create.account',
new Event(
$this,

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -50,7 +50,7 @@ final class DeleteController extends AccountBase
$this->accountService->delete($id);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'delete.account',
new Event(
$this,

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -50,7 +50,7 @@ final class EditController extends AccountBase
$accountDetails = $this->accountService->getByIdEnriched($accountRequest->id)->getAccountVData();
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'edit.account',
new Event(
$this,

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -52,7 +52,7 @@ final class EditPassController extends AccountBase
$accountDetails = $this->accountService->getByIdEnriched($accountRequest->id)->getAccountVData();
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'edit.account.pass',
new Event(
$this,

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -64,7 +64,7 @@ final class ViewController extends AccountBase
$accountEnrichedDto = $this->accountService->withUserGroups($accountEnrichedDto);
$accountEnrichedDto = $this->accountService->withTags($accountEnrichedDto);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'show.account',
new Event(
$this,

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -57,7 +57,7 @@ final class ViewPassController extends AccountBase
$accountDetails = $this->accountService->getByIdEnriched($id)->getAccountVData();
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'show.account.pass',
new Event(
$this,

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -51,7 +51,7 @@ final class CreateController extends CategoryBase
$categoryData->setId($id);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'create.category',
new Event(
$this,
@@ -82,4 +82,4 @@ final class CreateController extends CategoryBase
return $categoryData;
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -50,7 +50,7 @@ final class DeleteController extends CategoryBase
$this->categoryService->delete($id);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'delete.category',
new Event(
$this,
@@ -68,4 +68,4 @@ final class DeleteController extends CategoryBase
$this->returnResponseException($e);
}
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -46,7 +46,7 @@ final class EditController extends CategoryBase
$this->categoryService->update($categoryData);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'edit.category',
new Event(
$this,
@@ -80,4 +80,4 @@ final class EditController extends CategoryBase
return $categoryData;
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -46,7 +46,7 @@ final class SearchController extends CategoryBase
$itemSearchData = $this->buildSearchData();
$this->eventDispatcher->notifyEvent('search.category', new Event($this));
$this->eventDispatcher->notify('search.category', new Event($this));
$this->returnResponse(
ApiResponse::makeSuccess(
@@ -74,4 +74,4 @@ final class SearchController extends CategoryBase
return $itemSearchData;
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -53,7 +53,7 @@ final class ViewController extends CategoryBase
$categoryData = $this->categoryService->getById($id);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'show.category',
new Event(
$this,
@@ -78,4 +78,4 @@ final class ViewController extends CategoryBase
$this->returnResponseException($e);
}
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -51,7 +51,7 @@ final class CreateController extends ClientBase
$clientData->setId($id);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'create.client',
new Event(
$this,
@@ -83,4 +83,4 @@ final class CreateController extends ClientBase
return $clientData;
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -50,7 +50,7 @@ final class DeleteController extends ClientBase
$this->clientService->delete($id);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'delete.client',
new Event(
$this,
@@ -68,4 +68,4 @@ final class DeleteController extends ClientBase
processException($e);
}
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -49,7 +49,7 @@ final class EditController extends ClientBase
$this->clientService->update($clientData);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'edit.client',
new Event(
$this,
@@ -82,4 +82,4 @@ final class EditController extends ClientBase
return $clientData;
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -46,7 +46,7 @@ final class SearchController extends ClientBase
$itemSearchData = $this->buildSearchData();
$this->eventDispatcher->notifyEvent('search.client', new Event($this));
$this->eventDispatcher->notify('search.client', new Event($this));
$this->returnResponse(
ApiResponse::makeSuccess(
@@ -74,4 +74,4 @@ final class SearchController extends ClientBase
return $itemSearchData;
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -51,9 +51,9 @@ final class ViewController extends ClientBase
$clientData = $this->clientService->getById($id);
$this->eventDispatcher->notifyEvent('show.client', new Event($this));
$this->eventDispatcher->notify('show.client', new Event($this));
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'show.client',
new Event(
$this,
@@ -84,4 +84,4 @@ final class ViewController extends ClientBase
$this->returnResponseException($e);
}
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -76,7 +76,7 @@ final class BackupController extends ControllerBase
$this->fileBackupService->doBackup($path);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'run.backup.end',
new Event(
$this,

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -73,7 +73,7 @@ final class ExportController extends ControllerBase
$password = $this->apiService->getParamString('password');
$path = $this->apiService->getParamString('path', false, BACKUP_PATH);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'run.export.start',
new Event(
$this,
@@ -86,7 +86,7 @@ final class ExportController extends ControllerBase
$this->xmlExportService->doExport($path, $password);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'run.export.end',
new Event($this, EventMessage::factory()->addDescription(__u('Export process finished')))
);

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -51,7 +51,7 @@ final class CreateController extends TagBase
$tagData->setId($id);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'create.tag',
new Event(
$this,
@@ -81,4 +81,4 @@ final class CreateController extends TagBase
return $tagData;
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -50,7 +50,7 @@ final class DeleteController extends TagBase
$this->tagService->delete($id);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'delete.tag',
new Event(
$this,
@@ -69,4 +69,4 @@ final class DeleteController extends TagBase
}
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -49,7 +49,7 @@ final class EditController extends TagBase
$this->tagService->update($tagData);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'edit.tag',
new Event(
$this,
@@ -80,4 +80,4 @@ final class EditController extends TagBase
return $tagData;
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -46,7 +46,7 @@ final class SearchController extends TagBase
$itemSearchData = $this->buildSearchData();
$this->eventDispatcher->notifyEvent('search.tag', new Event($this));
$this->eventDispatcher->notify('search.tag', new Event($this));
$this->returnResponse(
ApiResponse::makeSuccess(
$this->tagService->search($itemSearchData)->getDataAsArray()

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -48,7 +48,7 @@ final class ViewController extends TagBase
$id = $this->apiService->getParamInt('id', true);
$tagData = $this->tagService->getById($id);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'show.tag',
new Event($this, EventMessage::factory()
->addDescription(__u('Tag displayed'))
@@ -64,4 +64,4 @@ final class ViewController extends TagBase
$this->returnResponseException($e);
}
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -51,7 +51,7 @@ final class CreateController extends UserGroupBase
$userGroupData->setId($id);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'create.userGroup',
new Event(
$this, EventMessage::factory()
@@ -82,4 +82,4 @@ final class CreateController extends UserGroupBase
return $userGroupData;
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -50,7 +50,7 @@ final class DeleteController extends UserGroupBase
$this->userGroupService->delete($id);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'delete.userGroup',
new Event(
$this,
@@ -69,4 +69,4 @@ final class DeleteController extends UserGroupBase
$this->returnResponseException($e);
}
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -49,7 +49,7 @@ final class EditController extends UserGroupBase
$this->userGroupService->update($userGroupData);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'edit.userGroup',
new Event(
$this,
@@ -85,4 +85,4 @@ final class EditController extends UserGroupBase
return $userGroupData;
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -46,7 +46,7 @@ final class SearchController extends UserGroupBase
$itemSearchData = $this->buildSearchData();
$this->eventDispatcher->notifyEvent('search.userGroup', new Event($this));
$this->eventDispatcher->notify('search.userGroup', new Event($this));
$this->returnResponse(
ApiResponse::makeSuccess($this->userGroupService->search($itemSearchData)->getDataAsArray())
@@ -70,4 +70,4 @@ final class SearchController extends UserGroupBase
return $itemSearchData;
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -48,7 +48,7 @@ final class ViewController extends UserGroupBase
$id = $this->apiService->getParamInt('id', true);
$userGroupData = $this->userGroupService->getById($id);
$this->eventDispatcher->notifyEvent(
$this->eventDispatcher->notify(
'show.userGroup',
new Event(
$this,
@@ -68,4 +68,4 @@ final class ViewController extends UserGroupBase
$this->returnResponseException($e);
}
}
}
}