You are here

abstract class ResourceDecoratorBase in RESTful 7.2

Class ResourceDecoratorBase.

@package Drupal\restful\Plugin\resource\Decorators

Hierarchy

Expanded class hierarchy of ResourceDecoratorBase

File

src/Plugin/resource/Decorators/ResourceDecoratorBase.php, line 25
Contains \Drupal\restful\Plugin\resource\Decorators\ResourceDecoratorBase.

Namespace

Drupal\restful\Plugin\resource\Decorators
View source
abstract class ResourceDecoratorBase extends PluginBase implements ResourceDecoratorInterface, ExplorableDecoratorInterface {

  /**
   * The decorated resource.
   *
   * @var ResourceInterface
   */
  protected $subject;

  /**
   * {@inheritdoc}
   */
  public function getDecoratedResource() {
    return $this->subject;
  }

  /**
   * {@inheritdoc}
   */
  public function getPrimaryResource() {
    $resource = $this
      ->getDecoratedResource();
    while ($resource instanceof ResourceDecoratorInterface) {
      $resource = $resource
        ->getDecoratedResource();
    }
    return $resource;
  }

  /**
   * {@inheritdoc}
   */
  public function dataProviderFactory() {
    return $this->subject
      ->dataProviderFactory();
  }

  /**
   * {@inheritdoc}
   */
  public function getAccount($cache = TRUE) {
    return $this->subject
      ->getAccount($cache);
  }

  /**
   * {@inheritdoc}
   */
  public function setAccount($account) {
    $this->subject
      ->setAccount($account);
    $this
      ->getDataProvider()
      ->setAccount($account);
  }

  /**
   * {@inheritdoc}
   */
  public function switchUserBack() {
    $this->subject
      ->switchUserBack();
  }

  /**
   * {@inheritdoc}
   */
  public function discover($path = NULL) {
    return $this->subject
      ->discover($path);
  }

  /**
   * {@inheritdoc}
   */
  public function getRequest() {
    return $this->subject
      ->getRequest();
  }

  /**
   * {@inheritdoc}
   */
  public function setRequest(RequestInterface $request) {
    $this->subject
      ->setRequest($request);

    // Make sure that the request is updated in the data provider.
    $this
      ->getDataProvider()
      ->setRequest($request);
  }

  /**
   * {@inheritdoc}
   */
  public function getPath() {
    return $this->subject
      ->getPath();
  }

  /**
   * {@inheritdoc}
   */
  public function setPath($path) {
    $this->subject
      ->setPath($path);
  }

  /**
   * {@inheritdoc}
   */
  public function getFieldDefinitions() {
    return $this->subject
      ->getFieldDefinitions();
  }

  /**
   * {@inheritdoc}
   */
  public function getDataProvider() {
    return $this->subject
      ->getDataProvider();
  }

  /**
   * {@inheritdoc}
   */
  public function setDataProvider(DataProviderInterface $data_provider = NULL) {
    $this->subject
      ->setDataProvider($data_provider);
  }

  /**
   * {@inheritdoc}
   */
  public function getResourceName() {
    return $this->subject
      ->getResourceName();
  }

  /**
   * {@inheritdoc}
   */
  public function process() {
    return $this->subject
      ->process();
  }

  /**
   * {@inheritdoc}
   */
  public function controllersInfo() {
    return $this->subject
      ->controllersInfo();
  }

  /**
   * {@inheritdoc}
   */
  public function getControllers() {
    return $this->subject
      ->getControllers();
  }

  /**
   * {@inheritdoc}
   */
  public function index($path) {
    return $this->subject
      ->index($path);
  }

  /**
   * {@inheritdoc}
   */
  public function view($path) {
    return $this->subject
      ->view($path);
  }

  /**
   * {@inheritdoc}
   */
  public function create($path) {
    return $this->subject
      ->create($path);
  }

  /**
   * {@inheritdoc}
   */
  public function update($path) {
    return $this->subject
      ->update($path);
  }

