$map=array(0->array(matchString->class,....), 1->array(matchString->class,.......).....)
foreach($map as $items) {
foreach($items as $itemkey=>$value){
if(inarray($itemkey,roles)) return new $value();
}
}
class OptoolLib_Utils_PromoCardHelper_PromoCardValidateHelper
{protected static $validatorPool = array();
public static function Instance(array $roles)
{
if (empty($roles)) {
throw new Exception('用户权限不能为空!');
}
$poolKey = implode('_', $roles);
if (!self::$validatorPool[$poolKey]) {
self::$validator = $this->getValidator($roles);
}
return self::$validator;
}private function getValidator(array $roles)
{
if (in_array(OptoolLib_User::GROUP_NAME_ADMIN, $roles)||in_array(OptoolLib_User::GROUP_NAME_PM, $roles)
||in_array('cs_director', $roles)) {$validator = new OptoolLib_Utils_PromoCardHelper_PromoCardValidateHighPermission();
} else if(in_array(OptoolLib_User::GROUP_NAME_CS_MANAGER, $roles)) {
$validator = new OptoolLib_Utils_PromoCardHelper_PromoCardValidateCsManerage();
} else if(in_array(OptoolLib_User::GROUP_NAME_MARKETING_BD, $roles)) {
} else if(in_array(OptoolLib_User::GROUP_NAME_CS_VIP, $roles)) {
} else if(in_array(OptoolLib_User::GROUP_NAME_CS, $roles)) {
} else {
throw new Exception('您的权限不足!');
}if (!$validator instanceof OptoolLib_Utils_PromoCardHelper_PromoCardValidatorInterface) {
throw new Exception('验证类必须继承 OptoolLib_Utils_PromoCardHelper_PromoCardValidatorInterface');
}return $validator;
}}
不能用MAP,悲剧