You are here

function _services_apply_endpoint in Services 7.3

Same name and namespace in other branches
  1. 6.3 services.resource_build.inc \_services_apply_endpoint()

Applies the endpoint to a set of resources. Resources and controllers that aren't supported will be removed (if $strict is set to TRUE) and both resources and controllers will get the 'endpoint' attribute set.

Parameters

array $resources: An array of resources that the endpoint should be applied on.

array $endpoint: A endpoint information array.

bool $strict: Optional.

Return value

void

4 calls to _services_apply_endpoint()
ServicesRESTServerFactory::getResources in servers/rest_server/includes/ServicesRESTServerFactory.inc
services_get_resources_apply_settings in ./services.module
Load the resources of the endpoint.
xmlrpc_server_xmlrpc in servers/xmlrpc_server/xmlrpc_server.module
Return an array of all defined services methods and callbacks.
_services_build_resources in includes/services.resource_build.inc
Builds the resource definition array for a endpoint.

File

includes/services.resource_build.inc, line 148
Contains functions necessary for building the resource definitions. This is only needed the first time a the resources for a endpoint are fetched, or when the cache has been cleared.

Code

function _services_apply_endpoint(&$resources, $endpoint, $strict = TRUE) {
  if (is_array($endpoint) && isset($endpoint['build_info'])) {
    $endpoint = $endpoint['build_info']['args'][0];
  }
  $classes = array_keys(services_operation_class_info());
  foreach ($resources as $name => &$resource) {
    $cres = $endpoint && isset($endpoint->resources[$name]) ? $endpoint->resources[$name] : array();
    if (isset($resource['key']) && $resource['key'] !== $name && $endpoint && isset($endpoint->resources[$resource['key']])) {
      $cres = $endpoint->resources[$resource['key']];
    }
    $resource['endpoint'] = $cres;
    if ($strict && empty($cres)) {
      unset($resources[$name]);
    }
    else {
      foreach ($classes as $class) {
        if (!empty($resource[$class])) {
          foreach ($resource[$class] as $op => $def) {
            $cop = isset($cres[$class][$op]) ? $cres[$class][$op] : array();
            if (empty($cop) || !$cop['enabled']) {
              if ($strict) {
                unset($resource[$class][$op]);
              }
            }
            else {
              $resource[$class][$op]['endpoint'] = empty($cop['settings']) ? array() : $cop['settings'];
              if (isset($cres['alias'])) {
                $resource[$class][$op]['endpoint']['alias'] = $cres['alias'];
              }
            }
          }
        }
      }
    }
  }
}