spotlibs/php-lib
Composer 安装命令:
composer require spotlibs/php-lib
包简介
PHP library for support spotlibs microservice development
README 文档
README
Description
This library is used to support easier development of Spotlibs Microservice Project.
This library provides rest client for communication between microservice. This library provides kafka client both producer and consumer with support avro serde.
Install
composer require spotlibs/php-lib
Usage
- Exception
<?php declare(strict_types=1); use Spotlibs\PhpLib\Exceptions\StdException; use Spotlibs\PhpLib\Exceptions\AccessException; class ExceptionUsage { public function ThrowingException() { throw new AccessException('You shall not pass!'); } // you can also throw any exception by static function of StdException public function ThrowingStandardException() { throw StdException::create( StdException::HEADER_EXCEPTION, 'Invalid headers to access this resource', ); } }
- Response
Standardized response body for a consistent response body structure
<?php declare(strict_types=1); use Spotlibs\PhpLib\Responses\StdResponse; use Illuminate\Http\Request; use Illuminate\Http\Response; use App\Http\Controllers\Controller; use App\Models\Post; class DailyNews extends Controller { public function index(Request $request): Response { Post::create([ 'headline' => 'Top 10 Countries with Best Cyber Security, Finland Ranked First', 'content' => 'Here are the top 10 countries with the best cyber securities based on the data published by Mix Mode and 2024 Global Security Index:' ]); return StdResponse::success('Daily news posted.'); } }
- DTO
<?php declare(strict_types=1); use Spotlibs\PhpLib\Dtos\TraitDtos; class Person { use TraitDtos; public string $name; public int $age; public array $hobbies; } class Introduction { protected Person $person; public function __construct() { // pass associative array to construct DTO $this->person = new Person([ 'name' => 'John', 'age' => 30, 'hobbies' => ['fishing', 'sleeping', 'coding'] ]); } public function index(): void { echo "Hi, my name is " . $this->person->name . ". I am " . $this->person->age . " year(s) old" . PHP_EOL; } }
- Context
Implement a context as an object containing several key:value from the begining to the end of request lifecycle. To use context, add this service provider to your bootstrap/app.php for Lumen or config/app.php for Laravel
$app->register(\Spotlibs\PhpLib\Providers\ContextServiceProvider::class);
- Activity Middleware
Request and response middleware to initiate context and writing activity log. To use this middleware, add this line to your app middleware setting
$app->middleware([ //... \Spotlibs\PhpLib\Middlewares\ActivityMonitor::class, //... ]);
- Logger
<?php declare(strict_types=1); use Spotlibs\PhpLib\Logs\Log; class HoldingBeer { public function HoldMyBeer() { Log::activity()->info(['timestamp' => '2006-01-02 15:04:05', 'status' => 'accomplished']); Log::worker()->info(['timestamp' => '2006-01-02 15:04:05', 'job' => 'holding bro\'s beer']); Log::runtime()->info(['timestamp' => '2006-01-02 15:04:05', 'error' => 'the beer likely to spilled']); Log::runtime()->warning(['timestamp' => '2006-01-02 15:04:05', 'error' => 'the beer gonna be spilled']); Log::runtime()->error(['timestamp' => '2006-01-02 15:04:05', 'error' => 'the beer got spilled']); } }
- Queue
add this service provider to your bootstrap/app.php for Lumen or config/app.php for Laravel
$app->register(\Spotlibs\PhpLib\Providers\QueueEventServiceProvider::class);
and here is how to use Queue
<?php declare(strict_types=1); use Spotlibs\PhpLib\Facades\Queue; use App\Jobs\SendMoney; use App\Models\Employee; class Payday { public function index(Request $request): void { $employees = Employee::get(); foreach ($employees as $employee) { Queue::pushOn('payday', new SendMoney()); } } }
spotlibs/php-lib 适用场景与选型建议
spotlibs/php-lib 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.58k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 08 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Microservice」 「php-lib」 「spotlibs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 spotlibs/php-lib 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spotlibs/php-lib 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 spotlibs/php-lib 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Библиотека для реализаций паттерна Pub/Sub
Библиотека для реализаций паттерна Pub/Sub
Implementation of the transactional outbox pattern on top of rekalogika/domain-event
Php framework that provide easy way to create php micro-services
A set of core functionality and convenience classes for a Lumen microservice.
A set of model related utility and convenience classes for a Lumen microservice.
统计信息
- 总下载量: 5.58k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-27