定制 php-skir/client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

php-skir/client

Composer 安装命令:

composer require php-skir/client

包简介

Laravel SkirRPC client package powered by Saloon.

README 文档

README

Laravel package for consuming SkirRPC services with Saloon.

Installation

composer require php-skir/client

Publish the config if you want Laravel container resolution:

php artisan vendor:publish --tag=skir-client-config
SKIR_CLIENT_BASE_URL=https://example.com/api/skir
SKIR_CLIENT_ENDPOINT=/
SKIR_CLIENT_CODEC=dense_json

Usage

Use generated MethodDescriptor objects from skir-php-generator or skir-laravel-data-generator:

use App\Skir\Admin\SkirMethods;
use Skir\Client\SkirClient;

$client = new SkirClient('https://example.com/api/skir');

$user = $client->invoke(
    SkirMethods::getUser(),
    [
        'id' => 42,
        'name' => 'Maxim',
    ],
);

In Laravel, resolve the configured client from the container:

$user = app(SkirClient::class)->invoke(SkirMethods::getUser(), $payload);

Generated typed client adapters wrap this lower-level transport:

use App\Skir\Admin\GetUserRequestData;
use App\Skir\Admin\SkirRpcClient;
use Skir\Client\SkirClient;

$client = new SkirRpcClient(app(SkirClient::class));

$user = $client->getUser(new GetUserRequestData(
    userId: 42,
));

Generation

The package includes an Artisan wrapper for the Skir compiler:

php artisan skir:generate-client

Use skir-php-generator for standard PHP DTOs or skir-laravel-data-generator for Spatie Laravel Data DTOs in your skir.yml.

Example skir.yml for Laravel Data clients:

generators:
  - mod: skir-laravel-data-generator
    outDir: app/SkirGenerated
    config:
      namespace: App\Skir

The command runs:

node node_modules/skir/dist/compiler.js gen --root <project-root>

Configure the executable paths with:

SKIR_CLIENT_NODE=node
SKIR_CLIENT_SKIR_BIN=/absolute/path/to/node_modules/skir/dist/compiler.js
SKIR_CLIENT_ROOT=/absolute/path/to/project

The command validates the configured project root and compiler file before spawning Node, then streams compiler output back through Artisan. Typed PHP objects, method descriptors, and typed RPC client adapters are produced by the Skir generator packages configured in skir.yml; this package provides the transport and the Laravel command to run that generation flow.

Codecs

Dense JSON is the default and matches the default server endpoint:

use App\Skir\Admin\SkirRpcClient;
use Skir\Client\SkirClient;

$transport = new SkirClient('https://example.com', '/api/skir');
$client = new SkirRpcClient($transport);

For readable JSON endpoints, configure both sides as standard JSON:

use Skir\Client\Codecs\SkirClientCodecs;
use Skir\Client\SkirClient;

$transport = new SkirClient(
    baseUrl: 'https://example.com',
    endpoint: '/api/skir',
    codec: SkirClientCodecs::standardJson(),
);

For base64-encoded dense JSON endpoints:

$transport = new SkirClient(
    baseUrl: 'https://example.com',
    endpoint: '/api/skir',
    codec: SkirClientCodecs::base64DenseJson(),
);

For binary CBOR endpoints:

$transport = new SkirClient(
    baseUrl: 'https://example.com',
    endpoint: '/api/skir',
    codec: SkirClientCodecs::cbor(),
);

CBOR support is optional. Install spomky-labs/cbor-php in the consuming app before using SkirClientCodecs::cbor() or SKIR_CLIENT_CODEC=cbor.

Container configuration supports:

SKIR_CLIENT_CODEC=dense_json
SKIR_CLIENT_CODEC=standard_json
SKIR_CLIENT_CODEC=base64_dense_json
SKIR_CLIENT_CODEC=cbor

The selected client codec must match the server endpoint codec.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固