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
Fund package maintenance!
kidiatoliny
Patreon
Installs: 27
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/akira/laravel-packagist
Requires
- php: ^8.4
- guzzlehttp/guzzle: ^7.9
- illuminate/console: ^12.0
- illuminate/support: ^12.0
- laravel/prompts: ^0.3.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- laravel/pint: ^1.24.0
- orchestra/workbench: ^10.0
- peckphp/peck: ^0.1.3
- pestphp/pest: ^4.1.0
- pestphp/pest-plugin-type-coverage: ^4.0.2
- phpstan/phpstan: ^2.1.26
- rector/rector: ^2.1.7
- symfony/var-dumper: ^7.3.3
This package is auto-updated.
Last update: 2025-10-26 18:57:09 UTC
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.