Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
lib
unicaen
auth
Commits
7e3cf398
Commit
7e3cf398
authored
Mar 26, 2019
by
Bertrand Gauthier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UtilisateurController: utilisation du RoleFormatter ; amélioration du RoleFormatter.
parent
6973a6e4
Pipeline
#4137
passed with stage
in 27 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
17 deletions
+45
-17
src/UnicaenAuth/Controller/UtilisateurController.php
src/UnicaenAuth/Controller/UtilisateurController.php
+6
-3
src/UnicaenAuth/Formatter/RoleFormatter.php
src/UnicaenAuth/Formatter/RoleFormatter.php
+39
-14
No files found.
src/UnicaenAuth/Controller/UtilisateurController.php
View file @
7e3cf398
...
...
@@ -7,8 +7,8 @@ use UnicaenApp\Mapper\Ldap\People as LdapPeopleMapper;
use
UnicaenAuth\Entity\Db\AbstractUser
;
use
UnicaenAuth\Entity\Ldap\People
;
use
UnicaenAuth\Entity\Shibboleth\ShibUser
;
use
UnicaenAuth\Formatter\RoleFormatter
;
use
UnicaenAuth\Options\ModuleOptions
;
use
UnicaenAuth\Service\ShibService
;
use
UnicaenAuth\Service\Traits\ShibServiceAwareTrait
;
use
UnicaenAuth\Service\Traits\UserContextServiceAwareTrait
;
use
UnicaenAuth\Service\UserContext
;
...
...
@@ -111,8 +111,11 @@ class UtilisateurController extends AbstractActionController
}
if
(
$addFlashMessage
)
{
$selectedRole
=
$this
->
serviceUserContext
->
getSelectedIdentityRoleToString
();
$message
=
sprintf
(
"Vous endossez à présent le profil utilisateur <strong>%s</strong>."
,
$selectedRole
);
$selectedRole
=
$this
->
serviceUserContext
->
getSelectedIdentityRole
();
$message
=
sprintf
(
"Vous endossez à présent le rôle utilisateur '<strong>%s</strong>'."
,
(
new
RoleFormatter
())
->
format
(
$selectedRole
)
);
$this
->
flashMessenger
()
->
setNamespace
(
'UnicaenAuth/success'
)
->
addMessage
(
$message
);
}
...
...
src/UnicaenAuth/Formatter/RoleFormatter.php
View file @
7e3cf398
...
...
@@ -2,41 +2,66 @@
namespace
UnicaenAuth\Formatter
;
use
Zend\Permissions\
Rbac
\RoleInterface
;
use
Zend\Permissions\
Acl\Role
\RoleInterface
;
class
RoleFormatter
{
/**
* Retourne le rôle
utilisateur
spécifié au format littéral.
* Retourne le rôle spécifié au format littéral.
*
* @param $role
* @param
object|RoleInterface|string
$role
* @return string
*
* @see formatOne()
*/
public
function
format
(
$role
)
{
return
$this
->
roleToString
(
$role
);
return
$this
->
formatOne
(
$role
);
}
/**
* Retourne le rôle
utilisateur
spécifié au format littéral.
* Retourne le rôle spécifié au format littéral.
*
* @param object|RoleInterface|string $role
* @return string
*/
p
rivate
function
roleToString
(
$role
)
p
ublic
function
formatOne
(
$role
)
{
$
string
=
'?'
;
$
formattedRole
=
'?'
;
if
(
is_object
(
$role
)
&&
method_exists
(
$role
,
'__toString'
))
{
$string
=
(
string
)
$role
;
}
elseif
(
$role
instanceof
RoleInterface
)
{
$string
=
$role
->
getRoleId
();
if
(
$role
instanceof
RoleInterface
)
{
$formattedRole
=
$role
->
getRoleId
();
}
elseif
(
is_string
(
$role
))
{
$string
=
$role
;
$formattedRole
=
(
string
)
$role
;
}
elseif
(
is_object
(
$role
)
&&
method_exists
(
$role
,
'__toString'
))
{
$formattedRole
=
$role
;
}
return
$formattedRole
;
}
/**
* Retourne les rôles spécifiés au format littéral.
*
* @param object[]|RoleInterface[]|string[] $roles
* @return string[]
*/
public
function
formatMany
(
array
$roles
)
{
$formattedRoles
=
[];
foreach
(
$roles
as
$key
=>
$role
)
{
if
(
$role
instanceof
RoleInterface
)
{
$key
=
$role
->
getRoleId
();
}
elseif
(
is_string
(
$role
))
{
$key
=
$role
;
}
$formattedRoles
[
$key
]
=
$this
->
formatOne
(
$role
);
}
return
$
string
;
return
$
formattedRoles
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment