summaryrefslogtreecommitdiff
path: root/libs/jsonrpc/src/JsonRPC/Validator/RpcFormatValidator.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2018-06-21 14:13:41 -0700
committerFrédéric Guillot <fred@kanboard.net>2018-06-21 14:13:41 -0700
commita491348d442ab8e6cd2fa403d4365cdad78e52ce (patch)
treea00f575d82afb2c9051bad95398b4250f4a3d44d /libs/jsonrpc/src/JsonRPC/Validator/RpcFormatValidator.php
parentc73ac5f1f818b6b21083f6785b4b2f6d778a6496 (diff)
Vendoring deprecated composer libs
Diffstat (limited to 'libs/jsonrpc/src/JsonRPC/Validator/RpcFormatValidator.php')
-rw-r--r--libs/jsonrpc/src/JsonRPC/Validator/RpcFormatValidator.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/libs/jsonrpc/src/JsonRPC/Validator/RpcFormatValidator.php b/libs/jsonrpc/src/JsonRPC/Validator/RpcFormatValidator.php
new file mode 100644
index 00000000..f253a5a1
--- /dev/null
+++ b/libs/jsonrpc/src/JsonRPC/Validator/RpcFormatValidator.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace JsonRPC\Validator;
+
+use JsonRPC\Exception\InvalidJsonRpcFormatException;
+
+/**
+ * Class RpcFormatValidator
+ *
+ * @package JsonRPC\Validator
+ * @author Frederic Guillot
+ */
+class RpcFormatValidator
+{
+ /**
+ * Validate
+ *
+ * @static
+ * @access public
+ * @param array $payload
+ * @throws InvalidJsonRpcFormatException
+ */
+ public static function validate(array $payload)
+ {
+ if (! isset($payload['jsonrpc']) ||
+ ! isset($payload['method']) ||
+ ! is_string($payload['method']) ||
+ $payload['jsonrpc'] !== '2.0' ||
+ (isset($payload['params']) && ! is_array($payload['params']))) {
+
+ throw new InvalidJsonRpcFormatException('Invalid JSON RPC payload');
+ }
+ }
+}
+