Commit 61925c6e authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Refactorisation (suppression héritage).

parent f8173ce6
<?php
namespace UnicaenAuth\View\Helper;
use UnicaenAuth\Acl\NamedRole;
use Zend\Permissions\Acl\Role\RoleInterface;
/**
......@@ -110,26 +109,20 @@ class UserProfile extends UserAbstract
$roles = array();
foreach ($identityRoles as $id => $role) {
$lib = '';
if ($role instanceof NamedRole) {
$lib = $role->getRoleName();
$lib = '?';
if (is_object($role) && method_exists($role, '__toString')) {
$lib = (string) $role;
}
elseif ($role instanceof RoleInterface) {
$lib = $role->getRoleId();
}
else {
$fallback = null;
set_error_handler(function() use (&$fallback, $unknown) { $fallback = $unknown; });
$lib = (string) $role;
restore_error_handler();
$lib = $lib ?: $fallback;
elseif (is_string($role)) {
$lib = $role;
}
if ($lib) {
if ($this->getTranslator()) {
$lib = $this->getTranslator()->translate($lib, $this->getTranslatorTextDomain());
}
$roles[$id] = $lib;
if ($this->getTranslator()) {
$lib = $this->getTranslator()->translate($lib, $this->getTranslatorTextDomain());
}
$roles[$id] = $lib;
}
return $roles;
......
<?php
namespace UnicaenAuth\View\Helper;
use BjyAuthorize\Provider\Identity\ProviderInterface;
use UnicaenAuth\Acl\NamedRole;
use Zend\Permissions\Acl\Role\RoleInterface;
/**
......@@ -13,8 +11,13 @@ use Zend\Permissions\Acl\Role\RoleInterface;
*
* @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
*/
class UserProfileSelect extends UserProfile
class UserProfileSelect extends UserAbstract
{
/**
* @var \UnicaenAuth\Service\UserContext
*/
protected $userContextService;
/**
* @var string
*/
......@@ -88,6 +91,16 @@ EOS;
return $html;
}
/**
* Retourne le code HTML généré par cette aide de vue.
*
* @return string
*/
public function __toString()
{
return $this->render();
}
/**
* Interroge le service pour abtenir le rôle sélectionné.
*
......@@ -116,31 +129,45 @@ EOS;
}
foreach ($roles as $id => $role) {
$lib = '';
if ($role instanceof NamedRole) {
$lib = $role->getRoleName();
$lib = '?';
if (is_object($role) && method_exists($role, '__toString')) {
$lib = (string) $role;
}
elseif ($role instanceof RoleInterface) {
$lib = $role->getRoleId();
}
else {
$fallback = null;
set_error_handler(function() use (&$fallback, $unknown) { $fallback = $unknown; });
$lib = (string) $role;
restore_error_handler();
$lib = $lib ?: $fallback;
elseif (is_string($role)) {
$lib = $role;
}
if ($lib) {
if ($this->getTranslator()) {
$lib = $this->getTranslator()->translate($lib, $this->getTranslatorTextDomain());
}
$roles[$id] = $lib;
if ($this->getTranslator()) {
$lib = $this->getTranslator()->translate($lib, $this->getTranslatorTextDomain());
}
$roles[$id] = $lib;
}
return $roles;
}
/**
*
* @return \UnicaenAuth\Service\UserContext
*/
public function getUserContextService()
{
return $this->userContextService;
}
/**
*
* @param \UnicaenAuth\Service\UserContext $userContextService
* @return self
*/
public function setUserContextService(\UnicaenAuth\Service\UserContext $userContextService = null)
{
$this->userContextService = $userContextService;
return $this;
}
/**
*
* @return array
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment