Added api.core.Documentation (human-readable permission set)
This commit is contained in:
parent
853d73a82b
commit
7f4662eaa6
|
@ -39,6 +39,9 @@
|
|||
/* (1) Build uri with args */
|
||||
$cfg[$method]['uri_scheme'] = self::uri_with_parameters($rq->get('id')['path'], $spec);
|
||||
|
||||
/* (2) Build human-readable permission list */
|
||||
$cfg[$method]['perm'] = "accessible with:".self::permissions($spec);
|
||||
|
||||
}
|
||||
|
||||
$response = new Response();
|
||||
|
@ -53,6 +56,7 @@
|
|||
/* (3) Builds uri with GET parameter inside
|
||||
*
|
||||
* @uri<String> Base URI
|
||||
* @spec<array> Specification
|
||||
*
|
||||
---------------------------------------------------------*/
|
||||
private static function uri_with_parameters($uri=null, $spec=null){
|
||||
|
@ -115,6 +119,52 @@
|
|||
}
|
||||
|
||||
|
||||
/* (4) Builds a readable permission list
|
||||
*
|
||||
* @spec<array> Specification
|
||||
*
|
||||
---------------------------------------------------------*/
|
||||
private static function permissions($spec=null){
|
||||
|
||||
/* (1) If no perm return nothing */
|
||||
if( !isset($spec['per']) || !is_array($spec['per']) || count($spec['per']) <= 0 )
|
||||
return 'anyone';
|
||||
|
||||
|
||||
/* (1) Manage permission groups
|
||||
---------------------------------------------------------*/
|
||||
$perm = '';
|
||||
|
||||
$first_or = true;
|
||||
foreach($spec['per'] as $or){
|
||||
|
||||
/* (1) Ignore non-array values */
|
||||
if( !is_array($or) )
|
||||
continue;
|
||||
|
||||
$perm .= !$first_or ? ') or' : '';
|
||||
|
||||
$first_or = false;
|
||||
$first_and = true;
|
||||
|
||||
/* (2) Manage AND */
|
||||
foreach($or as $and){
|
||||
|
||||
$perm .= $first_and ? ' (' : ' and ';
|
||||
$perm .= "$and";
|
||||
$first_and = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( !$first_or )
|
||||
$perm .= ')';
|
||||
|
||||
return $perm;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue