akira/laravel-packagist
Composer 安装命令:
composer require akira/laravel-packagist
包简介
A modular SDK and Laravel integration for the Packagist.org API with typed DTOs, configurable caching strategies, and static analysis level max
README 文档
README
A modular SDK and Laravel integration for the Packagist.org API with typed DTOs, configurable caching strategies, and static analysis level max.
Requires PHP 8.4+ and Laravel 12+
Features
- Type-Safe DTOs — Strict typing with readonly properties and immutability
- Configurable Cache Strategies — Multiple caching strategies (remember, revalidate, forever, none)
- Action Pattern — Clean separation of concerns with dedicated action classes
- Full Static Analysis — PHPStan level max with Larastan
- Pest Testing — Comprehensive test coverage with PestPHP
- Laravel 12 Ready — Built for modern Laravel applications
Installation
Install via Composer:
composer require akira/laravel-packagist
Publish the configuration file:
php artisan vendor:publish --provider="Akira\Packagist\Providers\PackagistServiceProvider"
Configuration
Edit config/packagist.php to customize your setup:
return [ 'use' => [ 'driver' => env('PACKAGIST_CACHE_DRIVER'), 'strategy' => \Akira\Packagist\Cache\RevalidateCache::class, 'ttl' => (int) env('PACKAGIST_CACHE_TTL', 3600), 'tags' => ['packagist'], 'enabled' => (bool) env('PACKAGIST_CACHE_ENABLED', true), ], 'per_action' => [ 'GetPackageAction' => [ 'strategy' => \Akira\Packagist\Cache\ForeverCache::class, ], 'SearchPackagesAction' => [ 'strategy' => \Akira\Packagist\Cache\RememberCache::class, 'ttl' => 300, ], ], ];
Usage
Get Package Information
use Akira\Packagist\Facades\Packagist; $package = Packagist::package('laravel/framework'); echo $package->name; // 'laravel/framework' echo $package->description; // 'The Laravel Framework' echo $package->downloads['total']; // total downloads echo $package->downloads['monthly']; // monthly downloads echo $package->downloads['daily']; // daily downloads echo $package->favers; // total favorites
Search Packages
$results = Packagist::search('laravel', [ 'type' => 'library', 'tags' => ['framework'], 'sort' => 'downloads', ]); foreach ($results['results'] as $package) { echo $package['name']; }
Get Statistics
$stats = Packagist::stats(['period' => 'monthly']);
Get Package Maintainers
$maintainers = Packagist::maintainers('laravel/framework'); foreach ($maintainers as $maintainer) { echo $maintainer['name']; echo $maintainer['email']; }
Cache Strategies
RevalidateCache (Default)
Uses Laravel's cache remember() method with optional TTL revalidation.
'strategy' => \Akira\Packagist\Cache\RevalidateCache::class,
RememberCache
Standard cache remember with configurable TTL (default: 3600 seconds).
'strategy' => \Akira\Packagist\Cache\RememberCache::class, 'ttl' => 300, // 5 minutes
ForeverCache
Caches indefinitely until manually cleared.
'strategy' => \Akira\Packagist\Cache\ForeverCache::class,
NoneCache
Disables caching entirely.
'strategy' => \Akira\Packagist\Cache\NoneCache::class,
Custom Cache Implementation
Implement the CacheContract to create your own caching strategy:
use Akira\Packagist\Contracts\CacheContract; class CustomCache implements CacheContract { public function get(string $key, callable $callback, int $ttl = 0, ?string $action = null): mixed { return $callback(); } public function forget(string $key): void { // Custom logic } }
Register in config:
'strategy' => CustomCache::class,
Custom HTTP Client
Implement the ClientContract for custom HTTP handling:
use Akira\Packagist\Contracts\ClientContract; class CustomClient implements ClientContract { public function get(string $endpoint): mixed { // Custom implementation } public function search(string $query, array $filters = []): mixed { // Custom implementation } }
Use it:
$manager = new PackagistManager(config('packagist')); $manager->withClient(new CustomClient());
Testing
Run the test suite:
composer test
Run tests with coverage:
composer test:coverage
Type coverage check:
composer test:type-coverage
Code Quality
Format code with Pint:
composer lint
Refactor with Rector:
composer refactor
Static analysis with PHPStan:
composer test:types
Check refactoring rules:
composer test:refactor
API Reference
Packagist Facade
package(string $name): PackageDTO— Get package informationsearch(string $query, array $filters = []): array— Search packagesstats(array $filters = []): array— Get statisticsmaintainers(string $package): array— Get package maintainerswithClient(ClientContract $client): PackagistManager— Use custom HTTP clientwithCache(CacheContract $cache): PackagistManager— Use custom cache strategy
DTOs
PackageDTO
name: stringdescription: stringrepository: ?stringversions: array<string, VersionDTO>maintainers: array<MaintainerDTO>homepage: ?stringlicense: ?stringdownloads: array— Download statistics withtotal,monthly,dailyfavers: int
VersionDTO
version: stringname: stringdescription: stringrequire: stringkeywords: arrayhomepage: ?stringlicense: ?stringauthors: array
MaintainerDTO
name: stringemail: stringhomepage: ?string
License
The MIT License (MIT). See LICENSE file for details.
Support
For issues, questions, or contributions, visit the GitHub repository.
akira/laravel-packagist 适用场景与选型建议
akira/laravel-packagist 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 95 次下载、GitHub Stars 达 4, 最近一次更新时间为 2025 年 10 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「composer」 「sdk」 「laravel」 「packagist」 「package-management」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 akira/laravel-packagist 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 akira/laravel-packagist 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 akira/laravel-packagist 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
This composer plugin enables installation of GravityForms WordPress plugin and its addons.
Simple ASCII output of array data
Generate a Composer repository from installed WordPress plugins and themes.
An image upload package which provides lot of functions such as upload, resize, crop, rotate, delete.
统计信息
- 总下载量: 95
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-26