You are here

class DeployServiceRestJSON in Deploy - Content Staging 7.3

Same name and namespace in other branches
  1. 7.2 plugins/DeployServiceRestJSON.inc \DeployServiceRestJSON

Class for deploying to a REST server using JSON

Hierarchy

Expanded class hierarchy of DeployServiceRestJSON

2 string references to 'DeployServiceRestJSON'
deploy_deploy_services in ./deploy.deploy.inc
Implements hook_deploy_services().
deploy_example_deploy_endpoints_default in modules/deploy_example/deploy_example.deploy_endpoints.inc
Implements hook_deploy_endpoints_default().

File

plugins/DeployServiceRestJSON.inc, line 10
JSON REST client for deploying entities.

View source
class DeployServiceRestJSON extends DeployServiceRest {

  /**
   * {@inheritdoc}
   */
  public function deploy(Traversable $iterator) {
    foreach ($iterator as $entity) {
      $json_data = drupal_json_encode($entity);
      $this->config['headers']['Content-Type'] = 'application/json';

      // TODO: Consider making the resource path configurable.
      $url = $this->config['url'] . '/' . $entity->__metadata['uri'] . '.json';

      // Temporary hack for the built-in PHP 5.4 web server that doesn't route
      // filenames correctly.
      // TODO: See if we can remove the .json suffix for all server. The
      // Content-Type header should be enough in most (all?) cases.
      if (php_sapi_name() == 'cli-server') {
        $url = $this->config['url'] . '/' . $entity->__metadata['uri'];
      }
      $this
        ->httpRequest($url, 'PUT', $json_data);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function publish(Traversable $iterator) {
    foreach ($iterator as $entity) {
      $this->config['headers']['Content-Type'] = 'application/json';

      // TODO: Consider making the resource path configurable.
      $url = $this->config['url'] . '/' . $entity->__metadata['uri'] . '/publish';

      //$this->httpRequest($url, 'POST');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeployServiceRest::$config public property Configuration options.
DeployServiceRest::$headers public property An associative array of http headers for the REST request.
DeployServiceRest::configForm public function Configuration form. Overrides DeployService::configForm
DeployServiceRest::fetchContext protected function Fetches the context for the HTTP request.
DeployServiceRest::httpRequest public function Makes a HTTP request. 1
DeployServiceRest::__construct public function Constructor for a service plugin. Overrides DeployService::__construct 1
DeployServiceRestJSON::deploy public function Deploy all entities in the $iterator. This method should only move entities over to the endpoint and create unpublished revisions (if supported). The 'publish' method is responsible for publishing all successfully deployed entities. Overrides DeployServiceRest::deploy
DeployServiceRestJSON::publish public function Publish all entities in the $iterator. This method should only publish entities on the endpoint (if supported). The 'deploy' method is responsible for moving the entities to the endpoint, prior to the publishing. Overrides DeployServiceRest::publish