Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: srjlewis/JsonRPC
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0
Choose a base ref
...
head repository: srjlewis/JsonRPC
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 20 commits
  • 24 files changed
  • 2 contributors

Commits on Dec 13, 2019

  1. Copy the full SHA
    e46f2d3 View commit details

Commits on May 29, 2020

  1. Copy the full SHA
    2257d8a View commit details

Commits on May 30, 2020

  1. Add better debug logging

    srjlewis committed May 30, 2020
    Copy the full SHA
    845b85d View commit details
  2. Add better debug logging

    srjlewis committed May 30, 2020
    Copy the full SHA
    7d2db56 View commit details
  3. Copy the full SHA
    30bbdf7 View commit details
  4. Copy the full SHA
    c2c720a View commit details
  5. Copy the full SHA
    d4febb5 View commit details

Commits on Jul 15, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7c9a962 View commit details

Commits on Nov 3, 2021

  1. Copy the full SHA
    9d1f248 View commit details

Commits on Nov 17, 2021

  1. Copy the full SHA
    f21b843 View commit details

Commits on Oct 10, 2024

  1. Copy the full SHA
    47da3ff View commit details
  2. Copy the full SHA
    90a8f44 View commit details

Commits on Oct 31, 2024

  1. Copy the full SHA
    367d798 View commit details
  2. Copy the full SHA
    7a20113 View commit details
  3. Copy the full SHA
    db498ad View commit details
  4. Copy the full SHA
    4bdad0e View commit details

Commits on Nov 1, 2024

  1. Copy the full SHA
    18b811f View commit details
  2. Copy the full SHA
    78154bf View commit details
  3. Copy the full SHA
    25c668a View commit details
  4. Copy the full SHA
    825e926 View commit details
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ Features
- Authentication and IP based client restrictions
- Custom Middleware
- Fully unit tested
- Requirements: PHP >= 5.3.4
- Requirements: PHP >= 8.0
- License: MIT

Author
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -16,13 +16,14 @@
"fguillot/json-rpc": "1.*"
},
"require": {
"php": ">=7.1",
"ext-json": "*"
"php": ">=8.0",
"ext-json": "*",
"psr/log": "^2.0 || ^3.0"
},
"autoload": {
"psr-0": {"JsonRPC": "src/"}
},
"require-dev": {
"phpunit/phpunit": "^7"
"phpunit/phpunit": "^9 || ^10.0 || ^11.0"
}
}
86 changes: 51 additions & 35 deletions src/JsonRPC/Client.php
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
use Exception;
use JsonRPC\Request\RequestBuilder;
use JsonRPC\Response\ResponseParser;
use JsonRPC\Response\ResponseParserInterface;

/**
* JsonRPC client class
@@ -18,55 +19,66 @@ class Client
* If the only argument passed to a function is an array
* assume it contains named arguments
*
* @access private
* @access protected
* @var boolean
*/
private $isNamedArguments = true;
protected $isNamedArguments = true;

/**
* Do not immediately throw an exception on error. Return it instead.
*
* @access public
* @var boolean
*/
private $returnException = false;
protected $returnException = false;

/**
* True for a batch request
*
* @access private
* @access protected
* @var boolean
*/
private $isBatch = false;
protected $isBatch = false;

/**
* Batch payload
*
* @access private
* @access protected
* @var array
*/
private $batch = array();
protected $batch = array();

/**
* Http Client
*
* @access private
* @access protected
* @var HttpClient
*/
private $httpClient;
protected $httpClient;

/**
* @var Response\ResponseParserInterface
*/
protected $responseParser;

/**
* Constructor
*
* @access public
* @param string $url Server URL
* @param bool $returnException Return exceptions
* @param HttpClient $httpClient HTTP client object
* @param string $url Server URL
* @param bool $returnException Return exceptions
* @param HttpClient|null $httpClient HTTP client object
* @param ResponseParserInterface|null $responseParser
*/
public function __construct($url = '', $returnException = false, HttpClient $httpClient = null)
{
public function __construct(
$url = '',
$returnException = false,
?HttpClient $httpClient = null,
?ResponseParserInterface $responseParser = null
) {
$this->httpClient = $httpClient ?: new HttpClient($url);
$this->returnException = $returnException;
$this->responseParser = $responseParser ?: ResponseParser::create();
}

/**
@@ -96,8 +108,8 @@ public function getHttpClient()
* Set username and password
*
* @access public
* @param string $username
* @param string $password
* @param string $username
* @param string $password
* @return $this
*/
public function authentication($username, $password)
@@ -113,8 +125,8 @@ public function authentication($username, $password)
* Automatic mapping of procedures
*
* @access public
* @param string $method Procedure name
* @param array $params Procedure arguments
* @param string $method Procedure name
* @param array $params Procedure arguments
* @return mixed
*/
public function __call($method, array $params)
@@ -135,7 +147,7 @@ public function __call($method, array $params)
public function batch()
{
$this->isBatch = true;
$this->batch = array();
$this->batch = array();
return $this;
}

@@ -148,22 +160,27 @@ public function batch()
public function send()
{
$this->isBatch = false;
return $this->sendPayload('['.implode(', ', $this->batch).']');
return $this->sendPayload('[' . implode(', ', $this->batch) . ']');
}

/**
* Execute a procedure
*
* @access public
* @param string $procedure Procedure name
* @param array $params Procedure arguments
* @param array $reqattrs
* @param string|null $requestId Request Id
* @param string[] $headers Headers for this request
* @param string $procedure Procedure name
* @param array $params Procedure arguments
* @param array $reqattrs
* @param string|null $requestId Request Id
* @param string[] $headers Headers for this request
* @return mixed
*/
public function execute($procedure, array $params = array(), array $reqattrs = array(), $requestId = null, array $headers = array())
{
public function execute(
$procedure,
array $params = array(),
array $reqattrs = array(),
$requestId = null,
array $headers = array()
) {
$payload = RequestBuilder::create()
->withProcedure($procedure)
->withParams($params)
@@ -182,17 +199,16 @@ public function execute($procedure, array $params = array(), array $reqattrs = a
/**
* Send payload
*
* @access private
* @access protected
* @param string $payload
* @param string[] $headers
* @return Exception|array
* @throws Exception
* @param string $payload
* @param string[] $headers
* @return Exception|Client
*/
private function sendPayload($payload, array $headers = array())
protected function sendPayload($payload, array $headers = array())
{
return ResponseParser::create()
return $this->responseParser
->withReturnException($this->returnException)
->withPayload($this->httpClient->execute($payload, $headers))
->parse();
->parse($this->httpClient->execute($payload, $headers));
}
}
2 changes: 1 addition & 1 deletion src/JsonRPC/Exception/ResponseException.php
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ class ResponseException extends RpcCallFailedException
* @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0
* @param mixed $data [optional] A value that contains additional information about the error.
*/
public function __construct($message = '', $code = 0, Exception $previous = null, $data = null)
public function __construct($message = '', $code = 0, ?Exception $previous = null, $data = null)
{
parent::__construct($message, $code, $previous);
$this->setData($data);
Loading