Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ jobs:
composer config repositories.server '{"type":"path","url":"../server","options":{"symlink":false}}' --json
if [ "${{ matrix.scenario }}" = 'both' ]
then
composer require php-skir/server:dev-main php-skir/client:dev-main --no-interaction --no-progress
composer require "php-skir/server:*@dev" "php-skir/client:*@dev" --no-interaction --no-progress
else
composer require php-skir/server:dev-main --no-interaction --no-progress
composer require "php-skir/server:*@dev" --no-interaction --no-progress
fi
composer require laravel/boost:^2.4 --dev --no-interaction --no-progress
test ! -L vendor/php-skir/server
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SkirRPC offers many of the same benefits as gRPC—shared method definitions, ge
- Route procedures to attributed or invokable Laravel controllers with native dependency injection, middleware, authorization, and Form Requests. See [Routing](docs/routing.md).
- Keep generated providers and manual handlers available for non-controller layouts. See [Routing](docs/routing.md#generated-procedure-providers).
- Inspect an endpoint's procedures through its opt-in Studio. See [Studio](docs/routing.md#studio).
- Configure dense JSON, standard JSON, base64 dense JSON, or CBOR package-wide or per endpoint. See [Codecs](docs/codecs.md).
- Configure dense JSON, standard JSON, or base64 dense JSON package-wide or per endpoint. See [Codecs](docs/codecs.md).

## Quick start

Expand Down
12 changes: 4 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
"php": "^8.4",
"laravel/framework": "^13.0",
"nikic/php-parser": "^5.8",
"php-skir/runtime": "^0.1@dev",
"php-skir/runtime": "^0.1@dev|^0.2@dev",
"symfony/process": "^7.4|^8.0"
},
"require-dev": {
"laravel/pint": "^1.29",
"orchestra/testbench": "^11.0",
"php-skir/client": "^0.1@dev",
"phpunit/phpunit": "^12.5",
"spomky-labs/cbor-php": "^3.2"
"php-skir/client": "^0.1@dev|^0.2@dev",
"phpunit/phpunit": "^12.5"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -68,16 +67,13 @@
]
},
"branch-alias": {
"dev-main": "0.1.x-dev"
"dev-main": "0.2.x-dev"
}
},
"scripts": {
"format": "pint",
"test": "phpunit"
},
"suggest": {
"spomky-labs/cbor-php": "Required when using SkirCodecs::cbor() for application/cbor endpoints."
},
"config": {
"sort-packages": true
},
Expand Down
22 changes: 1 addition & 21 deletions docs/codecs.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ return [
];
```

The codec class is resolved through Laravel's container and must implement `Skir\Server\Codecs\SkirCodec`. The built-in codec classes are `DenseJsonCodec`, `StandardJsonCodec`, `Base64DenseJsonCodec`, and `CborCodec`, all in the `Skir\Server\Codecs` namespace. An explicit codec passed as the third argument to `Route::skirRpc()` overrides the configured default for that route.
The codec class is resolved through Laravel's container and must implement `Skir\Server\Codecs\SkirCodec`. The built-in codec classes are `DenseJsonCodec`, `StandardJsonCodec`, and `Base64DenseJsonCodec`, all in the `Skir\Server\Codecs` namespace. An explicit codec passed as the third argument to `Route::skirRpc()` overrides the configured default for that route.

## Dense JSON

Expand Down Expand Up @@ -71,23 +71,3 @@ Route::skirRpc('/api/skir-base64', [
```

The outer SkirRPC envelope remains JSON; only the request and response values are represented as base64-encoded dense JSON.

## CBOR

CBOR accepts an `application/cbor` request body containing the SkirRPC `method` and dense `request` values, then returns an `application/cbor` response body:

```php
use Skir\Server\Codecs\SkirCodecs;

Route::skirRpc('/api/skir-cbor', [
Skir::controller(UserController::class),
], SkirCodecs::cbor());
```

CBOR support is optional. Install its runtime dependency in the consuming Laravel application before selecting this codec:

```bash
composer require spomky-labs/cbor-php
```

