File tree Expand file tree Collapse file tree 9 files changed +83
-74
lines changed Expand file tree Collapse file tree 9 files changed +83
-74
lines changed Original file line number Diff line number Diff line change 2222
2323namespace Haeckel \JsonRpcServerContract \Message ;
2424
25- use Haeckel \JsonRpcServerContract \DataStruct \ CollectionIface ;
25+ use Haeckel \JsonRpcServerContract \{ DataStruct , Response } ;
2626
2727/**
28- * @extends CollectionIface<RequestIface|NotificationIface>
28+ * @extends DataStruct\ CollectionIface<RequestIface|NotificationIface>
2929 *
3030 * @link https://www.jsonrpc.org/specification#batch
3131 */
32- interface BatchRequestIface extends CollectionIface
32+ interface BatchRequestIface extends DataStruct \ CollectionIface
3333{
3434 /** @no-named-arguments */
3535 public function add (RequestIface |NotificationIface ...$ elements ): void ;
@@ -43,10 +43,10 @@ public function remove(RequestIface|NotificationIface ...$elements): void;
4343 * if any request of a batch is invalid or hast invalid json, add the error response here
4444 * @no-named-arguments
4545 */
46- public function addResponseForInvalidReq (ResponseIface ...$ response ): void ;
46+ public function addResponseForInvalidReq (Response \ ErrorIface ...$ response ): void ;
4747
4848 /**
49- * @return list<ResponseIface >
49+ * @return list<Response\ErrorIface >
5050 */
5151 public function getResponsesForInvalidRequests (): array ;
5252}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Haeckel \JsonRpcServerContract \Response ;
6+
7+ interface BaseIface extends \JsonSerializable
8+ {
9+ public function getId (): null |int |string ;
10+ public function withId (null |int |string $ id ): static ;
11+
12+ public function getJsonrpc (): string ;
13+ public function withJsonrpc (string $ jsonrpc ): static ;
14+ }
Original file line number Diff line number Diff line change 2020
2121declare (strict_types=1 );
2222
23- namespace Haeckel \JsonRpcServerContract \Message ;
23+ namespace Haeckel \JsonRpcServerContract \Response ;
2424
2525use Haeckel \JsonRpcServerContract \DataStruct \CollectionIface ;
2626
2727/**
28- * @extends CollectionIface<ResponseIface >
28+ * @extends CollectionIface<ErrorIface|SuccessIface >
2929 *
3030 * @link https://www.jsonrpc.org/specification#batch
3131 */
32- interface BatchResponseIface extends CollectionIface
32+ interface BatchIface extends CollectionIface
3333{
3434 /** @no-named-arguments */
35- public function add (ResponseIface ...$ elements ): void ;
35+ public function add (ErrorIface | SuccessIface ...$ elements ): void ;
3636
37- public function current (): ? ResponseIface ;
37+ public function current (): null | ErrorIface | SuccessIface ;
3838
3939 /** @no-named-arguments */
40- public function remove (ResponseIface ...$ elements ): void ;
40+ public function remove (ErrorIface | SuccessIface ...$ elements ): void ;
4141}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Haeckel \JsonRpcServerContract \Response ;
6+
7+ use Haeckel \JsonRpcServerContract \Message ;
8+
9+ interface ErrorIface extends BaseIface
10+ {
11+ public function getError (): null |Message \ErrorObjectIface ;
12+ public function withError (null |Message \ErrorObjectIface $ error ): static ;
13+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * This file is part of haeckel/json-rpc-server-contracts.
5+ *
6+ * haeckel/json-rpc-server-contracts is free software:
7+ * you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
8+ * as published by the Free Software Foundation, either version 3 of the License,
9+ * or (at your option) any later version.
10+ *
11+ * haeckel/json-rpc-server-contracts is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY;
13+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+ * See the GNU Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public License along with
17+ * haeckel/json-rpc-server-contracts.
18+ * If not, see <https://www.gnu.org/licenses/>.
19+ */
20+
21+ declare (strict_types=1 );
22+
23+ namespace Haeckel \JsonRpcServerContract \Response ;
24+
25+ /** @link https://www.jsonrpc.org/specification#response_object */
26+ interface SuccessIface extends BaseIface
27+ {
28+ /** @return array<mixed>|bool|float|int|string|\stdClass|\JsonSerializable */
29+ public function getResult (): array |bool |float |int |string |\stdClass |\JsonSerializable ;
30+
31+ /** @param array<mixed>|bool|float|int|string|\stdClass|\JsonSerializable $result */
32+ public function withResult (
33+ array |bool |float |int |string |\stdClass |\JsonSerializable $ result ,
34+ ): static ;
35+ }
Original file line number Diff line number Diff line change 2222
2323namespace Haeckel \JsonRpcServerContract \Server ;
2424
25- use Haeckel \JsonRpcServerContract \Message ;
25+ use Haeckel \JsonRpcServerContract \Response ;
2626
2727/** serialize the response and output it */
2828interface EmitterIface
2929{
30- /** @throws \Throwable */
31- public function emit (Message \ResponseIface |Message \BatchResponseIface $ response ): void ;
30+ public function emit (
31+ Response \BatchIface |Response \ErrorIface |Response \SuccessIface $ response ,
32+ ): void ;
3233}
Original file line number Diff line number Diff line change 2222
2323namespace Haeckel \JsonRpcServerContract \Server ;
2424
25- use Haeckel \JsonRpcServerContract \Message ;
25+ use Haeckel \JsonRpcServerContract \{ Message , Response } ;
2626
2727/**
2828 * can be used compose classes the offer general services,
@@ -33,5 +33,5 @@ interface MiddlewareIface
3333 public function process (
3434 Message \NotificationIface |Message \RequestIface $ request ,
3535 RequestHandlerIface |NotificationHandlerIface $ handler ,
36- ): ? Message \ ResponseIface ;
36+ ): null | Response \ ErrorIface | Response \ SuccessIface ;
3737}
Original file line number Diff line number Diff line change 2222
2323namespace Haeckel \JsonRpcServerContract \Server ;
2424
25- use Haeckel \JsonRpcServerContract \{Exception , Message };
25+ use Haeckel \JsonRpcServerContract \{Exception , Message , Response };
2626
2727interface RequestHandlerIface
2828{
29- /** @throws Exception\JsonRpcErrorIface */
30- public function handle (Message \RequestIface $ request ): Message \ResponseIface ;
29+ public function handle (
30+ Message \RequestIface $ request ,
31+ ): Response \ErrorIface |Response \SuccessIface ;
3132}
You can’t perform that action at this time.
0 commit comments