angkor/binary-wrapper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

angkor/binary-wrapper

Composer 安装命令:

composer require angkor/binary-wrapper

包简介

Base abstraction for Laravel packages that wrap Go/Rust CLI binaries

README 文档

README

Base abstraction for Laravel packages that wrap Go/Rust CLI binaries.

Overview

This package provides the scaffolding to build Laravel packages around external CLI binaries (Go, Rust, etc.). It handles binary resolution, process execution, error handling, config publishing, and includes a ready-to-use Thumbhash implementation as a reference.

Requirements

  • PHP 8.3+
  • Laravel 11 or 12

Installation

composer require angkor/binary-wrapper

Usage

Building your own binary wrapper

1. Extend BinaryWrapper

use Angkor\BinaryWrapper\BinaryWrapper;

class MyTool extends BinaryWrapper
{
    protected function defaultBinary(): string
    {
        return 'mytool'; // fallback binary name on PATH
    }

    public function process(string $input): string
    {
        return trim($this->run(['--flag', $input])->output());
    }
}

2. Extend BinaryServiceProvider

use Angkor\BinaryWrapper\BinaryServiceProvider;

class MyToolServiceProvider extends BinaryServiceProvider
{
    protected function wrapperClass(): string
    {
        return MyTool::class;
    }

    protected function configKey(): string
    {
        return 'mytool';
    }

    protected function configPath(): string
    {
        return __DIR__ . '/../config/mytool.php';
    }
}

3. Create a config file (config/mytool.php)

return [
    'binary_path' => env('MYTOOL_BINARY_PATH', '/usr/local/bin/mytool'),
];

The service provider will automatically:

  • Merge config from your package
  • Bind MyTool in the container, injecting binary_path from config
  • Publish config and register the binary:check command when running in console

Publish config

php artisan vendor:publish --tag=mytool-config

Check binary accessibility

php artisan binary:check "App\MyTool"

Thumbhash

This package ships with a Thumbhash implementation that wraps the go-thumbhash CLI binary.

Setup

Register the service provider in config/app.php (auto-discovered via composer.json):

Angkor\BinaryWrapper\Thumbhash\ThumbhashServiceProvider::class,

Set the binary path in your .env:

THUMBHASH_BINARY_PATH=/usr/local/bin/thumbhash

Or publish and edit the config:

php artisan vendor:publish --tag=thumbhash-config

API

use Angkor\BinaryWrapper\Thumbhash\Facades\Thumbhash;

// Encode an image to a base64 thumbhash string
$hash = Thumbhash::encode('/path/to/image.jpg');

// Decode a thumbhash back to a PNG
Thumbhash::decode($hash, '/path/to/output.png');
Thumbhash::decode($hash, '/path/to/output.png', size: 32);

// Convert image to raw RGBA data
$dataPath = Thumbhash::toRawData('/path/to/image.jpg');
$dataPath = Thumbhash::toRawData('/path/to/image.jpg', '/path/to/output.data');

Exceptions

Exception Thrown when
BinaryNotFoundException Binary file does not exist at resolved path
ProcessFailedException Binary exits with a non-zero status code

Testing

composer test
composer analyse
composer format

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固