diff options
author | Frédéric Guillot <fred@kanboard.net> | 2018-06-21 14:13:41 -0700 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2018-06-21 14:13:41 -0700 |
commit | a491348d442ab8e6cd2fa403d4365cdad78e52ce (patch) | |
tree | a00f575d82afb2c9051bad95398b4250f4a3d44d /vendor/fguillot/json-rpc/src/JsonRPC/Request/RequestParser.php | |
parent | c73ac5f1f818b6b21083f6785b4b2f6d778a6496 (diff) |
Vendoring deprecated composer libs
Diffstat (limited to 'vendor/fguillot/json-rpc/src/JsonRPC/Request/RequestParser.php')
-rw-r--r-- | vendor/fguillot/json-rpc/src/JsonRPC/Request/RequestParser.php | 200 |
1 files changed, 0 insertions, 200 deletions
diff --git a/vendor/fguillot/json-rpc/src/JsonRPC/Request/RequestParser.php b/vendor/fguillot/json-rpc/src/JsonRPC/Request/RequestParser.php deleted file mode 100644 index ea1b7d43..00000000 --- a/vendor/fguillot/json-rpc/src/JsonRPC/Request/RequestParser.php +++ /dev/null @@ -1,200 +0,0 @@ -<?php - -namespace JsonRPC\Request; - -use Exception; -use JsonRPC\Exception\AccessDeniedException; -use JsonRPC\Exception\AuthenticationFailureException; -use JsonRPC\Exception\InvalidJsonRpcFormatException; -use JsonRPC\MiddlewareHandler; -use JsonRPC\ProcedureHandler; -use JsonRPC\Response\ResponseBuilder; -use JsonRPC\Validator\JsonFormatValidator; -use JsonRPC\Validator\RpcFormatValidator; - -/** - * Class RequestParser - * - * @package JsonRPC - * @author Frederic Guillot - */ -class RequestParser -{ - /** - * Request payload - * - * @access protected - * @var mixed - */ - protected $payload; - - /** - * List of exceptions that should not be relayed to the client - * - * @access protected - * @var array() - */ - protected $localExceptions = array( - 'JsonRPC\Exception\AuthenticationFailureException', - 'JsonRPC\Exception\AccessDeniedException', - ); - - /** - * ProcedureHandler - * - * @access protected - * @var ProcedureHandler - */ - protected $procedureHandler; - - /** - * MiddlewareHandler - * - * @access protected - * @var MiddlewareHandler - */ - protected $middlewareHandler; - - /** - * Get new object instance - * - * @static - * @access public - * @return RequestParser - */ - public static function create() - { - return new static(); - } - - /** - * Set payload - * - * @access public - * @param mixed $payload - * @return $this - */ - public function withPayload($payload) - { - $this->payload = $payload; - return $this; - } - - /** - * Exception classes that should not be relayed to the client - * - * @access public - * @param mixed $exception - * @return $this - */ - public function withLocalException($exception) - { - if (is_array($exception)) { - $this->localExceptions = array_merge($this->localExceptions, $exception); - } else { - $this->localExceptions[] = $exception; - } - - return $this; - } - - /** - * Set procedure handler - * - * @access public - * @param ProcedureHandler $procedureHandler - * @return $this - */ - public function withProcedureHandler(ProcedureHandler $procedureHandler) - { - $this->procedureHandler = $procedureHandler; - return $this; - } - - /** - * Set middleware handler - * - * @access public - * @param MiddlewareHandler $middlewareHandler - * @return $this - */ - public function withMiddlewareHandler(MiddlewareHandler $middlewareHandler) - { - $this->middlewareHandler = $middlewareHandler; - return $this; - } - - /** - * Parse incoming request - * - * @access public - * @return string - * @throws AccessDeniedException - * @throws AuthenticationFailureException - */ - public function parse() - { - try { - - JsonFormatValidator::validate($this->payload); - RpcFormatValidator::validate($this->payload); - - $this->middlewareHandler - ->withProcedure($this->payload['method']) - ->execute(); - - $result = $this->procedureHandler->executeProcedure( - $this->payload['method'], - empty($this->payload['params']) ? array() : $this->payload['params'] - ); - - if (! $this->isNotification()) { - return ResponseBuilder::create() - ->withId($this->payload['id']) - ->withResult($result) - ->build(); - } - } catch (Exception $e) { - return $this->handleExceptions($e); - } - - return ''; - } - - /** - * Handle exceptions - * - * @access protected - * @param Exception $e - * @return string - * @throws Exception - */ - protected function handleExceptions(Exception $e) - { - foreach ($this->localExceptions as $exception) { - if ($e instanceof $exception) { - throw $e; - } - } - - if ($e instanceof InvalidJsonRpcFormatException || ! $this->isNotification()) { - return ResponseBuilder::create() - ->withId(isset($this->payload['id']) ? $this->payload['id'] : null) - ->withException($e) - ->build(); - } - - return ''; - } - - /** - * Return true if the message is a notification - * - * @access protected - * @return bool - */ - protected function isNotification() - { - return is_array($this->payload) && !isset($this->payload['id']); - } -} |