You are here

function _invoice_api_dispatch in Invoice 7

Invoice API dispatcher

1 call to _invoice_api_dispatch()
invoice_init in ./invoice.module
Implements hook_init()

File

./invoice_api.inc, line 51

Code

function _invoice_api_dispatch() {
  $menuItem = menu_get_item();
  $pageCallback = isset($menuItem['page_callback']) ? $menuItem['page_callback'] : null;
  $pageArguments = isset($menuItem['page_arguments']) ? $menuItem['page_arguments'] : array();

  // Check for API route
  if (strpos($pageCallback, 'invoice_api') === 0) {
    $GLOBALS['invoice_api'] = true;
    if (isset($menuItem['page_arguments'][0])) {
      $format = $menuItem['page_arguments'][0];
      $pageArguments[0] = str_replace('invoice.', '', $format);
    }
    else {
      $format = null;
    }
    _invoice_api_check_response_format_support(str_replace('invoice.', '', $format));
    _invoice_api_authenticate();

    // Prepend request method
    array_unshift($pageArguments, strtoupper($_SERVER['REQUEST_METHOD']));
    call_user_func_array($pageCallback, $pageArguments);
    exit;
  }
}