You are here

public static function RestfulBase::executeCallback in RESTful 7

Execute a user callback.

Parameters

mixed $callback: There are 3 ways to define a callback:

  • String with a function name. Ex: 'drupal_map_assoc'.
  • An array containing an object and a method name of that object. Ex: array($this, 'format').
  • An array containing any of the methods before and an array of parameters to pass to the callback. Ex: array(array($this, 'processing'), array('param1', 2))

array $params: Array of additional parameters to pass in.

Return value

mixed The return value of the callback.

Throws

\RestfulException

7 calls to RestfulBase::executeCallback()
RestfulBase::getControllerFromPath in plugins/restful/RestfulBase.php
Return the controller from a given path.
RestfulCsrfTokenResource::index in plugins/restful/csrf/RestfulCsrfTokenResource.class.php
Get a list of entities.
RestfulDataProviderCToolsPlugins::view in plugins/restful/RestfulDataProviderCToolsPlugins.php
@todo: We should generalize this, as it's repeated often.
RestfulDataProviderDbQuery::mapDbRowToPublicFields in plugins/restful/RestfulDataProviderDbQuery.php
Prepares the output array from the database row object.
RestfulDataProviderVariable::mapVariableToPublicFields in plugins/restful/RestfulDataProviderVariable.php
Maps variable names and values to public fields.

... See full list

File

plugins/restful/RestfulBase.php, line 575
Contains RestfulBase.

Class

RestfulBase
Class \RestfulBase

Code

public static function executeCallback($callback, array $params = array()) {
  if (!is_callable($callback)) {
    if (is_array($callback) && count($callback) == 2 && is_array($callback[1])) {

      // This code deals with the third scenario in the docblock. Get the
      // callback and the parameters from the array, merge the parameters with
      // the existing ones and call recursively to reuse the logic for the
      // other cases.
      return static::executeCallback($callback[0], array_merge($params, $callback[1]));
    }
    $callback_name = is_array($callback) ? $callback[1] : $callback;
    throw new \RestfulException(format_string('Callback function: @callback does not exists.', array(
      '@callback' => $callback_name,
    )));
  }
  return call_user_func_array($callback, $params);
}