Calling `SkirCodecs::cbor()` without the dependency throws a `SkirServerException` while the route is being built.
3 changes: 1 addition & 2 deletions resources/boost/guidelines/core.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
`authorize()` and `rules()`; scaffolded Form Requests deny access and validate nothing by default.

Method middleware does not protect Studio. Put middleware on the outer Skir route when Studio or the
complete endpoint must be private. Keep the server codec aligned with clients, and treat CBOR as
serialization rather than security.
complete endpoint must be private. Keep the server codec aligned with clients.

Use the `skir-server-development` skill for procedure routing, scaffolding, Studio, codec, or testing
work.
2 changes: 1 addition & 1 deletion resources/boost/skills/skir-server-development/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ boundaries.
- Choosing or implementing generated standard PHP objects, Spatie Laravel Data objects, or Simple
Data Objects—including input hydration and validation: read
[structures and validation](references/structures-and-validation.md).
- Studio exposure, codecs, CBOR, failures, or test coverage: read
- Studio exposure, codecs, failures, or test coverage: read
[Studio, codecs, and testing](references/studio-codecs-and-testing.md).
- Tasks crossing these areas: read every relevant reference before changing code.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ method invocation.
The configured `codec` must implement `SkirCodec`. Laravel resolves the class through the container;
an explicit third argument to `Route::skirRpc()` overrides the package default for that route.

Built-in implementations are `DenseJsonCodec`, `StandardJsonCodec`, `Base64DenseJsonCodec`, and
`CborCodec`. The matching factories are available through `SkirCodecs`. Clients and servers must use
Built-in implementations are `DenseJsonCodec`, `StandardJsonCodec`, and `Base64DenseJsonCodec`.
The matching factories are available through `SkirCodecs`. Clients and servers must use
the same codec.

CBOR uses `application/cbor` and requires `spomky-labs/cbor-php`. It is binary serialization, not
privacy or encryption. Selecting it without the optional dependency fails while the route is built.

## Required behavior coverage

Use PHPUnit feature tests at the Laravel boundary and never call a real external service. Cover the
Expand All @@ -38,15 +35,15 @@ paths applicable to the change:
- authorization HTTP 403 with `skir_authorization_failed`;
- unauthenticated and unauthorized method calls;
- protected and intentionally public Studio behavior;
- malformed JSON, malformed CBOR, missing method, unknown method, and invalid payload envelopes;
- malformed JSON, missing method, unknown method, and invalid payload envelopes;
- duplicate method registration from controllers, providers, or manual handlers;
- configured and route-specific codec success plus invalid codec configuration;
- controller middleware ordering, short-circuit responses, and the terminable middleware rejection;
- regressions for explicit `null`, boundary request shapes, and any corrected failure contract.

Assert status, Skir error code/details, response content type/body, authorization boundary, and side
effects. For Studio, assert both rendered procedure metadata and protection on the outer route. For
codec changes, use genuine encoded request/response bodies rather than treating JSON and CBOR as
codec changes, use genuine encoded request/response bodies rather than treating codecs as
interchangeable.

When a test fails, first identify whether the mismatch belongs to route protection, method
Expand Down
31 changes: 0 additions & 31 deletions src/Codecs/CborCodec.php

This file was deleted.

12 changes: 0 additions & 12 deletions src/Codecs/SkirCodecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,8 @@

namespace Skir\Server\Codecs;

use Skir\Runtime\Cbor;
use Skir\Server\Exceptions\SkirServerException;

final class SkirCodecs
{
public static function cbor(): SkirCodec
{
if (! Cbor::available()) {
throw SkirServerException::missingCborDependency();
}

return new CborCodec;
}

public static function denseJson(): SkirCodec
{
return new DenseJsonCodec;
Expand Down
18 changes: 0 additions & 18 deletions src/Codecs/SkirHttpCodec.php

This file was deleted.

9 changes: 0 additions & 9 deletions src/Exceptions/SkirServerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@ public static function invalidRouteProvider(mixed $provider): self
);
}

public static function missingCborDependency(): self
{
return new self(
'Skir CBOR support requires the [spomky-labs/cbor-php] Composer package.',
'skir_missing_cbor_dependency',
500,
);
}

