summaryrefslogtreecommitdiff
path: root/libs/jsonrpc/src/JsonRPC/Validator/RpcFormatValidator.php
blob: f253a5a1c97eddaca71d233c9c98c935ca2c2e41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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');
        }
    }
}