summaryrefslogtreecommitdiff
path: root/server/vendor/php-opencloud/common/src/Common/Api/Operator.php
diff options
context:
space:
mode:
authorLoic GUEGAN <loic@Manzerbredes.home>2016-04-16 19:10:27 +0200
committerLoic GUEGAN <loic@Manzerbredes.home>2016-04-16 19:10:27 +0200
commita3ff4d243e2ac37d4516ae56ff86985eadc00eb8 (patch)
tree32e71c42855cc46d95d9c6b74ad2c145eb9ec7eb /server/vendor/php-opencloud/common/src/Common/Api/Operator.php
parent396c90f921c30de2d15d2ce52d5d1beabf8eb52d (diff)
parent31d2d0c158ad4daa3dde7a905f3c2e312c194f2e (diff)
Test
Diffstat (limited to 'server/vendor/php-opencloud/common/src/Common/Api/Operator.php')
-rwxr-xr-xserver/vendor/php-opencloud/common/src/Common/Api/Operator.php175
1 files changed, 0 insertions, 175 deletions
diff --git a/server/vendor/php-opencloud/common/src/Common/Api/Operator.php b/server/vendor/php-opencloud/common/src/Common/Api/Operator.php
deleted file mode 100755
index 5698779..0000000
--- a/server/vendor/php-opencloud/common/src/Common/Api/Operator.php
+++ /dev/null
@@ -1,175 +0,0 @@
-<?php declare(strict_types=1);
-
-namespace OpenCloud\Common\Api;
-
-use GuzzleHttp\Promise\PromiseInterface;
-use GuzzleHttp\Psr7\Uri;
-use function GuzzleHttp\uri_template;
-use GuzzleHttp\ClientInterface;
-use GuzzleHttp\Promise\Promise;
-use OpenCloud\Common\Resource\ResourceInterface;
-use OpenCloud\Common\Transport\RequestSerializer;
-use Psr\Http\Message\ResponseInterface;
-
-/**
- * {@inheritDoc}
- */
-abstract class Operator implements OperatorInterface
-{
- /** @var ClientInterface */
- protected $client;
-
- /** @var ApiInterface */
- protected $api;
-
- /**
- * {@inheritDoc}
- */
- public function __construct(ClientInterface $client, ApiInterface $api)
- {
- $this->client = $client;
- $this->api = $api;
- }
-
- /**
- * Magic method for dictating how objects are rendered when var_dump is called.
- * For the benefit of users, extremely verbose and heavy properties (such as HTTP clients) are
- * removed to provide easier access to normal state, such as resource attributes.
- *
- * @codeCoverageIgnore
- * @return array
- */
- public function __debugInfo()
- {
- $excludedVars = ['client', 'errorBuilder', 'api'];
-
- $output = [];
-
- foreach (get_object_vars($this) as $key => $val) {
- if (!in_array($key, $excludedVars)) {
- $output[$key] = $val;
- }
- }
-
- return $output;
- }
-
- /**
- * Retrieves a populated Operation according to the definition and values provided. A
- * HTTP client is also injected into the object to allow it to communicate with the remote API.
- *
- * @param array $definition The data that dictates how the operation works
- *
- * @return Operation
- */
- public function getOperation(array $definition): Operation
- {
- return new Operation($definition);
- }
-
- protected function sendRequest(Operation $operation, array $userValues = [], bool $async = false)
- {
- $operation->validate($userValues);
-
- $options = (new RequestSerializer)->serializeOptions($operation, $userValues);
- $method = $async ? 'requestAsync' : 'request';
- $uri = uri_template($operation->getPath(), $userValues);
-
- return $this->client->$method($operation->getMethod(), $uri, $options);
- }
-
- /**
- * {@inheritDoc}
- */
- public function execute(array $definition, array $userValues = []): ResponseInterface
- {
- return $this->sendRequest($this->getOperation($definition), $userValues);
- }
-
- /**
- * {@inheritDoc}
- */
- public function executeAsync(array $definition, array $userValues = []): PromiseInterface
- {
- return $this->sendRequest($this->getOperation($definition), $userValues, true);
- }
-
- /**
- * {@inheritDoc}
- */
- public function model(string $class, $data = null): ResourceInterface
- {
- $model = new $class($this->client, $this->api);
-
- // @codeCoverageIgnoreStart
- if (!$model instanceof ResourceInterface) {
- throw new \RuntimeException(sprintf('%s does not implement %s', $class, ResourceInterface::class));
- }
- // @codeCoverageIgnoreEnd
-
- if ($data instanceof ResponseInterface) {
- $model->populateFromResponse($data);
- } elseif (is_array($data)) {
- $model->populateFromArray($data);
- }
-
- return $model;
- }
-
- /**
- * Will create a new instance of this class with the current HTTP client and API injected in. This
- * is useful when enumerating over a collection since multiple copies of the same resource class
- * are needed.
- *
- * @return static
- */
- public function newInstance(): self
- {
- return new static($this->client, $this->api);
- }
-
- /**
- * @return \GuzzleHttp\Psr7\Uri:null
- */
- protected function getHttpBaseUrl()
- {
- return $this->client->getConfig('base_uri');
- }
-
- /**
- * Magic method which intercepts async calls, finds the sequential version, and wraps it in a
- * {@see Promise} object. In order for this to happen, the called methods need to be in the
- * following format: `createAsync`, where `create` is the sequential method being wrapped.
- *
- * @param $methodName The name of the method being invoked.
- * @param $args The arguments to be passed to the sequential method.
- *
- * @throws \RuntimeException If method does not exist
- *
- * @return Promise
- */
- public function __call($methodName, $args)
- {
- $e = function ($name) {
- return new \RuntimeException(sprintf('%s::%s is not defined', get_class($this), $name));
- };
-
- if (substr($methodName, -5) === 'Async') {
- $realMethod = substr($methodName, 0, -5);
- if (!method_exists($this, $realMethod)) {
- throw $e($realMethod);
- }
-
- $promise = new Promise(
- function () use (&$promise, $realMethod, $args) {
- $value = call_user_func_array([$this, $realMethod], $args);
- $promise->resolve($value);
- }
- );
-
- return $promise;
- }
-
- throw $e($methodName);
- }
-}