laminas / laminas-json-server Goto Github PK
View Code? Open in Web Editor NEWLaminas Json-Server is a JSON-RPC server implementation.
Home Page: https://docs.laminas.dev/laminas-json-server/
License: BSD 3-Clause "New" or "Revised" License
Laminas Json-Server is a JSON-RPC server implementation.
Home Page: https://docs.laminas.dev/laminas-json-server/
License: BSD 3-Clause "New" or "Revised" License
Q | A |
---|---|
New Feature | yes |
To be prepared for the december release of PHP 8.0, this repository has some additional TODOs to be tested against the new major version.
In order to make this repository compatible, one has to follow these steps:
composer.json
to provide support for PHP 8.0 by adding the constraint ~8.0.0
composer.json
to drop support for PHP less than 7.3composer.json
to implement phpunit 9.3 which supports PHP 7.3+.travis.yml
to ignore platform requirements when installing composer dependencies (simply add --ignore-platform-reqs
to COMPOSER_ARGS
env variable).travis.yml
to add PHP 8.0 to the matrix (NOTE: Do not allow failures as PHP 8.0 has a feature freeze since 2020-08-04!)The Service Mapping Description (SMD) detects wrong return values under certain (unclear) circumstances.
Q | A |
---|---|
PHP | 7.4 |
laminas/laminas-json-server | 3.3 |
The return value types are kind of multiplied (see below).
I have the following Dummy class, which describes return values via phpdoc as follows.
<?php
declare(strict_types=1);
/**
* Dummy
*/
class Dummy
{
/**
* Method a
*
* @param int $x
* @param float $y
* @return array
*/
public function a(int $x, float $y): array
{
return ['a'];
}
/**
* Method b
*
* @param int|float $x
* @param string $y
* @param int|float $z
* @return object
*/
public function b($x, $y, $z = 0.0): object
{
return (object)['name' => 'b'];
}
/**
* Method c
*
* @param int $x
* @param int $y
* @param int $z
* @return array
*/
public function c(int $x, int $y = 0, int $z = 0): array
{
return ['name' => 'c'];
}
/**
* Method d
*
* @param int|float $x
* @param float $y
* @return array
*/
public function d(int $x, float $y): array
{
return ['d'];
}
}
The auto-generated Service Mapping Description (SMD) looks like follows.
{
"transport": "POST",
"envelope": "JSON-RPC-2.0",
"contentType": "application\/json",
"SMDVersion": "2.0",
"services": {
"dummy.a": {
"envelope": "JSON-RPC-2.0",
"transport": "POST",
"name": "dummy.a",
"parameters": [
{
"type": "integer",
"name": "x",
"optional": false
},
{
"type": "float",
"name": "y",
"optional": false
}
],
"returns": "array"
},
"dummy.b": {
"envelope": "JSON-RPC-2.0",
"transport": "POST",
"name": "dummy.b",
"parameters": [
{
"type": [
"integer",
"float"
],
"name": "x",
"optional": false
},
{
"type": "string",
"name": "y",
"optional": false
},
{
"type": [
"integer",
"float"
],
"name": "z",
"optional": true,
"default": 0
}
],
"returns": [
"object",
"object",
"object",
"object",
"object",
"object"
]
},
"dummy.c": {
"envelope": "JSON-RPC-2.0",
"transport": "POST",
"name": "dummy.c",
"parameters": [
{
"type": "integer",
"name": "x",
"optional": false
},
{
"type": "integer",
"name": "y",
"optional": true,
"default": 0
},
{
"type": "integer",
"name": "z",
"optional": true,
"default": 0
}
],
"returns": [
"array",
"array",
"array"
]
},
"dummy.d": {
"envelope": "JSON-RPC-2.0",
"transport": "POST",
"name": "dummy.d",
"parameters": [
{
"type": [
"integer",
"float"
],
"name": "x",
"optional": false
},
{
"type": "float",
"name": "y",
"optional": false
}
],
"returns": [
"array",
"array"
]
}
},
"methods": {
"dummy.a": {
"envelope": "JSON-RPC-2.0",
"transport": "POST",
"name": "dummy.a",
"parameters": [
{
"type": "integer",
"name": "x",
"optional": false
},
{
"type": "float",
"name": "y",
"optional": false
}
],
"returns": "array"
},
"dummy.b": {
"envelope": "JSON-RPC-2.0",
"transport": "POST",
"name": "dummy.b",
"parameters": [
{
"type": [
"integer",
"float"
],
"name": "x",
"optional": false
},
{
"type": "string",
"name": "y",
"optional": false
},
{
"type": [
"integer",
"float"
],
"name": "z",
"optional": true,
"default": 0
}
],
"returns": [
"object",
"object",
"object",
"object",
"object",
"object"
]
},
"dummy.c": {
"envelope": "JSON-RPC-2.0",
"transport": "POST",
"name": "dummy.c",
"parameters": [
{
"type": "integer",
"name": "x",
"optional": false
},
{
"type": "integer",
"name": "y",
"optional": true,
"default": 0
},
{
"type": "integer",
"name": "z",
"optional": true,
"default": 0
}
],
"returns": [
"array",
"array",
"array"
]
},
"dummy.d": {
"envelope": "JSON-RPC-2.0",
"transport": "POST",
"name": "dummy.d",
"parameters": [
{
"type": [
"integer",
"float"
],
"name": "x",
"optional": false
},
{
"type": "float",
"name": "y",
"optional": false
}
],
"returns": [
"array",
"array"
]
}
}
}
The return values seems to be multiplied. It looks like there is a relation to the params.
Method | Return | Conclusion |
---|---|---|
dummy.a | array | Ok |
dummy.b | array of 6 objects | strange, why 6 objects? |
dummy.c | array of 3 arrays | strange, why 3 arrays? |
dummy.d | array of 2 arrays | strange, why 2 arrays? |
The return values should not be multiplied.
This issue has been moved from the zendframework
repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html
Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7544
User: @dreadnought78
Created On: 2015-05-23T22:04:16Z
Updated At: 2015-11-06T23:57:01Z
Body
If the user forgot or send some required parameter with a wrong name the server returns the error ERROR_INVALID_PARAMS.
This request added a invalid parameters list in the json response.
Result before
{
"error":{
"code":-32602,
"message":"Invalid params",
"data":null
},
"id":"8",
"jsonrpc":"2.0"
}
Result after
{
"error":{
"code":-32602,
"message":"Invalid param(s): [estimatedMonths, location, specieId, coatTypeId]",
"data":null
},
"id":"8",
"jsonrpc":"2.0"
}
*Please do not consider this pull request if this implementation has not been made before for security reasons.
Originally posted by @GeeH at zendframework/zend-json#25
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are awaiting their schedule. Click on a checkbox to get an update now.
composer.json
php ^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0
laminas/laminas-http ^2.15.1
laminas/laminas-json ^3.3.0
laminas/laminas-server ^2.11.0
laminas/laminas-coding-standard ^2.4.0
phpunit/phpunit ^9.5.26
psalm/plugin-phpunit ^0.18.0
vimeo/psalm ^5.0.0
.github/workflows/continuous-integration.yml
.github/workflows/docs-build.yml
.github/workflows/release-on-milestone-closed.yml
Q | A |
---|---|
Documentation | no |
Bugfix | no |
BC Break | no |
New Feature | no |
RFC | no |
QA | yes |
In preparation of bringing this component in compliance with the JSON-RPC 2.0 specs, I would like to update this component to a currently supported PHP version including language features (strict types, type declarations).
@Xerkus suggested the following schedule. If possible, each point will be provided in a separate PR
to achieve green CI at each step and make reviews easier.
This issue serves as a task list and an overview of the progress.
This "project" will not introduce features, bugfixes or BC breaks. Necessary functionality changes will be handled separately afterwards.
EDIT:
List of additional changes required. Initially these points resulted from the code review in #3 and will be added on if required.
dev-4.0
Json::encode
& Json::decode
in favor of native json_encode
and json_decode
(add ext-json to composer.json)ExceptionInterface
should extend Throwable
laminas/laminas-coding-standard
2.0array
arguments more generic, probably iterable
(e.g. Smd::addServices(array $services)
)Smd::addService(Smd\Service $service)
drop array support and argument type check [BC]Server::getSmd()
Return should be changed to ?string
as you get a result or nothing.Cache::saveSmd()
Return should be void. Regardless of whether caching attempt was successful just carry on.Cache::deleteSmd()
Operation result is irrelevant for the consumer. Return nothing. :void
Client::__construct()
QA: rename $server
to $serverAddress
to better reflect its meaningServer::handle()
Not sure about the reason for false
instead of null
here ($request
parameter). This should be changed at some point i thinkServer::__call
Design: return null;
should be used when method is not : void
. A change to be done when static analysis tool introduced.Server::handleRequest()
QA: if (! $request->isMethodError() && '' === $request->getMethod()) {
Method error check block from below can be merged with this block:laminas-server
, update used version in here as well as update usages (method signatures).master
Smd::getDescription()
returns $description
instead of self
Q | A |
---|---|
QA | yes |
As decided during the Technical-Steering-Committee Meeting on August 3rd, 2020, Laminas wants to implement vimeo/psalm in all packages.
Implementing psalm is quite easy.
.psalm.xml.dist
in the project root$ composer require vimeo/psalm
$ vendor/bin/psalm --set-baseline=psalm-baseline.xml
static-analysis
with the command psalm --shepherd --stats
script:
in .travis.yml
: - if [[ $TEST_COVERAGE == 'true' ]]; then composer static-analysis ; fi
phpstan.neon.dist
, .travis.yml
entry, composer.json
require-dev
and scripts
)What is the reason, that the assertions of ClientTest::testLastRequestAndResponseAreSetAfterRpcMethodCall()
are commented out?
Could not find any hints in Git history (change was made prior to what is available in Git history).
Tests are green locally (PHP 7.2, Windows 10), if I re-active them.
laminas-json-server/test/ClientTest.php
Lines 86 to 87 in 8b21392
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.