/** @param array<string, array<int, string>> $errors */
public static function validationFailed(array $errors): self
{
Expand Down
14 changes: 2 additions & 12 deletions src/Http/Controllers/SkirRpcController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use JsonException;
use Skir\Runtime\Exceptions\SkirRuntimeException;
use Skir\Server\Codecs\SkirCodec;
use Skir\Server\Codecs\SkirHttpCodec;
use Skir\Server\Exceptions\SkirServerException;
use Skir\Server\Http\Requests\SkirMethodRequestScope;
use Skir\Server\PreparedProcedure;
Expand Down Expand Up @@ -49,7 +48,7 @@ public function __invoke(Request $request): Response
}

$codec = $server->codec();
$payload = $this->payloadFromRequest($request, $codec);
$payload = $this->payloadFromRequest($request);
$method = $this->methodFromPayload($payload);
$procedure = $server->procedure($method);
$requestPayload = array_key_exists('request', $payload) ? $payload['request'] : 0;
Expand Down Expand Up @@ -100,11 +99,6 @@ private function encodeResponse(
): Response {
$encodedResponse = $codec->encodeResponse($procedure->descriptor, $result);

if ($codec instanceof SkirHttpCodec) {
return response($encodedResponse, Response::HTTP_OK)
->header('content-type', $codec->contentType());
}

return response()->json($encodedResponse, Response::HTTP_OK);
}

Expand Down Expand Up @@ -153,16 +147,12 @@ private function studioEnabled(Request $request): bool
* request?: mixed
* }
*/
private function payloadFromRequest(Request $request, SkirCodec $codec): array
private function payloadFromRequest(Request $request): array
{
if ($this->usesQueryString($request)) {
return $this->payloadFromQueryString($request);
}

if ($codec instanceof SkirHttpCodec) {
return $codec->decodePayload($request->getContent());
}

try {
$decodedPayload = json_decode($request->getContent(), flags: JSON_THROW_ON_ERROR);
} catch (JsonException $exception) {
Expand Down
4 changes: 0 additions & 4 deletions tests/Feature/BoostAssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public function it_keeps_server_guidance_anchored_to_the_released_package(): voi
'DenseJsonCodec',
'StandardJsonCodec',
'Base64DenseJsonCodec',
'CborCodec',
'skir_validation_failed',
'skir_authorization_failed',
'malformed',
Expand All @@ -156,14 +155,11 @@ public function it_keeps_server_guidance_portable_and_non_executable(): void
'make composer',
'make npm',
'make test',
'CBOR encrypts',
'CBOR is secure',
'edit generated',
] as $forbiddenGuidance) {
$this->assertStringNotContainsStringIgnoringCase($forbiddenGuidance, $guidance);
}

$this->assertStringContainsString('serialization', $guidance);
$this->assertStringContainsString('Do not edit', $guidance);
$this->assertSame(
[self::GUIDELINE, self::SKILL, ...self::REFERENCES],
Expand Down
3 changes: 0 additions & 3 deletions tests/Feature/ClientServerCodecContractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public static function codecs(): iterable
yield 'dense JSON' => ['dense-json'];
yield 'standard JSON' => ['standard-json'];
yield 'base64 dense JSON' => ['base64-dense-json'];
yield 'CBOR' => ['cbor'];
}

private function clientCodec(string $codecName): SkirClientCodec
Expand All @@ -82,7 +81,6 @@ private function clientCodec(string $codecName): SkirClientCodec
'dense-json' => SkirClientCodecs::denseJson(),
'standard-json' => SkirClientCodecs::standardJson(),
'base64-dense-json' => SkirClientCodecs::base64DenseJson(),
'cbor' => SkirClientCodecs::cbor(),
};
}

Expand All @@ -92,7 +90,6 @@ private function serverCodec(string $codecName): SkirCodec
'dense-json' => SkirCodecs::denseJson(),
'standard-json' => SkirCodecs::standardJson(),
'base64-dense-json' => SkirCodecs::base64DenseJson(),
'cbor' => SkirCodecs::cbor(),
};
}

Expand Down
Loading
Loading