Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Bee-color framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jordan Breton
Bee-color framework
Commits
04281b5a
Commit
04281b5a
authored
Jul 26, 2019
by
Jordan Breton
✏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP command & query embeded security (spliting app security level and domain security concerns)
parent
bc935d9c
Changes
117
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
117 changed files
with
750 additions
and
283 deletions
+750
-283
daemons/modelSupervisor/server/components/writer/modelManager/MMDomainEventManager.php
...r/components/writer/modelManager/MMDomainEventManager.php
+2
-2
daemons/modelSupervisor/server/components/writer/modelManager/ModelManager.php
...or/server/components/writer/modelManager/ModelManager.php
+1
-1
engine/config/lang/en.lang.json
engine/config/lang/en.lang.json
+6
-3
engine/config/lang/fr.lang.json
engine/config/lang/fr.lang.json
+4
-1
engine/core/app/WebApp.php
engine/core/app/WebApp.php
+1
-1
engine/core/app/context/DefaultContext.php
engine/core/app/context/DefaultContext.php
+18
-4
engine/core/cache/ICacheSystem.php
engine/core/cache/ICacheSystem.php
+3
-3
engine/core/cache/systems/APCUBasedCache.php
engine/core/cache/systems/APCUBasedCache.php
+2
-2
engine/core/cache/systems/MemoryCache.php
engine/core/cache/systems/MemoryCache.php
+123
-0
engine/core/cache/systems/NoCache.php
engine/core/cache/systems/NoCache.php
+2
-2
engine/core/command/Command.php
engine/core/command/Command.php
+15
-5
engine/core/command/CommandDispatcher.php
engine/core/command/CommandDispatcher.php
+2
-2
engine/core/command/CommandHandlerFactory.php
engine/core/command/CommandHandlerFactory.php
+1
-1
engine/core/command/ICommand.php
engine/core/command/ICommand.php
+6
-1
engine/core/command/ICommandBus.php
engine/core/command/ICommandBus.php
+1
-1
engine/core/command/ICommandDispatcher.php
engine/core/command/ICommandDispatcher.php
+1
-1
engine/core/command/ICommandHandler.php
engine/core/command/ICommandHandler.php
+1
-1
engine/core/command/ICommandHandlerFactory.php
engine/core/command/ICommandHandlerFactory.php
+1
-1
engine/core/command/ICommandInflector.php
engine/core/command/ICommandInflector.php
+1
-1
engine/core/command/InflectorBasedCommandDispatcher.php
engine/core/command/InflectorBasedCommandDispatcher.php
+3
-3
engine/core/command/SynchroneCommandBus.php
engine/core/command/SynchroneCommandBus.php
+16
-9
engine/core/command/inflectors/NamespaceBasedInflector.php
engine/core/command/inflectors/NamespaceBasedInflector.php
+2
-2
engine/core/command/security/CommandAccessRuleFactory.php
engine/core/command/security/CommandAccessRuleFactory.php
+32
-0
engine/core/command/security/CommandSecurityCenter.php
engine/core/command/security/CommandSecurityCenter.php
+35
-0
engine/core/command/security/ICommandAccessRuleFactory.php
engine/core/command/security/ICommandAccessRuleFactory.php
+17
-0
engine/core/command/security/ICommandSecurityCenter.php
engine/core/command/security/ICommandSecurityCenter.php
+16
-0
engine/core/command/security/errors/RejectedCommand.php
engine/core/command/security/errors/RejectedCommand.php
+10
-0
engine/core/command/security/rules/AllCommandsAllowed.php
engine/core/command/security/rules/AllCommandsAllowed.php
+18
-0
engine/core/command/security/rules/AllCommandsDenied.php
engine/core/command/security/rules/AllCommandsDenied.php
+18
-0
engine/core/command/security/rules/AndCommandAccessRule.php
engine/core/command/security/rules/AndCommandAccessRule.php
+41
-0
engine/core/command/security/rules/CommandAccessAccessRulesCollector.php
...mand/security/rules/CommandAccessAccessRulesCollector.php
+34
-0
engine/core/command/security/rules/ICommandAccessRule.php
engine/core/command/security/rules/ICommandAccessRule.php
+16
-0
engine/core/command/security/rules/ICommandAccessRulesCollector.php
...e/command/security/rules/ICommandAccessRulesCollector.php
+13
-0
engine/core/command/security/rules/OrCommandAccessRule.php
engine/core/command/security/rules/OrCommandAccessRule.php
+37
-0
engine/core/data/model/InMemoryEventBasedModel.php
engine/core/data/model/InMemoryEventBasedModel.php
+1
-1
engine/core/data/model/snapshoter/ModelSnapshoter.php
engine/core/data/model/snapshoter/ModelSnapshoter.php
+2
-2
engine/core/domain/events/DomainEventListenerFactory.php
engine/core/domain/events/DomainEventListenerFactory.php
+1
-1
engine/core/domain/events/IDomainEventDispatcher.php
engine/core/domain/events/IDomainEventDispatcher.php
+2
-2
engine/core/domain/events/IDomainEventListener.php
engine/core/domain/events/IDomainEventListener.php
+1
-1
engine/core/domain/events/IDomainEventListenerFactory.php
engine/core/domain/events/IDomainEventListenerFactory.php
+1
-1
engine/core/domain/events/IDomainEventObserver.php
engine/core/domain/events/IDomainEventObserver.php
+3
-3
engine/core/domain/events/observers/ConfBasedDomainEventObserver.php
.../domain/events/observers/ConfBasedDomainEventObserver.php
+13
-13
engine/core/domain/events/observers/DomainEventObserver.php
engine/core/domain/events/observers/DomainEventObserver.php
+7
-7
engine/core/domain/events/store/DBBasedEventStore.php
engine/core/domain/events/store/DBBasedEventStore.php
+7
-7
engine/core/domain/events/store/IEventStore.php
engine/core/domain/events/store/IEventStore.php
+4
-4
engine/core/domain/repository/AggregateRootRepository.php
engine/core/domain/repository/AggregateRootRepository.php
+16
-16
engine/core/domain/repository/IAggregateRootRepository.php
engine/core/domain/repository/IAggregateRootRepository.php
+8
-8
engine/core/security/AccessControlCenter.php
engine/core/security/AccessControlCenter.php
+2
-2
engine/core/security/IAccessControlCenter.php
engine/core/security/IAccessControlCenter.php
+2
-2
engine/core/security/rules/RequireAuthentification.php
engine/core/security/rules/RequireAuthentification.php
+3
-7
engine/core/security/rules/UserTypeBasedAccess.php
engine/core/security/rules/UserTypeBasedAccess.php
+22
-8
engine/core/security/rules/ValidToken.php
engine/core/security/rules/ValidToken.php
+18
-13
engine/package/contact/command/handlers/ArchiveContactsHandler.php
...ckage/contact/command/handlers/ArchiveContactsHandler.php
+1
-1
engine/package/contact/command/handlers/CreateContactHandler.php
...package/contact/command/handlers/CreateContactHandler.php
+1
-1
engine/package/contact/command/handlers/MarkContactsAsReadHandler.php
...ge/contact/command/handlers/MarkContactsAsReadHandler.php
+1
-1
engine/package/contact/command/handlers/MarkContactsAsUnreadHandler.php
.../contact/command/handlers/MarkContactsAsUnreadHandler.php
+1
-1
engine/package/contact/command/handlers/UnarchiveContactsHandler.php
...age/contact/command/handlers/UnarchiveContactsHandler.php
+1
-1
engine/package/contact/domain/repository/ContactRepository.php
...e/package/contact/domain/repository/ContactRepository.php
+5
-5
engine/package/contact/handlers/action/ArchiveHandler.php
engine/package/contact/handlers/action/ArchiveHandler.php
+2
-2
engine/package/contact/handlers/action/MarkAsReadHandler.php
engine/package/contact/handlers/action/MarkAsReadHandler.php
+2
-2
engine/package/contact/handlers/action/MarkAsUnreadHandler.php
...e/package/contact/handlers/action/MarkAsUnreadHandler.php
+2
-2
engine/package/contact/handlers/action/UnarchiveHandler.php
engine/package/contact/handlers/action/UnarchiveHandler.php
+2
-2
engine/package/general/handlers/action/PostDataDefaultActionHandler.php
.../general/handlers/action/PostDataDefaultActionHandler.php
+2
-2
engine/package/news/command/handlers/ArchiveArticlesHandler.php
.../package/news/command/handlers/ArchiveArticlesHandler.php
+1
-1
engine/package/news/command/handlers/CreateArticleHandler.php
...ne/package/news/command/handlers/CreateArticleHandler.php
+1
-1
engine/package/news/command/handlers/EditArticleHandler.php
engine/package/news/command/handlers/EditArticleHandler.php
+1
-1
engine/package/news/command/handlers/PutArticlesOfflineHandler.php
...ckage/news/command/handlers/PutArticlesOfflineHandler.php
+1
-1
engine/package/news/command/handlers/PutArticlesOnlineHandler.php
...ackage/news/command/handlers/PutArticlesOnlineHandler.php
+1
-1
engine/package/news/command/handlers/UnarchiveArticlesHandler.php
...ackage/news/command/handlers/UnarchiveArticlesHandler.php
+1
-1
engine/package/news/domain/repository/ArticleRepository.php
engine/package/news/domain/repository/ArticleRepository.php
+4
-4
engine/package/news/handlers/action/ArchiveHandler.php
engine/package/news/handlers/action/ArchiveHandler.php
+2
-2
engine/package/news/handlers/action/CreateHandler.php
engine/package/news/handlers/action/CreateHandler.php
+2
-2
engine/package/news/handlers/action/EditHandler.php
engine/package/news/handlers/action/EditHandler.php
+4
-4
engine/package/news/handlers/action/PutOfflineHandler.php
engine/package/news/handlers/action/PutOfflineHandler.php
+2
-2
engine/package/news/handlers/action/PutOnlineHandler.php
engine/package/news/handlers/action/PutOnlineHandler.php
+2
-2
engine/package/news/handlers/action/UnarchiveHandler.php
engine/package/news/handlers/action/UnarchiveHandler.php
+2
-2
engine/package/users/command/handlers/CancelMailChangeHandler.php
...ackage/users/command/handlers/CancelMailChangeHandler.php
+1
-1
engine/package/users/command/handlers/CancelPasswordRetrievingHandler.php
...sers/command/handlers/CancelPasswordRetrievingHandler.php
+1
-1
engine/package/users/command/handlers/CancelUserRegistrationHandler.php
.../users/command/handlers/CancelUserRegistrationHandler.php
+1
-1
engine/package/users/command/handlers/ChangeLoginHandler.php
engine/package/users/command/handlers/ChangeLoginHandler.php
+1
-1
engine/package/users/command/handlers/ChangePasswordHandler.php
.../package/users/command/handlers/ChangePasswordHandler.php
+1
-1
engine/package/users/command/handlers/ChangeTypeHandler.php
engine/package/users/command/handlers/ChangeTypeHandler.php
+1
-1
engine/package/users/command/handlers/ChangeUserMailHandler.php
.../package/users/command/handlers/ChangeUserMailHandler.php
+1
-1
engine/package/users/command/handlers/ConfirmUserMailChangeHandler.php
...e/users/command/handlers/ConfirmUserMailChangeHandler.php
+1
-1
engine/package/users/command/handlers/ConfirmUserRegistrationHandler.php
...users/command/handlers/ConfirmUserRegistrationHandler.php
+1
-1
engine/package/users/command/handlers/DisableUsersHandler.php
...ne/package/users/command/handlers/DisableUsersHandler.php
+1
-1
engine/package/users/command/handlers/EnableUsersHandler.php
engine/package/users/command/handlers/EnableUsersHandler.php
+1
-1
engine/package/users/command/handlers/RegisterUserHandler.php
...ne/package/users/command/handlers/RegisterUserHandler.php
+1
-1
engine/package/users/command/handlers/RemoveUsersHandler.php
engine/package/users/command/handlers/RemoveUsersHandler.php
+1
-1
engine/package/users/command/handlers/ResetPasswordHandler.php
...e/package/users/command/handlers/ResetPasswordHandler.php
+1
-1
engine/package/users/command/handlers/RetrievePasswordHandler.php
...ackage/users/command/handlers/RetrievePasswordHandler.php
+1
-1
engine/package/users/domain/repository/UserRepository.php
engine/package/users/domain/repository/UserRepository.php
+8
-8
engine/package/users/handlers/action/CancelChangeMailHandler.php
...package/users/handlers/action/CancelChangeMailHandler.php
+3
-3
engine/package/users/handlers/action/ChangeMailConfirmationHandler.php
...e/users/handlers/action/ChangeMailConfirmationHandler.php
+4
-4
engine/package/users/handlers/action/ChangeMailHandler.php
engine/package/users/handlers/action/ChangeMailHandler.php
+2
-2
engine/package/users/handlers/action/ChangePasswordHandler.php
...e/package/users/handlers/action/ChangePasswordHandler.php
+2
-2
engine/package/users/handlers/action/ConfirmUserRegistrationHandler.php
.../users/handlers/action/ConfirmUserRegistrationHandler.php
+3
-3
engine/package/users/handlers/action/ForgottenPasswordHandler.php
...ackage/users/handlers/action/ForgottenPasswordHandler.php
+2
-2
engine/package/users/handlers/action/LoginHandler.php
engine/package/users/handlers/action/LoginHandler.php
+1
-1
engine/package/users/handlers/action/RegisterHandler.php
engine/package/users/handlers/action/RegisterHandler.php
+3
-3
engine/package/users/handlers/action/ResendChangeMailHandler.php
...package/users/handlers/action/ResendChangeMailHandler.php
+2
-2
engine/package/users/handlers/action/ResendForgottenPasswordMailHandler.php
...rs/handlers/action/ResendForgottenPasswordMailHandler.php
+2
-2
engine/package/users/handlers/action/ResetPasswordHandler.php
...ne/package/users/handlers/action/ResetPasswordHandler.php
+3
-3
engine/package/users/handlers/action/admin/CancelChangeMailHandler.php
...e/users/handlers/action/admin/CancelChangeMailHandler.php
+2
-2
engine/package/users/handlers/action/admin/CancelResetPasswordHandler.php
...sers/handlers/action/admin/CancelResetPasswordHandler.php
+2
-2
engine/package/users/handlers/action/admin/CancelUserRegistrationHandler.php
...s/handlers/action/admin/CancelUserRegistrationHandler.php
+2
-2
engine/package/users/handlers/action/admin/ChangeMailHandler.php
...package/users/handlers/action/admin/ChangeMailHandler.php
+2
-2
engine/package/users/handlers/action/admin/ChangeTypeHandler.php
...package/users/handlers/action/admin/ChangeTypeHandler.php
+2
-2
engine/package/users/handlers/action/admin/DisableHandler.php
...ne/package/users/handlers/action/admin/DisableHandler.php
+2
-2
engine/package/users/handlers/action/admin/EnableHandler.php
engine/package/users/handlers/action/admin/EnableHandler.php
+2
-2
engine/package/users/handlers/action/admin/RegisterHandler.php
...e/package/users/handlers/action/admin/RegisterHandler.php
+2
-2
engine/package/users/handlers/action/admin/RemoveHandler.php
engine/package/users/handlers/action/admin/RemoveHandler.php
+2
-2
engine/package/users/handlers/action/admin/ResetPasswordHandler.php
...kage/users/handlers/action/admin/ResetPasswordHandler.php
+2
-2
tests/PHPUnit/integration/modules/contact/ContactTest.php
tests/PHPUnit/integration/modules/contact/ContactTest.php
+4
-4
tests/PHPUnit/unit/modules/contact/data/model/ContactModelTest.php
...Unit/unit/modules/contact/data/model/ContactModelTest.php
+2
-2
tests/PHPUnit/unit/modules/news/data/model/ArticleModelTest.php
...PHPUnit/unit/modules/news/data/model/ArticleModelTest.php
+3
-3
tests/PHPUnit/unit/modules/users/data/model/UserModelTest.php
...s/PHPUnit/unit/modules/users/data/model/UserModelTest.php
+15
-15
No files found.
daemons/modelSupervisor/server/components/writer/modelManager/MMDomainEventManager.php
View file @
04281b5a
...
...
@@ -15,8 +15,8 @@ final class MMDomainEventManager extends DomainEventObserver {
/**
* @param IDomainEvent $e
*/
public
function
dispatch
(
IDomainEvent
$e
):
void
{
parent
::
dispatch
(
$e
);
public
function
dispatch
DomainEvent
(
IDomainEvent
$e
):
void
{
parent
::
dispatch
DomainEvent
(
$e
);
foreach
(
$this
->
getListeners
()
as
$listened
=>
$listeners
){
if
(
$e
instanceof
$listened
){
foreach
(
$listeners
as
$listener
){
...
...
daemons/modelSupervisor/server/components/writer/modelManager/ModelManager.php
View file @
04281b5a
...
...
@@ -243,7 +243,7 @@ final class ModelManager implements IModelManager, ICrossModelAccess {
$this
->
_models
[
get_class
(
$model
)]
=
$model
;
foreach
(
$model
->
listenEvents
()
as
$listened
){
$this
->
_domainEventManager
->
add
EventListener
(
$listened
,
$model
);
$this
->
_domainEventManager
->
add
DomainEventListener
(
$listened
,
$model
);
}
}
}
...
...
engine/config/lang/en.lang.json
View file @
04281b5a
...
...
@@ -3,10 +3,13 @@
"engine"
:
{
"core"
:
{
"app"
:
{
"ACTION_HANDLER_NOT_FOUND"
:
"ActionHandler [[$]] doesn't exists
!
"
,
"ACTION_HANDLER_NOT_FOUND"
:
"ActionHandler [[$]] doesn't exists"
,
"INTERNAL_ERROR"
:
"Internal error : [$]"
,
"MUST_BE_LOGGED"
:
"Access denied : you must be connected !"
,
"404_NOT_FOUND"
:
"Page '[$]' not found !"
"MUST_BE_LOGGED"
:
"You must be connected."
,
"ACCESS_DENIED"
:
"Access denied"
,
"INSUFFICIENT_PRIVILEGIES"
:
"Insufficient user privileges."
,
"BAD_CSRF_TOKEN"
:
"Invalid CSRF token."
,
"404_NOT_FOUND"
:
"Page '[$]' not found"
}
},
"package"
:
{
...
...
engine/config/lang/fr.lang.json
View file @
04281b5a
...
...
@@ -5,7 +5,10 @@
"app"
:
{
"ACTION_HANDLER_NOT_FOUND"
:
"L'ActionHandler [[$]] n'existe pas !"
,
"INTERNAL_ERROR"
:
"Erreur interne : [$]"
,
"MUST_BE_LOGGED"
:
"Accès refusé : vous devez être connecté pour effectuer cette action !"
,
"MUST_BE_LOGGED"
:
"Vous devez être connecté pour effectuer cette action !"
,
"ACCESS_DENIED"
:
"Accès refusé"
,
"INSUFFICIENT_PRIVILEGIES"
:
"Privilèges utilisateur insuffisants."
,
"BAD_CSRF_TOKEN"
:
"Token CSRF invalide."
,
"404_NOT_FOUND"
:
"La page '[$]' n'existe pas !"
}
},
...
...
engine/core/app/WebApp.php
View file @
04281b5a
...
...
@@ -42,7 +42,7 @@ final class WebApp {
)
$layout
=
$cache
->
get
(
$cacheKey
);
else
{
$translator
=
$this
->
_context
->
getTranslator
();
$permission
=
$this
->
_context
->
getAccessControlCenter
()
->
check
Permissions
(
$action
);
$permission
=
$this
->
_context
->
getAccessControlCenter
()
->
check
AccessPermission
(
$action
);
$response
=
$this
->
_context
->
getActionHook
()
->
hook
(
$action
,
$permission
);
if
(
is_null
(
$response
)){
if
(
$permission
->
isGranted
()){
...
...
engine/core/app/context/DefaultContext.php
View file @
04281b5a
...
...
@@ -20,6 +20,10 @@ use wfw\engine\core\command\ICommandBus;
use
wfw\engine\core\command\ICommandHandlerFactory
;
use
wfw\engine\core\command\ICommandInflector
;
use
wfw\engine\core\command\inflectors\NamespaceBasedInflector
;
use
wfw\engine\core\command\security\CommandAccessRuleFactory
;
use
wfw\engine\core\command\security\CommandSecurityCenter
;
use
wfw\engine\core\command\security\ICommandSecurityCenter
;
use
wfw\engine\core\command\security\rules\CommandAccessAccessRulesCollector
;
use
wfw\engine\core\command\SynchroneCommandBus
;
use
wfw\engine\core\data\DBAccess\NOSQLDB\msServer\IMSServerAccess
;
use
wfw\engine\core\data\DBAccess\NOSQLDB\msServer\MSServerWriterAccess
;
...
...
@@ -150,7 +154,7 @@ class DefaultContext implements IWebAppContext {
* @param null|String $ajaxViewPath Chemin d'accés à la vue ajax par défaut
* @param array $connections Connexions d'urls
* @param array $langs Langues disponibles
* @param array $
accessRules Liste des régles d'accés
* @param array $
securityRules 3 indxes : access, command, query
* @param array $hooks Liste des hooks
* @param array $diceRules Regles à ajouter à Dice
* @param array $globals Contient la variables globales de php aux index _GET,_POST,_FILES,_SERVER
...
...
@@ -164,7 +168,7 @@ class DefaultContext implements IWebAppContext {
?string
$ajaxViewPath
=
null
,
array
$connections
=
[],
array
$langs
=
[],
array
$
access
Rules
=
[],
array
$
security
Rules
=
[],
array
$hooks
=
[],
array
$diceRules
=
[],
array
$globals
=
[],
...
...
@@ -176,6 +180,10 @@ class DefaultContext implements IWebAppContext {
$genericFactory
=
new
DiceBasedFactory
(
$this
->
_dice
=
$dice
=
new
Dice
());
$this
->
getErrorHandler
()
->
handle
();
//TODO : init if not set for commands and queries
$commandRules
=
$securityRules
[
"command"
]
??
[];
$accessRules
=
$securityRules
[
"access"
]
??
[];
$queryRules
=
$securityRules
[
"query"
]
??
[];
if
(
count
(
$accessRules
)
===
0
)
$accessRules
=
[
RequireAuthentification
::
class
=>
[
array_merge
(
...
...
@@ -250,12 +258,14 @@ class DefaultContext implements IWebAppContext {
$this
->
_translator
=
$translator
=
$this
->
initTranslator
(
$langs
,
null
);
$instance
=
$this
;
$commandRulesCollector
=
new
CommandAccessAccessRulesCollector
(
new
CommandAccessRuleFactory
(
$genericFactory
),
$commandRules
);
$this
->
_dice
->
addRules
([
'*'
=>
[
'substitutions'
=>
[
IConf
::
class
=>
[
Dice
::
INSTANCE
=>
function
()
use
(
$conf
){
return
$conf
;
}
],
/*IRouter::class => [ Dice::INSTANCE => function() use($router){return $router;}],*/
IMailProvider
::
class
=>
[
Dice
::
INSTANCE
=>
function
()
use
(
$instance
,
$conf
){
return
$this
->
initMailProvider
(
$conf
);
...
...
@@ -308,8 +318,12 @@ class DefaultContext implements IWebAppContext {
ICommandInflector
::
class
=>
[
'instanceOf'
=>
NamespaceBasedInflector
::
class
,
'shared'
=>
true
],
ICommandSecurityCenter
::
class
=>
[
'instanceOf'
=>
CommandSecurityCenter
::
class
,
'shared'
=>
true
,
'constructParams'
=>
[
$commandRulesCollector
->
collect
()
]
],
ICommandHandlerFactory
::
class
=>
[
'instanceOf'
=>
CommandHandlerFactory
::
class
,
'shared'
=>
true
'instanceOf'
=>
CommandHandlerFactory
::
class
,
'shared'
=>
true
],
IEventStore
::
class
=>
[
'instanceOf'
=>
DBBasedEventStore
::
class
],
IDBAccess
::
class
=>
[
...
...
engine/core/cache/ICacheSystem.php
View file @
04281b5a
...
...
@@ -13,10 +13,10 @@ interface ICacheSystem {
public
function
get
(
string
$key
);
/**
* @param string[] $keys Clé des valeurs à chercher
* @return
\Travers
able
* @param string[] $keys Clé
s
des valeurs à chercher
* @return
iter
able
*/
public
function
getAll
(
array
$keys
):
\
Travers
able
;
public
function
getAll
(
array
$keys
):
iter
able
;
/**
* @param string[] $keys Clés des valeurs à supprimer du cache
...
...
engine/core/cache/systems/APCUBasedCache.php
View file @
04281b5a
...
...
@@ -93,9 +93,9 @@ final class APCUBasedCache implements ICacheSystem{
* to APCUIterator::__construct()
* @see https://bugs.php.net/bug.php?id=78002
* @param string[] $keys Clé des valeurs à chercher
* @return
\Travers
able
* @return
iter
able
*/
public
function
getAll
(
array
$keys
):
\
Travers
able
{
public
function
getAll
(
array
$keys
):
iter
able
{
foreach
(
$keys
as
$k
=>
$key
){
$keys
[
$k
]
=
"/"
.
str_replace
(
"/"
,
'\/'
,
"^
$this->_namespace
::
$key
"
)
.
"/"
;
}
...
...
engine/core/cache/systems/MemoryCache.php
0 → 100644
View file @
04281b5a
<?php
namespace
wfw\engine\core\cache\systems
;
use
wfw\engine\core\cache\ICacheSystem
;
/**
* Class MemoryCache
*
* @package wfw\engine\core\cache\systems
*/
final
class
MemoryCache
implements
ICacheSystem
{
/** @var array $_data */
private
$_data
;
/** @var null|string $_namespace */
private
$_namespace
;
/**
* MemoryCache constructor.
*
* @param null|string $namespace
*/
public
function
__construct
(
?string
$namespace
=
null
)
{
$this
->
_data
=
[];
$this
->
_namespace
=
$namespace
;
}
/**
* Obtient la valeur d'une clé en cache
*
* @param string $key Clé de la valeur à rechercher
* @return mixed Valeur attribuée à la clé
*/
public
function
get
(
string
$key
)
{
return
$this
->
_data
[
"
$this->_namespace
::
$key
"
][
"data"
]
??
null
;
}
/**
* @param string[] $keys Clé des valeurs à chercher
* @return iterable
*/
public
function
getAll
(
array
$keys
):
iterable
{
return
array_intersect_key
(
$this
->
_data
,
array_flip
(
array_map
(
function
(
$key
){
return
"
$this->_namespace
::
$key
"
;
},
$keys
)));
}
/**
* @param string[] $keys Clés des valeurs à supprimer du cache
*/
public
function
deleteAll
(
array
$keys
)
{
foreach
(
$keys
as
$key
)
if
(
$this
->
contains
(
$key
))
unset
(
$this
->
_data
[
"
$this->_namespace
::
$key
"
]);
}
/**
* Cache une variable
*
* @param string $key Clé de stockage
* @param mixed $data Donnée à stocker
* @param float $timeout Temps de stockage en secondes (0 : pas de temps de vie, existe jusqu'à la suppression manuelle)
* @return bool True si l'opération a réussi, false sinon
*/
public
function
set
(
string
$key
,
$data
,
float
$timeout
=
0
):
bool
{
$this
->
_data
[
"
$this->_namespace
::
$key
"
]
=
[
"data"
=>
$data
,
"timeout"
=>
microtime
(
true
)
+
$timeout
];
return
true
;
}
/**
* Mets à jour une donnée en cache
*
* @param string $key Clé de la donnée à changer
* @param mixed $data Nouvelle données
* @param float $timeout Temps de stockage en secondes (0 : pas de temps de vie, existe jusqu'à la suppression manuelle)
* @return bool True si l'opération a réussi, false sinon
*/
public
function
update
(
string
$key
,
$data
,
float
$timeout
=
0
):
bool
{
if
(
$this
->
contains
(
$key
))
return
$this
->
set
(
$key
,
$data
,
$timeout
);
else
return
false
;
}
/**
* Supprime une donnée en cache
*
* @param string $key Clé de la donnée à supprimer du cache
* @return bool True si l'opération a réussi, false sinon
*/
public
function
delete
(
string
$key
):
bool
{
if
(
$this
->
contains
(
$key
)){
unset
(
$this
->
_data
[
"
$this->_namespace
::
$key
"
]);
return
true
;
}
else
return
false
;
}
/**
* Vide le cache
*
* @return bool True si l'opération a réussi, false sinon
*/
public
function
clear
():
bool
{
$this
->
_data
=
[];
return
true
;
}
/**
* Teste l'existence d'une clé de donnée en cache
*
* @param string $key Clé à tester
* @return bool True si la clé existe, false sinon
*/
public
function
contains
(
string
$key
):
bool
{
if
(
isset
(
$this
->
_data
[
"
$this->_namespace
::
$key
"
])){
if
(
microtime
(
true
)
<=
$this
->
_data
[
"
$this->_namespace
::
$key
"
][
"timeout"
])
return
true
;
else
unset
(
$this
->
_data
[
"
$this->_namespace
::
$key
"
]);
}
return
false
;
}
}
\ No newline at end of file
engine/core/cache/systems/NoCache.php
View file @
04281b5a
...
...
@@ -62,9 +62,9 @@ class NoCache implements ICacheSystem{
/**
* @param string[] $keys Clé des valeurs à chercher
* @return
\Travers
able
* @return
iter
able
*/
public
function
getAll
(
array
$keys
):
\
Traversable
{
}
public
function
getAll
(
array
$keys
):
iterable
{
return
[];
}
/**
* @param string[] $keys Clés des valeurs à supprimer du cache
...
...
engine/core/command/Command.php
View file @
04281b5a
...
...
@@ -9,28 +9,38 @@ use wfw\engine\lib\PHP\types\UUID;
abstract
class
Command
implements
ICommand
{
/** @var UUID */
private
$_uuid
;
/** @var null|string $_userId */
private
$_userId
;
/** @var float */
private
$_generationDate
;
/**
* Command constructor.
*
* @param null|string $userId
*/
public
function
__construct
(){
public
function
__construct
(
?string
$userId
=
null
){
$this
->
_userId
=
$userId
;
$this
->
_uuid
=
new
UUID
();
$this
->
_generationDate
=
microtime
(
true
);
}
/**
* Retourne l'UUID de la commande
* @return UUID
* @return UUID Command ID
*/
public
function
getId
():
UUID
{
return
$this
->
_uuid
;
}
/**
* Retourne la date de création de la commande
* @return float
* @return null|string User ID that try to execute the command
*/
public
function
getUserId
():
?string
{
return
$this
->
_userId
;
}
/**
* @return float Creation date
*/
public
function
getGenerationDate
():
float
{
return
$this
->
_generationDate
;
...
...
engine/core/command/CommandDispatcher.php
View file @
04281b5a
...
...
@@ -25,11 +25,11 @@ final class CommandDispatcher implements ICommandDispatcher {
* @param ICommand $command Commande à dispatcher
* @throws NoCommandHandlerFound
*/
public
function
dispatch
(
ICommand
$command
):
void
{
public
function
dispatch
Command
(
ICommand
$command
):
void
{
$success
=
false
;
foreach
(
$this
->
_dispatchers
as
$dispatcher
){
try
{
$dispatcher
->
dispatch
(
$command
);
$dispatcher
->
dispatch
Command
(
$command
);
$success
=
true
;
break
;
}
catch
(
NoCommandHandlerFound
$e
){}
...
...
engine/core/command/CommandHandlerFactory.php
View file @
04281b5a
...
...
@@ -26,7 +26,7 @@ final class CommandHandlerFactory implements ICommandHandlerFactory {
* @param array $params Paramètres de création
* @return ICommandHandler
*/
public
function
build
(
string
$handlerClass
,
array
$params
=
[]):
ICommandHandler
{
public
function
build
CommandHandler
(
string
$handlerClass
,
array
$params
=
[]):
ICommandHandler
{
return
$this
->
_factory
->
create
(
$handlerClass
,
$params
,[
ICommandHandler
::
class
]);
}
}
\ No newline at end of file
engine/core/command/ICommand.php
View file @
04281b5a
...
...
@@ -4,7 +4,7 @@ namespace wfw\engine\core\command;
use
wfw\engine\lib\PHP\types\UUID
;
/**
*
Représente une commande pour un CommandHandler
*
Command
*/
interface
ICommand
{
/**
...
...
@@ -12,6 +12,11 @@ interface ICommand {
*/
public
function
getId
():
UUID
;
/**
* @return null|string Uner that initates the command (if available)
*/
public
function
getUserId
():
?string
;
/**
* @return float
*/
...
...
engine/core/command/ICommandBus.php
View file @
04281b5a
...
...
@@ -12,5 +12,5 @@ interface ICommandBus {
*
* @return mixed
*/
public
function
execute
(
ICommand
$command
):
void
;
public
function
execute
Command
(
ICommand
$command
):
void
;
}
\ No newline at end of file
engine/core/command/ICommandDispatcher.php
View file @
04281b5a
...
...
@@ -11,5 +11,5 @@ interface ICommandDispatcher {
* @param ICommand $command Commande à dispatcher
* @throws NoCommandHandlerFound
*/
public
function
dispatch
(
ICommand
$command
):
void
;
public
function
dispatch
Command
(
ICommand
$command
):
void
;
}
\ No newline at end of file
engine/core/command/ICommandHandler.php
View file @
04281b5a
...
...
@@ -9,5 +9,5 @@ interface ICommandHandler {
* Traite la commande
* @param ICommand $command Commande à traiter
*/
public
function
handle
(
ICommand
$command
);
public
function
handle
Command
(
ICommand
$command
);
}
\ No newline at end of file
engine/core/command/ICommandHandlerFactory.php
View file @
04281b5a
...
...
@@ -12,5 +12,5 @@ interface ICommandHandlerFactory {
* @param array $params Paramètres de création
* @return ICommandHandler
*/
public
function
build
(
string
$handlerClass
,
array
$params
=
[]):
ICommandHandler
;
public
function
build
CommandHandler
(
string
$handlerClass
,
array
$params
=
[]):
ICommandHandler
;
}
\ No newline at end of file
engine/core/command/ICommandInflector.php
View file @
04281b5a
...
...
@@ -14,5 +14,5 @@ interface ICommandInflector {
* @return ICommandHandler[]
* @throws NoCommandHandlerFound
*/
public
function
resolveHandlers
(
ICommand
$command
):
array
;
public
function
resolve
Command
Handlers
(
ICommand
$command
):
array
;
}
\ No newline at end of file
engine/core/command/InflectorBasedCommandDispatcher.php
View file @
04281b5a
...
...
@@ -22,10 +22,10 @@ final class InflectorBasedCommandDispatcher implements ICommandDispatcher {
* @param ICommand $command Commande à dispatcher
* @throws NoHandlerFound
*/
public
function
dispatch
(
ICommand
$command
):
void
{
$handlers
=
$this
->
_inflector
->
resolveHandlers
(
$command
);
public
function
dispatch
Command
(
ICommand
$command
):
void
{
$handlers
=
$this
->
_inflector
->
resolve
Command
Handlers
(
$command
);
foreach
(
$handlers
as
$handler
){
$handler
->
handle
(
$command
);
$handler
->
handle
Command
(
$command
);
}
}
}
\ No newline at end of file
engine/core/command/SynchroneCommandBus.php
View file @
04281b5a
<?php
namespace
wfw\engine\core\command
;
use
wfw\engine\core\command\security\errors\RejectedCommand
;
use
wfw\engine\core\command\security\ICommandSecurityCenter
;
/**
* Traite les commandes de manières synchrone
*/
final
class
SynchroneCommandBus
implements
ICommandBus
{
/**
* Inflecteur de commande (permet de savoir quel handler correspond à quelle commande)
* @var ICommandInflector $_inflector
*/
/** @var ICommandInflector $_inflector */
private
$_inflector
;
/** @var ICommandSecurityCenter $_security */
private
$_security
;
/**
* SynchroneCommandBus constructor.
*
* @param ICommandInflector $inflector Trouve le handler d'une commande
* @param ICommandInflector $inflector Trouve le handler d'une commande
* @param ICommandSecurityCenter $security
*/
public
function
__construct
(
ICommandInflector
$inflector
)
{
public
function
__construct
(
ICommandInflector
$inflector
,
ICommandSecurityCenter
$security
)
{
$this
->
_inflector
=
$inflector
;
$this
->
_security
=
$security
;
}
/**
* Redirige la commande vers son handler et retourne le résultat du handler
* @param ICommand $command Commande à rediriger
*/
public
function
execute
(
ICommand
$command
):
void
{
$handlers
=
$this
->
_inflector
->
resolveHandlers
(
$command
);
public
function
executeCommand
(
ICommand
$command
):
void
{
if
(
!
$this
->
_security
->
allowCommand
(
$command
))
throw
new
RejectedCommand
(
"Access denied : "
.
get_class
(
$command
)
.
" rejected by the security center."
);
$handlers
=
$this
->
_inflector
->
resolveCommandHandlers
(
$command
);
foreach
(
$handlers
as
$handler
){
$handler
->
handle
(
$command
);
$handler
->
handle
Command
(
$command
);
}
}
}
\ No newline at end of file
engine/core/command/inflectors/NamespaceBasedInflector.php
View file @
04281b5a
...
...
@@ -35,7 +35,7 @@ final class NamespaceBasedInflector implements ICommandInflector {
* @return ICommandHandler[]
* @throws NoCommandHandlerFound
*/
public
function
resolveHandlers
(
ICommand
$command
):
array
{
public
function
resolve
Command
Handlers
(
ICommand
$command
):
array
{
$handlers
=
$this
->
resolveHandlersFromCommandClass
(
get_class
(
$command
));
if
(
count
(
$handlers
)
>
0
){
return
$handlers
;
...
...
@@ -59,7 +59,7 @@ final class NamespaceBasedInflector implements ICommandInflector {
$className
=
array_pop
(
$tmp
);
try
{
$res
[]
=
$this
->
_factory
->
build
(
$res
[]
=
$this
->
_factory
->
build
CommandHandler
(
implode
(
'\\'
,
$tmp
)
.
'\\handlers\\'
.
$className
.
'Handler'
);
}
catch
(
\
Exception
$e
){}
...
...
engine/core/command/security/CommandAccessRuleFactory.php
0 → 100644
View file @
04281b5a
<?php
namespace
wfw\engine\core\command\security
;
use
wfw\engine\core\app\factory\IGenericAppFactory
;
use
wfw\engine\core\command\security\rules\ICommandAccessRule
;
/**
* Create access rules from a class and params with the app DIC.
*/
final
class
CommandAccessRuleFactory
implements
ICommandAccessRuleFactory
{
/** @var IGenericAppFactory $_factory */
private
$_factory
;
/**
* CommandAccessRuleFactory constructor.
*
* @param IGenericAppFactory $factory
*/
public
function
__construct
(
IGenericAppFactory
$factory
)
{
$this
->
_factory
=
$factory
;
}
/**
* @param string $ruleClass
* @param array $params
* @return ICommandAccessRule
*/
public
function
create
(
string
$ruleClass
,
array
$params
=
[]):
ICommandAccessRule
{
return
$this
->
_factory
->
create
(
$ruleClass
,
$params
,[
ICommandAccessRule
::
class
]);
}
}
\ No newline at end of file
engine/core/command/security/CommandSecurityCenter.php
0 → 100644
View file @
04281b5a
<?php
namespace
wfw\engine\core\command\security
;
use
wfw\engine\core\command\ICommand
;
use
wfw\engine\core\command\security\rules\ICommandAccessRule
;
/**
* Default security center. Will check if a command is allowed checking a CommandAccessRule.
*/
final
class
CommandSecurityCenter
implements
ICommandSecurityCenter
{
/** @var ICommandAccessRule $_rule */
private
$_rule
;
/** @var bool $_ignoredAsTrue */
private
$_ignoredAsTrue
;
/**
* CommandSecurityCenter constructor.
*
* @param ICommandAccessRule $rule
* @param bool $ignoredAsTrue
*/
public
function
__construct
(
ICommandAccessRule
$rule
,
bool
$ignoredAsTrue
=
false
)
{
$this
->
_rule
=
$rule
;
$this
->
_ignoredAsTrue
=
$ignoredAsTrue
;
}
/**
* @param ICommand $cmd Command to run.
* @return bool True, the command is allowed for that user. False otherwise.
*/
public
function
allowCommand
(
ICommand
$cmd
):
bool
{
return
$this
->
_rule
->
checkCommand
(
$cmd
)
??
$this
->
_ignoredAsTrue
;
}
}
\ No newline at end of file
engine/core/command/security/ICommandAccessRuleFactory.php
0 → 100644
View file @
04281b5a