  /**
   * {@inheritdoc}
   */
  public function replace($path) {
    return $this->subject
      ->replace($path);
  }

  /**
   * {@inheritdoc}
   */
  public function remove($path) {
    $this->subject
      ->remove($path);
  }

  /**
   * {@inheritdoc}
   */
  public function getVersion() {
    return $this->subject
      ->getVersion();
  }

  /**
   * {@inheritdoc}
   */
  public function versionedUrl($path = '', $options = array(), $version_string = TRUE) {
    return $this->subject
      ->versionedUrl($path, $options, $version_string);
  }

  /**
   * {@inheritdoc}
   */
  public function getConfiguration() {
    return $this->subject
      ->getConfiguration();
  }

  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) {
    $this->subject
      ->setConfiguration($configuration);
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return $this->subject
      ->defaultConfiguration();
  }

  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    return $this->subject
      ->calculateDependencies();
  }

  /**
   * {@inheritdoc}
   */
  public function access() {
    return $this->subject
      ->access();
  }

  /**
   * {@inheritdoc}
   */
  public function getControllerFromPath($path = NULL, ResourceInterface $resource = NULL) {
    return $this->subject
      ->getControllerFromPath($path, $resource ?: $this);
  }

  /**
   * {@inheritdoc}
   */
  public function getResourceMachineName() {
    return $this->subject
      ->getResourceMachineName();
  }

  /**
   * {@inheritdoc}
   *
   * This is a decorated resource, get proxy the request until you reach the
   * annotated resource.
   */
  public function getPluginDefinition() {
    return $this->subject
      ->getPluginDefinition();
  }

  /**
   * {@inheritdoc}
   *
   * This is a decorated resource, set proxy the request until you reach the
   * annotated resource.
   */
  public function setPluginDefinition(array $plugin_definition) {
    $this->subject
      ->setPluginDefinition($plugin_definition);
    if (!empty($plugin_definition['dataProvider'])) {
      $this
        ->getDataProvider()
        ->addOptions($plugin_definition['dataProvider']);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function enable() {
    $this->subject
      ->enable();
  }

  /**
   * {@inheritdoc}
   */
  public function disable() {
    $this->subject
      ->disable();
  }

  /**
   * {@inheritdoc}
   */
  public function isEnabled() {
    return $this->subject
      ->isEnabled();
  }

  /**
   * {@inheritdoc}
   */
  public function setFieldDefinitions(ResourceFieldCollectionInterface $field_definitions) {
    return $this->subject
      ->setFieldDefinitions($field_definitions);
  }

  /**
   * {@inheritdoc}
   */
  public function getUrl(array $options = array(), $keep_query = TRUE, RequestInterface $request = NULL) {
    return $this->subject
      ->getUrl($options, $keep_query, $request);
  }

  /**
   * {@inheritdoc}
   */
  public function doGet($path = '', array $query = array()) {
    $this
      ->setPath($path);
    $this
      ->setRequest(Request::create($this
      ->versionedUrl($path, array(
      'absolute' => FALSE,
    )), $query, RequestInterface::METHOD_GET));
    return $this
      ->process();
  }

  /**
   * {@inheritdoc}
   */
  public function doPost(array $parsed_body) {
    return $this
      ->doWrite(RequestInterface::METHOD_POST, '', $parsed_body);
  }

  /**
   * {@inheritdoc}
   */
  public function doPatch($path, array $parsed_body) {
    if (!$path) {
      throw new BadRequestException('PATCH requires a path. None given.');
    }
    return $this
      ->doWrite(RequestInterface::METHOD_PATCH, $path, $parsed_body);
  }

  /**
   * {@inheritdoc}
   */
  public function doPut($path, array $parsed_body) {
    if (!$path) {
      throw new BadRequestException('PUT requires a path. None given.');
    }
    return $this
      ->doWrite(RequestInterface::METHOD_PUT, $path, $parsed_body);
  }

  /**
   * {@inheritdoc}
   */
  private function doWrite($method, $path, array $parsed_body) {
    $this
      ->setPath($path);
    $this
      ->setRequest(Request::create($this
      ->versionedUrl($path, array(
      'absolute' => FALSE,
    )), array(), $method, NULL, FALSE, NULL, array(), array(), array(), $parsed_body));
    return $this
      ->process();
  }

  /**
   * {@inheritdoc}
   */
  public function doDelete($path) {
    if (!$path) {
      throw new BadRequestException('DELETE requires a path. None given.');
    }
    $this
      ->setPath($path);
    $this
      ->setRequest(Request::create($this
      ->versionedUrl($path, array(
      'absolute' => FALSE,
    )), array(), RequestInterface::METHOD_DELETE));
    return $this
      ->process();
  }

  /**
   * {@inheritdoc}
   */
  public function getPluginId() {
    return $this->subject
      ->getPluginId();
  }

  /**
   * Checks if the decorated object is an instance of something.
   *
   * @param string $class
   *   Class or interface to check the instance.
   *
   * @return bool
   *   TRUE if the decorated object is an instace of the $class. FALSE
   *   otherwise.
   */
  public function isInstanceOf($class) {
    if ($this instanceof $class || $this->subject instanceof $class) {
      return TRUE;
    }

    // Check if the decorated resource is also a decorator.
    if ($this->subject instanceof ExplorableDecoratorInterface) {
      return $this->subject
        ->isInstanceOf($class);
    }
    return FALSE;
  }

  /**
   * If any method not declared, then defer it to the decorated field.
   *
   * This decorator class is proxying all the calls declared in the
   * ResourceInterface to the underlying decorated resource. But it is not
   * doing it for any of the methods of the parents of ResourceInterface.
   *
   * With this code, any method that is not declared in the class will try to
   * make that method call it in the decorated resource.
   *
   * @param string $name
   *   The name of the method that could not be found.
   * @param array $arguments
   *   The arguments passed to the method, collected in an array.
   *
   * @return mixed
   *   The result of the call.
   */
  public function __call($name, $arguments) {
    return call_user_func_array(array(
      $this->subject,
      $name,
    ), $arguments);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ResourceDecoratorBase::$subject protected property The decorated resource.
ResourceDecoratorBase::access public function Determine if user can access the handler. Overrides ResourceInterface::access
ResourceDecoratorBase::calculateDependencies public function
ResourceDecoratorBase::controllersInfo public function Gets the controllers. Overrides ResourceInterface::controllersInfo
ResourceDecoratorBase::create public function Basic implementation for create. Overrides ResourceInterface::create
ResourceDecoratorBase::dataProviderFactory public function Data provider factory. Overrides ResourceInterface::dataProviderFactory 1
ResourceDecoratorBase::defaultConfiguration public function
ResourceDecoratorBase::disable public function Disable the resource. Overrides ResourceInterface::disable 1
ResourceDecoratorBase::discover public function Discovery controller callback. Overrides ResourceInterface::discover
ResourceDecoratorBase::doDelete public function Shorthand method to perform a quick DELETE request. Overrides ResourceInterface::doDelete
ResourceDecoratorBase::doGet public function Shorthand method to perform a quick GET request. Overrides ResourceInterface::doGet
ResourceDecoratorBase::doPatch public function Shorthand method to perform a quick PATCH request. Overrides ResourceInterface::doPatch
ResourceDecoratorBase::doPost public function Shorthand method to perform a quick POST request. Overrides ResourceInterface::doPost
ResourceDecoratorBase::doPut public function Shorthand method to perform a quick PUT request. Overrides ResourceInterface::doPut
ResourceDecoratorBase::doWrite private function
ResourceDecoratorBase::enable public function Enable the resource. Overrides ResourceInterface::enable 1
ResourceDecoratorBase::getAccount public function Get the user from for request. Overrides ResourceInterface::getAccount
ResourceDecoratorBase::getConfiguration public function
ResourceDecoratorBase::getControllerFromPath public function Return the controller for a given path. Overrides ResourceInterface::getControllerFromPath
ResourceDecoratorBase::getControllers public function Gets the controllers for this resource. Overrides ResourceInterface::getControllers
ResourceDecoratorBase::getDataProvider public function Gets the data provider. Overrides ResourceInterface::getDataProvider 1
ResourceDecoratorBase::getDecoratedResource public function Gets the decorated resource. Overrides ResourceDecoratorInterface::getDecoratedResource
ResourceDecoratorBase::getFieldDefinitions public function Gets the field definitions. Overrides ResourceInterface::getFieldDefinitions 1
ResourceDecoratorBase::getPath public function Gets the path of the resource. Overrides ResourceInterface::getPath 1
ResourceDecoratorBase::getPluginDefinition public function This is a decorated resource, get proxy the request until you reach the annotated resource. 1
ResourceDecoratorBase::getPluginId public function
ResourceDecoratorBase::getPrimaryResource public function Gets the primary resource, the one that is not a decorator. Overrides ResourceDecoratorInterface::getPrimaryResource
ResourceDecoratorBase::getRequest public function Get the request object. Overrides ResourceInterface::getRequest
ResourceDecoratorBase::getResourceMachineName public function Gets the resource machine name. Overrides ResourceInterface::getResourceMachineName 1
ResourceDecoratorBase::getResourceName public function Gets the resource name. Overrides ResourceInterface::getResourceName
ResourceDecoratorBase::getUrl public function Helper method; Get the URL of the resource and query strings. Overrides ResourceInterface::getUrl
ResourceDecoratorBase::getVersion public function Return array keyed with the major and minor version of the resource. Overrides ResourceInterface::getVersion
ResourceDecoratorBase::index public function Basic implementation for listing. Overrides ResourceInterface::index 1
ResourceDecoratorBase::isEnabled public function Checks if the resource is enabled. Overrides ResourceInterface::isEnabled 1
ResourceDecoratorBase::isInstanceOf public function Checks if the decorated object is an instance of something. Overrides ExplorableDecoratorInterface::isInstanceOf
ResourceDecoratorBase::process public function Controller function that passes the data along and executes right action. Overrides ResourceInterface::process 2
ResourceDecoratorBase::remove public function Basic implementation for update. Overrides ResourceInterface::remove 1
ResourceDecoratorBase::replace public function Basic implementation for update. Overrides ResourceInterface::replace 1
ResourceDecoratorBase::setAccount public function Overrides ResourceInterface::setAccount 1
ResourceDecoratorBase::setConfiguration public function
ResourceDecoratorBase::setDataProvider public function Sets the data provider. Overrides ResourceInterface::setDataProvider 1
ResourceDecoratorBase::setFieldDefinitions public function Sets the field definitions. Overrides ResourceInterface::setFieldDefinitions
ResourceDecoratorBase::setPath public function Sets the path of the resource. Overrides ResourceInterface::setPath 1
ResourceDecoratorBase::setPluginDefinition public function This is a decorated resource, set proxy the request until you reach the annotated resource. Overrides ResourceInterface::setPluginDefinition
ResourceDecoratorBase::setRequest public function Sets the request object. Overrides ResourceInterface::setRequest
ResourceDecoratorBase::switchUserBack public function Switches the user back from the original user for the session. Overrides ResourceInterface::switchUserBack
ResourceDecoratorBase::update public function Basic implementation for update. Overrides ResourceInterface::update 1
ResourceDecoratorBase::versionedUrl public function Gets a resource URL based on the current version. Overrides ResourceInterface::versionedUrl
ResourceDecoratorBase::view public function Basic implementation for view. Overrides ResourceInterface::view 1
ResourceDecoratorBase::__call public function If any method not declared, then defer it to the decorated field.
ResourceInterface::IDS_SEPARATOR constant The string that separates multiple ids.