You are here

class EntityShareServerRest in Entity Share 7

Class EntityShareServerRest.

Hierarchy

Expanded class hierarchy of EntityShareServerRest

File

modules/entity_share_server/includes/entity_share_server.rest.inc, line 11
Class for handling REST request.

View source
class EntityShareServerRest extends EntityShareServerRestAbstract {

  /**
   * Handle the GET method action.
   *
   * Read an entity by UUID.
   */
  protected function handleGet() {
    $entity_type = $this
      ->getParam('type');
    $entity_uuid = $this
      ->getParam('id');
    if (!empty($entity_type)) {
      $uuids = array();
      if (!empty($entity_uuid)) {
        $uuids[] = $entity_uuid;
      }
      $entities = entity_uuid_load($entity_type, $uuids);
      if (!empty($entity_uuid)) {
        if (empty($entities)) {
          $this
            ->setError('Entity not found', '404 Not Found');
        }
        else {
          $entity = reset($entities);
          $export = new EntityShareEntityExport($entity);
          $exported_entity = $export
            ->execute();
          $this
            ->setResult($exported_entity);
        }
      }
      else {

        // @todo Deal with list get.
        $this
          ->setResult($entities);
      }
    }
    else {

      // @todo Should we set a more precise error?
      $this
        ->setError('Incorrect parameters');
    }
  }

  /**
   * Handle the POST method action.
   *
   * Create a new entity.
   */
  protected function handlePost() {
    $request = $this
      ->getRequest();
    if (isset($request)) {
      $entity = $request['datas'];
      try {
        $import = new EntityShareEntityImport($entity);
        $entity_id = $import
          ->execute();
        if (!empty($entity_id)) {
          $this
            ->setResult(array(
            'entity_id' => $entity_id,
          ));
        }
        else {
          $this
            ->setError('Entity not created');
        }
      } catch (Exception $e) {
        $this
          ->setError('Error will trying to create entity', '500 Internal Server Error');
      }
    }
  }

  /**
   * Handle the PUT method action.
   *
   * Update an entity.
   */
  protected function handlePut() {
    $this
      ->handlePost();
  }

  /**
   * Handle the DELETE method action.
   *
   * Delete an entity by UUID.
   */
  protected function handleDelete() {
    try {
      $result = entity_uuid_delete($this
        ->getParam('type'), $this
        ->getParam('id'));
      $this
        ->setResult($result === FALSE ? FALSE : TRUE);
    } catch (Exception $e) {
      $this
        ->setError('Error will trying to delete entity', '500 Internal Server Error');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityShareServerRest::handleDelete protected function Handle the DELETE method action. Overrides EntityShareServerRestAbstract::handleDelete
EntityShareServerRest::handleGet protected function Handle the GET method action. Overrides EntityShareServerRestAbstract::handleGet
EntityShareServerRest::handlePost protected function Handle the POST method action. Overrides EntityShareServerRestAbstract::handlePost
EntityShareServerRest::handlePut protected function Handle the PUT method action. Overrides EntityShareServerRestAbstract::handlePut
EntityShareServerRestAbstract::$error protected property Error.
EntityShareServerRestAbstract::$headers protected property Http headers.
EntityShareServerRestAbstract::$request protected property Http request.
EntityShareServerRestAbstract::$response protected property Http response.
EntityShareServerRestAbstract::$result protected property Result.
EntityShareServerRestAbstract::doLogin protected function Authenticate the user.
EntityShareServerRestAbstract::formatResponse protected function Format the response in function of the accept header.
EntityShareServerRestAbstract::getDefaultRequest protected function Default request parameters.
EntityShareServerRestAbstract::getError public function Get the error of the action.
EntityShareServerRestAbstract::getParam public function Get the parameter value.
EntityShareServerRestAbstract::getRequest public function Get the Request.
EntityShareServerRestAbstract::getRequestMethod public function Get the method of the request.
EntityShareServerRestAbstract::getResult public function Get the result of the action.
EntityShareServerRestAbstract::handle public function Handle the server.
EntityShareServerRestAbstract::HOOK_PREFIX constant
EntityShareServerRestAbstract::IP_RESTRICTED_VARIABLE constant
EntityShareServerRestAbstract::isRequestAllowed protected function Security control.
EntityShareServerRestAbstract::outputResponse protected function Output the response to the client.
EntityShareServerRestAbstract::parseRequest protected function Parse the request.
EntityShareServerRestAbstract::sendHeaders protected function Send headers to the response.
EntityShareServerRestAbstract::setError protected function Set the error of the action.
EntityShareServerRestAbstract::setHeader public function Set a header (but not send it).
EntityShareServerRestAbstract::setResult protected function Set the result of the action.
EntityShareServerRestAbstract::STATUS_ERROR constant
EntityShareServerRestAbstract::STATUS_OK constant
EntityShareServerRestAbstract::WATCHDOG_TYPE constant
EntityShareServerRestAbstract::__construct public function Constructor. Initialize properties.