/** * Detects whether the script is running from a command line environment. * * @return bool * TRUE if a command line environment is detected. FALSE otherwise. */ protected function isCli() { // Needed to detect if run-tests.sh is running the tests. $cli = \RestfulManager::getRequestHttpHeader('User-Agent') == 'Drupal command line'; return $cli || drupal_is_cli(); }
/** * Allow altering the request before it is processed. * * @param $request * The request array. */ function hook_restful_parse_request_alter(&$request) { $request['__application'] += array( 'some_header' => \RestfulManager::getRequestHttpHeader('X-Some-Header'), ); }
/** * Gets the major and minor version for the current request. * * @param string $path * The router path. * * @return array * The array with the version. */ public static function getVersionFromRequest($path = NULL) { $version = &drupal_static(__CLASS__ . '::' . __FUNCTION__); if (isset($version)) { return $version; } list($resource_name, $version) = static::getPageArguments($path); if (preg_match('/^v\d+(\.\d+)?$/', $version)) { $version = static::parseVersionString($version, $resource_name); return $version; } // If there is no version in the URL check the header. if ($api_version = \RestfulManager::getRequestHttpHeader('X-API-Version')) { $version = static::parseVersionString($api_version, $resource_name); return $version; } // If there is no version negotiation information return the latest version. $version = static::getResourceLastVersion($resource_name); return $version; }