You are here

public static function ResourceManager::executeCallback in RESTful 7.2

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

Overrides ResourceManagerInterface::executeCallback

9 calls to ResourceManager::executeCallback()
CacheDecoratedResource::process in src/Plugin/resource/Decorators/CacheDecoratedResource.php
Controller function that passes the data along and executes right action.
CsrfToken::index in src/Plugin/resource/CsrfToken.php
Basic implementation for listing.
FormatterManager::processData in src/Formatter/FormatterManager.php
Helper function to get a formatter and apply a method.
Resource::getControllerFromPath in src/Plugin/resource/Resource.php
Return the controller for a given path.
Resource::preflight in src/Plugin/resource/Resource.php
Adds the Allowed-Origin headers.

... See full list

File

src/Resource/ResourceManager.php, line 178
Contains \Drupal\restful\Resource\ResourceManager.

Class

ResourceManager

Namespace

Drupal\restful\Resource

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 ServerConfigurationException("Callback function: {$callback_name} does not exist.");
  }
  return call_user_func_array($callback, $params);
}