Skip to content

Commit

Permalink
feature:2926 add option to hide API methods to reflection.getMethodList
Browse files Browse the repository at this point in the history
git-svn-id: http://piwigo.org/svn/trunk@23261 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
mistic100 committed Jun 16, 2013
1 parent 5671287 commit 0a98109
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions include/ws_core.inc.php
Expand Up @@ -303,15 +303,18 @@ function sendResponse($response)
* @param methodName string - the name of the method as seen externally
* @param callback mixed - php method to be invoked internally
* @param params array - map of allowed parameter names with optional default
* values and parameter flags. Example of $params:
* array( 'param1' => array('default'=>523, 'flags'=>WS_PARAM_FORCE_ARRAY) ) .
* Possible parameter flags are:
* WS_PARAM_ALLOW_ARRAY - this parameter can be an array
* WS_PARAM_FORCE_ARRAY - if this parameter is scalar, force it to an array
* before invoking the method
* values and parameter flags. Example of $params:
* array( 'param1' => array('default'=>523, 'flags'=>WS_PARAM_FORCE_ARRAY) ).
* Possible parameter flags are:
* WS_PARAM_ALLOW_ARRAY - this parameter can be an array
* WS_PARAM_FORCE_ARRAY - if this parameter is scalar, force it to an array
* before invoking the method
* @param description string - a description of the method.
* @param include_file string - a file to be included befaore the callback is executed
* @param options array - Available options are:
* hidden - if true, this method won't be visible by reflection.getMethodList
*/
function addMethod($methodName, $callback, $params=array(), $description, $include_file='')
function addMethod($methodName, $callback, $params=array(), $description, $include_file='', $options=array())
{
if (!is_array($params))
{
Expand All @@ -323,21 +326,21 @@ function addMethod($methodName, $callback, $params=array(), $description, $inclu
$params = array_flip($params);
}

foreach( $params as $param=>$options)
foreach( $params as $param=>$data)
{
if ( !is_array($options) )
if ( !is_array($data) )
{
$params[$param] = array('flags'=>0);
}
else
{
$flags = isset($options['flags']) ? $options['flags'] : 0;
if ( array_key_exists('default', $options) )
$flags = isset($data['flags']) ? $data['flags'] : 0;
if ( array_key_exists('default', $data) )
{
$flags |= WS_PARAM_OPTIONAL;
}
$options['flags'] = $flags;
$params[$param] = $options;
$data['flags'] = $flags;
$params[$param] = $data;
}
}

Expand All @@ -346,6 +349,7 @@ function addMethod($methodName, $callback, $params=array(), $description, $inclu
'description' => $description,
'signature' => $params,
'include' => $include_file,
'options' => $options,
);
}

Expand Down Expand Up @@ -461,7 +465,9 @@ function invoke($methodName, $params)
*/
static function ws_getMethodList($params, &$service)
{
return array('methods' => new PwgNamedArray( array_keys($service->_methods),'method' ) );
$methods = array_filter($service->_methods,
create_function('$m', 'return empty($m["options"]["hidden"]) || !$m["options"]["hidden"];'));
return array('methods' => new PwgNamedArray( array_keys($methods),'method' ) );
}

/**
Expand Down

0 comments on commit 0a98109

Please sign in to comment.