View source
<?php
namespace Drupal\restful\Plugin\resource\Decorators;
use Drupal\Component\Plugin\PluginBase;
use Drupal\restful\Exception\BadRequestException;
use Drupal\restful\Http\Request;
use Drupal\restful\Http\RequestInterface;
use Drupal\restful\Plugin\resource\DataProvider\DataProviderInterface;
use Drupal\restful\Plugin\resource\Field\ResourceFieldCollectionInterface;
use Drupal\restful\Plugin\resource\ResourceInterface;
use Drupal\restful\Util\ExplorableDecoratorInterface;
abstract class ResourceDecoratorBase extends PluginBase implements ResourceDecoratorInterface, ExplorableDecoratorInterface {
protected $subject;
public function getDecoratedResource() {
return $this->subject;
}
public function getPrimaryResource() {
$resource = $this
->getDecoratedResource();
while ($resource instanceof ResourceDecoratorInterface) {
$resource = $resource
->getDecoratedResource();
}
return $resource;
}
public function dataProviderFactory() {
return $this->subject
->dataProviderFactory();
}
public function getAccount($cache = TRUE) {
return $this->subject
->getAccount($cache);
}
public function setAccount($account) {
$this->subject
->setAccount($account);
$this
->getDataProvider()
->setAccount($account);
}
public function switchUserBack() {
$this->subject
->switchUserBack();
}
public function discover($path = NULL) {
return $this->subject
->discover($path);
}
public function getRequest() {
return $this->subject
->getRequest();
}
public function setRequest(RequestInterface $request) {
$this->subject
->setRequest($request);
$this
->getDataProvider()
->setRequest($request);
}
public function getPath() {
return $this->subject
->getPath();
}
public function setPath($path) {
$this->subject
->setPath($path);
}
public function getFieldDefinitions() {
return $this->subject
->getFieldDefinitions();
}
public function getDataProvider() {
return $this->subject
->getDataProvider();
}
public function setDataProvider(DataProviderInterface $data_provider = NULL) {
$this->subject
->setDataProvider($data_provider);
}
public function getResourceName() {
return $this->subject
->getResourceName();
}
public function process() {
return $this->subject
->process();
}
public function controllersInfo() {
return $this->subject
->controllersInfo();
}
public function getControllers() {
return $this->subject
->getControllers();
}
public function index($path) {
return $this->subject
->index($path);
}
public function view($path) {
return $this->subject
->view($path);
}
public function create($path) {
return $this->subject
->create($path);
}
public function update($path) {
return $this->subject
->update($path);
}
public function replace($path) {
return $this->subject
->replace($path);
}
public function remove($path) {
$this->subject
->remove($path);
}
public function getVersion() {
return $this->subject
->getVersion();
}
public function versionedUrl($path = '', $options = array(), $version_string = TRUE) {
return $this->subject
->versionedUrl($path, $options, $version_string);
}
public function getConfiguration() {
return $this->subject
->getConfiguration();
}
public function setConfiguration(array $configuration) {
$this->subject
->setConfiguration($configuration);
}
public function defaultConfiguration() {
return $this->subject
->defaultConfiguration();
}
public function calculateDependencies() {
return $this->subject
->calculateDependencies();
}
public function access() {
return $this->subject
->access();
}
public function getControllerFromPath($path = NULL, ResourceInterface $resource = NULL) {
return $this->subject
->getControllerFromPath($path, $resource ?: $this);
}
public function getResourceMachineName() {
return $this->subject
->getResourceMachineName();
}
public function getPluginDefinition() {
return $this->subject
->getPluginDefinition();
}
public function setPluginDefinition(array $plugin_definition) {
$this->subject
->setPluginDefinition($plugin_definition);
if (!empty($plugin_definition['dataProvider'])) {
$this
->getDataProvider()
->addOptions($plugin_definition['dataProvider']);
}
}
public function enable() {
$this->subject
->enable();
}
public function disable() {
$this->subject
->disable();
}
public function isEnabled() {
return $this->subject
->isEnabled();
}
public function setFieldDefinitions(ResourceFieldCollectionInterface $field_definitions) {
return $this->subject
->setFieldDefinitions($field_definitions);
}
public function getUrl(array $options = array(), $keep_query = TRUE, RequestInterface $request = NULL) {
return $this->subject
->getUrl($options, $keep_query, $request);
}
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();
}
public function doPost(array $parsed_body) {
return $this
->doWrite(RequestInterface::METHOD_POST, '', $parsed_body);
}
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);
}
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);
}
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();
}
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();
}
public function getPluginId() {
return $this->subject
->getPluginId();
}
public function isInstanceOf($class) {
if ($this instanceof $class || $this->subject instanceof $class) {
return TRUE;
}
if ($this->subject instanceof ExplorableDecoratorInterface) {
return $this->subject
->isInstanceOf($class);
}
return FALSE;
}
public function __call($name, $arguments) {
return call_user_func_array(array(
$this->subject,
$name,
), $arguments);
}
}