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
6e6026d5
Commit
6e6026d5
authored
Aug 12, 2019
by
Jordan Breton
✏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added queries base
parent
e976758f
Changes
54
Hide whitespace changes
Inline
Side-by-side
Showing
54 changed files
with
1012 additions
and
92 deletions
+1012
-92
engine/core/app/context/BaseAppContext.php
engine/core/app/context/BaseAppContext.php
+2
-2
engine/core/command/SynchroneCommandBus.php
engine/core/command/SynchroneCommandBus.php
+1
-1
engine/core/command/inflectors/NamespaceBasedInflector.php
engine/core/command/inflectors/NamespaceBasedInflector.php
+9
-4
engine/core/query/IQuery.php
engine/core/query/IQuery.php
+24
-0
engine/core/query/IQueryDispatcher.php
engine/core/query/IQueryDispatcher.php
+15
-0
engine/core/query/IQueryHandler.php
engine/core/query/IQueryHandler.php
+13
-0
engine/core/query/IQueryHandlerFactory.php
engine/core/query/IQueryHandlerFactory.php
+16
-0
engine/core/query/IQueryInflector.php
engine/core/query/IQueryInflector.php
+18
-0
engine/core/query/IQueryProcessor.php
engine/core/query/IQueryProcessor.php
+16
-0
engine/core/query/InflectorBasedQueryDispatcher.php
engine/core/query/InflectorBasedQueryDispatcher.php
+31
-0
engine/core/query/Query.php
engine/core/query/Query.php
+48
-0
engine/core/query/QueryDispatcher.php
engine/core/query/QueryDispatcher.php
+41
-0
engine/core/query/QueryHandlerFactory.php
engine/core/query/QueryHandlerFactory.php
+32
-0
engine/core/query/QueryProcessor.php
engine/core/query/QueryProcessor.php
+40
-0
engine/core/query/errors/NoQueryHandlerFound.php
engine/core/query/errors/NoQueryHandlerFound.php
+7
-0
engine/core/query/errors/QueryFailure.php
engine/core/query/errors/QueryFailure.php
+7
-0
engine/core/query/inflectors/NamespaceBasedInflector.php
engine/core/query/inflectors/NamespaceBasedInflector.php
+104
-0
engine/core/query/security/IQueryAccessRuleFactory.php
engine/core/query/security/IQueryAccessRuleFactory.php
+17
-0
engine/core/query/security/IQuerySecurityCenter.php
engine/core/query/security/IQuerySecurityCenter.php
+16
-0
engine/core/query/security/QueryAccessRuleFactory.php
engine/core/query/security/QueryAccessRuleFactory.php
+32
-0
engine/core/query/security/QuerySecurityCenter.php
engine/core/query/security/QuerySecurityCenter.php
+35
-0
engine/core/query/security/errors/RejectedQuery.php
engine/core/query/security/errors/RejectedQuery.php
+10
-0
engine/core/query/security/rules/AllQueriesAllowed.php
engine/core/query/security/rules/AllQueriesAllowed.php
+18
-0
engine/core/query/security/rules/AllQueriesDenied.php
engine/core/query/security/rules/AllQueriesDenied.php
+18
-0
engine/core/query/security/rules/AndQueryAccessRule.php
engine/core/query/security/rules/AndQueryAccessRule.php
+41
-0
engine/core/query/security/rules/IQueryAccessRule.php
engine/core/query/security/rules/IQueryAccessRule.php
+16
-0
engine/core/query/security/rules/IQueryAccessRulesCollector.php
.../core/query/security/rules/IQueryAccessRulesCollector.php
+13
-0
engine/core/query/security/rules/NotQueryAccessRule.php
engine/core/query/security/rules/NotQueryAccessRule.php
+32
-0
engine/core/query/security/rules/OrQueryAccessRule.php
engine/core/query/security/rules/OrQueryAccessRule.php
+37
-0
engine/core/query/security/rules/QueryAccessRulesCollector.php
...e/core/query/security/rules/QueryAccessRulesCollector.php
+34
-0
engine/core/query/security/rules/UserTypeBasedQueryAccessRule.php
...ore/query/security/rules/UserTypeBasedQueryAccessRule.php
+184
-0
engine/package/general/handlers/action/PostDataDefaultActionHandler.php
.../general/handlers/action/PostDataDefaultActionHandler.php
+9
-9
engine/package/users/handlers/action/CancelChangeMailHandler.php
...package/users/handlers/action/CancelChangeMailHandler.php
+4
-4
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
+3
-3
engine/package/users/handlers/action/ChangePasswordHandler.php
...e/package/users/handlers/action/ChangePasswordHandler.php
+3
-3
engine/package/users/handlers/action/ConfirmUserRegistrationHandler.php
.../users/handlers/action/ConfirmUserRegistrationHandler.php
+4
-4
engine/package/users/handlers/action/DefaultUserActionHandler.php
...ackage/users/handlers/action/DefaultUserActionHandler.php
+7
-7
engine/package/users/handlers/action/ForgottenPasswordHandler.php
...ackage/users/handlers/action/ForgottenPasswordHandler.php
+3
-3
engine/package/users/handlers/action/LoginHandler.php
engine/package/users/handlers/action/LoginHandler.php
+4
-4
engine/package/users/handlers/action/RegisterHandler.php
engine/package/users/handlers/action/RegisterHandler.php
+4
-4
engine/package/users/handlers/action/ResendChangeMailHandler.php
...package/users/handlers/action/ResendChangeMailHandler.php
+3
-3
engine/package/users/handlers/action/ResendForgottenPasswordMailHandler.php
...rs/handlers/action/ResendForgottenPasswordMailHandler.php
+3
-3
engine/package/users/handlers/action/ResetPasswordHandler.php
...ne/package/users/handlers/action/ResetPasswordHandler.php
+4
-4
engine/package/users/handlers/action/admin/CancelChangeMailHandler.php
...e/users/handlers/action/admin/CancelChangeMailHandler.php
+3
-3
engine/package/users/handlers/action/admin/CancelResetPasswordHandler.php
...sers/handlers/action/admin/CancelResetPasswordHandler.php
+3
-3
engine/package/users/handlers/action/admin/CancelUserRegistrationHandler.php
...s/handlers/action/admin/CancelUserRegistrationHandler.php
+3
-3
engine/package/users/handlers/action/admin/ChangeMailHandler.php
...package/users/handlers/action/admin/ChangeMailHandler.php
+3
-3
engine/package/users/handlers/action/admin/ChangeTypeHandler.php
...package/users/handlers/action/admin/ChangeTypeHandler.php
+3
-3
engine/package/users/handlers/action/admin/DisableHandler.php
...ne/package/users/handlers/action/admin/DisableHandler.php
+3
-3
engine/package/users/handlers/action/admin/EnableHandler.php
engine/package/users/handlers/action/admin/EnableHandler.php
+3
-3
engine/package/users/handlers/action/admin/RegisterHandler.php
...e/package/users/handlers/action/admin/RegisterHandler.php
+3
-3
engine/package/users/handlers/action/admin/RemoveHandler.php
engine/package/users/handlers/action/admin/RemoveHandler.php
+3
-3
engine/package/users/handlers/action/admin/ResetPasswordHandler.php
...kage/users/handlers/action/admin/ResetPasswordHandler.php
+3
-3
No files found.
engine/core/app/context/BaseAppContext.php
View file @
6e6026d5
...
...
@@ -12,7 +12,7 @@ use wfw\engine\core\app\factory\IGenericAppFactory;
use
wfw\engine\core\cache\ICacheSystem
;
use
wfw\engine\core\cache\systems\APCUBasedCache
;
use
wfw\engine\core\command\CommandHandlerFactory
;
use
wfw\engine\core\command\I
CommandBus
;
use
wfw\engine\core\command\I
QueryProcessor
;
use
wfw\engine\core\command\ICommandHandlerFactory
;
use
wfw\engine\core\command\ICommandInflector
;
use
wfw\engine\core\command\inflectors\NamespaceBasedInflector
;
...
...
@@ -173,7 +173,7 @@ class BaseAppContext implements IAppContext {
'instanceOf'
=>
MailFactory
::
class
,
'shared'
=>
true
],
I
CommandBus
::
class
=>
[
'instanceOf'
=>
SynchroneCommandBus
::
class
,
'shared'
=>
true
],
I
QueryProcessor
::
class
=>
[
'instanceOf'
=>
SynchroneCommandBus
::
class
,
'shared'
=>
true
],
ICommandInflector
::
class
=>
[
'instanceOf'
=>
NamespaceBasedInflector
::
class
,
'shared'
=>
true
,
'constructParams'
=>
[
$this
->
getCommandHandlers
()
]
...
...
engine/core/command/SynchroneCommandBus.php
View file @
6e6026d5
...
...
@@ -7,7 +7,7 @@ use wfw\engine\core\command\security\ICommandSecurityCenter;
/**
* Traite les commandes de manières synchrone
*/
final
class
SynchroneCommandBus
implements
I
CommandBus
{
final
class
SynchroneCommandBus
implements
I
QueryProcessor
{
/** @var ICommandInflector $_inflector */
private
$_inflector
;
/** @var ICommandSecurityCenter $_security */
...
...
engine/core/command/inflectors/NamespaceBasedInflector.php
View file @
6e6026d5
...
...
@@ -76,12 +76,17 @@ final class NamespaceBasedInflector implements ICommandInflector {
$res
[]
=
$this
->
_handlers
[
$command
];
}
else
{
$r
=
[];
$tmp
=
explode
(
"
\\
"
,
$command
);
$className
=
array_pop
(
$tmp
);
if
(
$pos
=
strrpos
(
$command
,
$search
=
"
\\
commands
\\
"
)
!==
false
)
{
$handlerClass
=
substr_replace
(
$command
,
"
\\
commands
\\
handlers
\\
"
,
$pos
,
strlen
(
$search
)
);
}
try
{
$r
[]
=
$this
->
_factory
->
buildCommandHandler
(
implode
(
'\\'
,
$tmp
)
.
'\\handlers\\'
.
$className
.
'Handler'
(
$handlerClass
??
$command
)
.
"Handler"
);
}
catch
(
\
Exception
$e
){}
...
...
engine/core/query/IQuery.php
0 → 100755
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query
;
use
wfw\engine\lib\PHP\types\UUID
;
/**
* Command
*/
interface
IQuery
{
/**
* @return UUID
*/
public
function
getId
():
UUID
;
/**
* @return null|string Uner that initates the query (if available)
*/
public
function
getInitiatorId
():
?string
;
/**
* @return float
*/
public
function
getGenerationDate
():
float
;
}
\ No newline at end of file
engine/core/query/IQueryDispatcher.php
0 → 100755
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query
;
use
wfw\engine\core\query\errors\NoQueryHandlerFound
;
/**
* Dispatcher de commandes
*/
interface
IQueryDispatcher
{
/**
* @param IQuery $command Commande à dispatcher
* @throws NoQueryHandlerFound
*/
public
function
dispatchCommand
(
IQuery
$command
):
void
;
}
\ No newline at end of file
engine/core/query/IQueryHandler.php
0 → 100755
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query
;
/**
* Permet de traiter une commande
*/
interface
IQueryHandler
{
/**
* Traite la commande
* @param IQuery $command Commande à traiter
*/
public
function
handleCommand
(
IQuery
$command
);
}
\ No newline at end of file
engine/core/query/IQueryHandlerFactory.php
0 → 100755
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query
;
/**
* Factory de IQueryHandler
*/
interface
IQueryHandlerFactory
{
/**
* Constuit un IQueryHandler à partir du nom de la classe d'un QueryHandler
*
* @param string $handlerClass Classe du handler à construire
* @param array $params Paramètres de création
* @return IQueryHandler
*/
public
function
buildQueryHandler
(
string
$handlerClass
,
array
$params
=
[]):
IQueryHandler
;
}
\ No newline at end of file
engine/core/query/IQueryInflector.php
0 → 100755
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query
;
use
wfw\engine\core\query\errors\NoQueryHandlerFound
;
/**
* Permet de trouver un handler pour une commande
*/
interface
IQueryInflector
{
/**
* Trouve un handler pour une commande
*
* @param IQuery $query Query dont on cherche le handler
* @return IQueryHandler[]
* @throws NoQueryHandlerFound
*/
public
function
resolveQueryHandlers
(
IQuery
$query
):
array
;
}
\ No newline at end of file
engine/core/query/IQueryProcessor.php
0 → 100755
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query
;
/**
* Reçois les commandes et les redirige vers leur handler
*/
interface
IQueryProcessor
{
/**
* Redirige la commande vers son handler
*
* @param ICommand $command Commande à rediriger
*
* @return mixed
*/
public
function
executeCommand
(
ICommand
$command
):
void
;
}
\ No newline at end of file
engine/core/query/InflectorBasedQueryDispatcher.php
0 → 100755
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query
;
/**
* Utilise un inflecteur pour déterminer le command handler à charger, évite les configurations
* manuelles.
*/
final
class
InflectorBasedQueryDispatcher
implements
IQueryDispatcher
{
/** @var ICommandInflector $_inflector */
private
$_inflector
;
/**
* InflectorBasedCommandObserver constructor.
*
* @param ICommandInflector $inflector Inflecteur
*/
public
function
__construct
(
ICommandInflector
$inflector
)
{
$this
->
_inflector
=
$inflector
;
}
/**
* @param ICommand $command Commande à dispatcher
* @throws NoHandlerFound
*/
public
function
dispatchCommand
(
ICommand
$command
):
void
{
$handlers
=
$this
->
_inflector
->
resolveCommandHandlers
(
$command
);
foreach
(
$handlers
as
$handler
){
$handler
->
handleCommand
(
$command
);
}
}
}
\ No newline at end of file
engine/core/query/Query.php
0 → 100755
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query
;
use
wfw\engine\lib\PHP\types\UUID
;
/**
* Commande de base
*/
abstract
class
Query
implements
IQuery
{
/** @var UUID */
private
$_uuid
;
/** @var null|string $_userId */
private
$_initiatorId
;
/** @var float */
private
$_generationDate
;
/**
* Command constructor.
*
* @param null|string $initiatorId
*/
public
function
__construct
(
?string
$initiatorId
=
null
){
$this
->
_initiatorId
=
$initiatorId
;
$this
->
_uuid
=
new
UUID
();
$this
->
_generationDate
=
microtime
(
true
);
}
/**
* @return UUID Command ID
*/
public
function
getId
():
UUID
{
return
$this
->
_uuid
;
}
/**
* @return null|string User ID that try to execute the command
*/
public
function
getInitiatorId
():
?string
{
return
$this
->
_initiatorId
;
}
/**
* @return float Creation date
*/
public
function
getGenerationDate
():
float
{
return
$this
->
_generationDate
;
}
}
\ No newline at end of file
engine/core/query/QueryDispatcher.php
0 → 100755
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query
;
use
wfw\engine\core\query\errors\NoQueryHandlerFound
;
/**
* Dispatcher de query base. Peut-être construit avec une liste de dispatchers de queries.
* L'instance courante tentera un à un chaque dispatcher dans l'ordre à chaque echec, et s'arrêtera
* dés lors qu'un dispatch() aura réussi.
*/
final
class
QueryDispatcher
implements
IQueryDispatcher
{
/** @var IQueryDispatcher[] $_dispatchers */
private
$_dispatchers
;
/**
* QueryDispatcher constructor.
*
* @param IQueryDispatcher ...$dispatchers
*/
public
function
__construct
(
IQueryDispatcher
...
$dispatchers
)
{
$this
->
_dispatchers
=
$dispatchers
;
}
/**
* @param IQuery $command Commande à dispatcher
* @throws NoQueryHandlerFound
*/
public
function
dispatchCommand
(
IQuery
$command
):
void
{
$success
=
false
;
foreach
(
$this
->
_dispatchers
as
$dispatcher
){
try
{
$dispatcher
->
dispatchCommand
(
$command
);
$success
=
true
;
break
;
}
catch
(
NoQueryHandlerFound
$e
){}
}
if
(
!
$success
){
throw
new
NoQueryHandlerFound
(
"No handler found for command "
.
get_class
(
$command
));
}
}
}
\ No newline at end of file
engine/core/query/QueryHandlerFactory.php
0 → 100644
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query
;
use
wfw\engine\core\app\factory\IGenericAppFactory
;
/**
* Factory basée sur dice pour la création d'un command handler
*/
final
class
QueryHandlerFactory
implements
IQueryHandlerFactory
{
/** @var IGenericAppFactory $_factory */
private
$_factory
;
/**
* DiceBasedCommandHandlerFactory constructor.
*
* @param IGenericAppFactory $factory
*/
public
function
__construct
(
IGenericAppFactory
$factory
)
{
$this
->
_factory
=
$factory
;
}
/**
* Constuit un IQueryHandler à partir du nom de la classe d'un CommandHandler
*
* @param string $handlerClass Classe du handler à construire
* @param array $params Paramètres de création
* @return IQueryHandler
*/
public
function
buildCommandHandler
(
string
$handlerClass
,
array
$params
=
[]):
IQueryHandler
{
return
$this
->
_factory
->
create
(
$handlerClass
,
$params
,[
IQueryHandler
::
class
]);
}
}
\ No newline at end of file
engine/core/query/QueryProcessor.php
0 → 100755
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query
;
use
wfw\engine\core\query\security\errors\RejectedQuery
;
use
wfw\engine\core\query\security\IQuerySecurityCenter
;
/**
* Traite les commandes de manières synchrone
*/
final
class
QueryProcessor
implements
IQueryProcessor
{
/** @var IQueryInflector $_inflector */
private
$_inflector
;
/** @var IQuerySecurityCenter $_security */
private
$_security
;
/**
* SynchroneCommandBus constructor.
*
* @param IQueryInflector $inflector Trouve le handler d'une commande
* @param IQuerySecurityCenter $security
*/
public
function
__construct
(
IQueryInflector
$inflector
,
IQuerySecurityCenter
$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
executeCommand
(
ICommand
$command
):
void
{
if
(
!
$this
->
_security
->
allowCommand
(
$command
))
throw
new
RejectedQuery
(
"Access denied : "
.
get_class
(
$command
)
.
" rejected by the security center."
);
$handlers
=
$this
->
_inflector
->
resolveCommandHandlers
(
$command
);
foreach
(
$handlers
as
$handler
){
$handler
->
handleCommand
(
$command
);
}
}
}
\ No newline at end of file
engine/core/query/errors/NoQueryHandlerFound.php
0 → 100755
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query\errors
;
/**
* Aucun handler n'a été trouvé pour la commande.
*/
final
class
NoQueryHandlerFound
extends
\
Exception
{}
\ No newline at end of file
engine/core/query/errors/QueryFailure.php
0 → 100644
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query\errors
;
/**
* Une commande a échoué
*/
class
QueryFailure
extends
\
Exception
{}
\ No newline at end of file
engine/core/query/inflectors/NamespaceBasedInflector.php
0 → 100755
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query\inflectors
;
use
wfw\engine\core\query\errors\NoQueryHandlerFound
;
use
wfw\engine\core\query\IQuery
;
use
wfw\engine\core\query\IQueryHandler
;
use
wfw\engine\core\query\IQueryHandlerFactory
;
use
wfw\engine\core\query\IQueryInflector
;
/**
* Tente de résoudre les QueryHandlers en se basant sur le namespace de la querye.
* Exemple : la query \wfw\engine\packages\users\queries\CreateUser
* sera résolue : \wfw\engine\packages\users\queries\handlers\CreateUserHandler
*/
final
class
NamespaceBasedInflector
implements
IQueryInflector
{
/** @var IQueryHandlerFactory $_factory */
private
$_factory
;
/** @var IQueryHandler[][] $_handlers */
private
$_handlers
;
/** @var IQueryHandler $_resolved */
private
$_resolved
;
/**
* NamespaceBasedInflector constructor.
*
* @param IQueryHandlerFactory $factory Factory de handlers
* @param array $handlers
*/
public
function
__construct
(
IQueryHandlerFactory
$factory
,
array
$handlers
=
[])
{
$this
->
_factory
=
$factory
;
$this
->
_handlers
=
[];
$this
->
_resolved
=
[];
foreach
(
$handlers
as
$queryClass
=>
$handlerClasses
){
if
(
!
is_a
(
$queryClass
,
IQuery
::
class
,
true
))
throw
new
\
InvalidArgumentException
(
"
$queryClass
doesn't implements "
.
IQuery
::
class
);
if
(
!
isset
(
$this
->
_handlers
[
$queryClass
]))
$this
->
_handlers
[
$queryClass
]
=
[];
foreach
(
$handlerClasses
as
$class
=>
$params
){
if
(
!
is_a
(
$class
,
IQueryHandler
::
class
,
true
))
throw
new
\
InvalidArgumentException
(
"
$class
doesn't implements "
.
IQueryHandler
::
class
);
$this
->
_handlers
[
$queryClass
][
$class
]
=
$factory
->
buildQueryHandler
(
$class
,
$params
);
}
}
}
/**
* Trouve un handler pour une querye
*
* @param IQuery $query Comande dont on cherche le handler
* @return IQueryHandler[]
* @throws NoQueryHandlerFound
*/
public
function
resolveQueryHandlers
(
IQuery
$query
):
array
{
$handlers
=
$this
->
resolveHandlersFromQueryClass
(
get_class
(
$query
));
if
(
count
(
$handlers
)
>
0
){
return
$handlers
;
}
else
{
throw
new
NoQueryHandlerFound
(
"No query handler found for query "
.
get_class
(
$query
)
);
}
}
/**
* @param string $query Classe de la querye à résoudre.
* @return array
*/
private
function
resolveHandlersFromQueryClass
(
string
$query
):
array
{
$res
=
[];
if
(
isset
(
$this
->
_resolved
[
$query
])){
$res
[]
=
$this
->
_handlers
[
$query
];
}
else
{
$r
=
[];
if
(
$pos
=
strrpos
(
$query
,
$search
=
"
\\
queries
\\
"
)
!==
false
)
{
$handlerClass
=
substr_replace
(
$query
,
"
\\
queries
\\
handlers
\\
"
,
$pos
,
strlen
(
$search
)
);
}
try
{
$r
[]
=
$this
->
_factory
->
buildQueryHandler
(
(
$handlerClass
??
$query
)
.
"Handler"
);
}
catch
(
\
Exception
$e
){}
$this
->
_handlers
[
$query
]
=
array_merge
(
$this
->
_handlers
[
$query
]
??
[],
$r
);
$res
[]
=
$r
;
}
foreach
(
$this
->
_handlers
as
$class
=>
$handlers
){
if
(
is_a
(
$query
,
$class
))
$res
[]
=
$handlers
;
}
return
array_merge
(
...
$res
);
}
}
\ No newline at end of file
engine/core/query/security/IQueryAccessRuleFactory.php
0 → 100644
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query\security
;
use
wfw\engine\core\query\security\rules\IQueryAccessRule
;
/**
* Allow to create access rules
*/
interface
IQueryAccessRuleFactory
{
/**
* @param string $ruleClass
* @param array $params
* @return IQueryAccessRule
*/
public
function
create
(
string
$ruleClass
,
array
$params
=
[]):
IQueryAccessRule
;
}
\ No newline at end of file
engine/core/query/security/IQuerySecurityCenter.php
0 → 100644
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query\security
;
use
wfw\engine\core\query\IQuery
;
/**
* Will check if a user (or anonymous user) is allowed to run a command.
*/
interface
IQuerySecurityCenter
{
/**
* @param IQuery $cmd Command to run.
* @return bool True, the command is allowed for that user. False otherwise.
*/
public
function
allowCommand
(
IQuery
$cmd
):
bool
;
}
\ No newline at end of file
engine/core/query/security/QueryAccessRuleFactory.php
0 → 100644
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query\security
;
use
wfw\engine\core\app\factory\IGenericAppFactory
;
use
wfw\engine\core\query\security\rules\IQueryAccessRule
;
/**
* Create access rules from a class and params with the app DIC.
*/
final
class
QueryAccessRuleFactory
implements
IQueryAccessRuleFactory
{
/** @var IGenericAppFactory $_factory */
private
$_factory
;
/**
* QueryAccessRuleFactory constructor.
*
* @param IGenericAppFactory $factory
*/
public
function
__construct
(
IGenericAppFactory
$factory
)
{
$this
->
_factory
=
$factory
;
}
/**
* @param string $ruleClass
* @param array $params
* @return IQueryAccessRule
*/
public
function
create
(
string
$ruleClass
,
array
$params
=
[]):
IQueryAccessRule
{
return
$this
->
_factory
->
create
(
$ruleClass
,
$params
,[
IQueryAccessRule
::
class
]);
}
}
\ No newline at end of file
engine/core/query/security/QuerySecurityCenter.php
0 → 100644
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query\security
;
use
wfw\engine\core\query\IQuery
;
use
wfw\engine\core\query\security\rules\IQueryAccessRule
;
/**
* Default security center. Will check if a command is allowed checking a CommandAccessRule.
*/
final
class
QuerySecurityCenter
implements
IQuerySecurityCenter
{
/** @var IQueryAccessRule $_rule */
private
$_rule
;
/** @var bool $_ignoredAsTrue */
private
$_ignoredAsTrue
;
/**
* QuerySecurityCenter constructor.
*
* @param IQueryAccessRule $rule
* @param bool $ignoredAsTrue
*/
public
function
__construct
(
IQueryAccessRule
$rule
,
bool
$ignoredAsTrue
=
false
)
{
$this
->
_rule
=
$rule
;
$this
->
_ignoredAsTrue
=
$ignoredAsTrue
;
}
/**
* @param IQuery $cmd Query to run.
* @return bool True, the query is allowed for that user. False otherwise.
*/
public
function
allowCommand
(
IQuery
$cmd
):
bool
{
return
$this
->
_rule
->
checkCommand
(
$cmd
)
??
$this
->
_ignoredAsTrue
;
}
}
\ No newline at end of file
engine/core/query/security/errors/RejectedQuery.php
0 → 100644
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query\security\errors
;
use
wfw\engine\core\query\errors\QueryFailure
;
/**
* Throwed when a command have been rejected (attempted to be runned by a non authorized user)
*/
class
RejectedQuery
extends
QueryFailure
{}
\ No newline at end of file
engine/core/query/security/rules/AllQueriesAllowed.php
0 → 100644
View file @
6e6026d5
<?php
namespace
wfw\engine\core\query\security\rules
;
use
wfw\engine\core\query\IQuery
;
/**
* All queries are allowed.
*/
final
class
AllQueriesAllowed
implements
IQueryAccessRule
{
/**
* @param IQuery $cmd
* @return null|bool True if the query can be run, false otherwise.