Added api.core.Documentation (human-readable parameter list)

This commit is contained in:
xdrm-brackets 2017-12-13 13:00:20 +01:00
parent 73925299a2
commit a2828fbd63
1 changed files with 87 additions and 8 deletions

View File

@ -40,7 +40,13 @@
$cfg[$method]['uri_scheme'] = self::uri_scheme($rq->get('id')['path'], $spec);
/* (2) Build human-readable permission list */
$cfg[$method]['perm'] = "accessible with:".self::permissions($spec);
$cfg[$method]['permissions'] = "accessible with:".self::permissions($spec);
unset($cfg[$method]['per']);
/* (3) Build ease parameter list */
$cfg[$method]['parameters'] = self::parameters($spec);
unset($cfg[$method]['par']);
}
@ -96,19 +102,16 @@
$pspec = $spec['par']["URL$i"];
/* (2.2) Define the 'optional' property */
$optional = ( isset($pspec['opt']) && $pspec['opt'] === true ) ? '?' : '';
/* (2.3) If 'rename' set the rename content */
/* (2.2) If 'rename' set the rename content */
if( isset($pspec['ren']) && is_string($pspec['ren']) ){
$uri .= '/@'.$pspec['ren']."$optional";
$uri .= '/@'.$pspec['ren'];
continue;
}
/* (2.4) If no rename set the default name */
$uri .= "/@url$i$optional";
/* (2.3) If no rename set the default name */
$uri .= "/@url$i";
}
return $uri;
@ -161,6 +164,82 @@
}
/* (5) Builds a readable parameter list
*
* @spec<array> Specification
*
---------------------------------------------------------*/
private static function parameters($spec=null){
/* (1) If no param return nothing */
if( !isset($spec['par']) || !is_array($spec['par']) || count($spec['par']) <= 0 )
return;
/* (2) Initialize parameter output */
$param = [
'GET' => [],
'POST' => []
];
$post_index = -1;
/* (1) Set 'URL' parameter available in the spec */
foreach($spec['par'] as $pname=>$pspec){
/* (1) Manage POST parameters
---------------------------------------------------------*/
if( strlen($pname) >= 3 && substr($pname, 0, 3) == 'URL' && is_numeric(substr($pname, 3)) ){
/* (1) Get the URL index (position) */
$index = intval(substr($pname,3));
/* (2) Manage 'rename' property */
$name = ( isset($pspec['ren']) && is_string($pspec['ren']) ) ? $pspec['ren'] : $pname;
/* (3) Set default values */
$param['GET'][$index] = [
'name' => $name,
'required' => !isset($pspec['opt']) || $pspec['opt'] !== true
];
/* (4) Manage 'default' property */
if( !$param['GET'][$index]['required'] )
$param['GET'][$index]['default'] = isset($pspec['def']) ? $pspec['def'] : null;
continue;
}
/* (2) Manage GET+POST parameters
---------------------------------------------------------*/
/* (1) Get the POST index */
$post_index = $post_index + 1;
/* (2) Manage 'rename' property */
$name = ( isset($pspec['ren']) && is_string($pspec['ren']) ) ? $pspec['ren'] : $pname;
/* (3) Set default values */
$param['POST'][$post_index] = [
'name' => $name,
'required' => !isset($pspec['opt']) || $pspec['opt'] !== true
];
/* (4) Manage 'default' property */
if( !$param['POST'][$post_index]['required'] )
$param['POST'][$post_index]['default'] = isset($pspec['def']) ? $pspec['def'] : null;
}
return $param;
}