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+
- 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
Install via Composer:
composer require akira/laravel-packagistPublish the configuration file:
php artisan vendor:publish --provider="Akira\Packagist\Providers\PackagistServiceProvider"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,
],
],
];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$results = Packagist::search('laravel', [
'type' => 'library',
'tags' => ['framework'],
'sort' => 'downloads',
]);
foreach ($results['results'] as $package) {
echo $package['name'];
}$stats = Packagist::stats(['period' => 'monthly']);$maintainers = Packagist::maintainers('laravel/framework');
foreach ($maintainers as $maintainer) {
echo $maintainer['name'];
echo $maintainer['email'];
}Uses Laravel's cache remember() method with optional TTL revalidation.
'strategy' => \Akira\Packagist\Cache\RevalidateCache::class,Standard cache remember with configurable TTL (default: 3600 seconds).
'strategy' => \Akira\Packagist\Cache\RememberCache::class,
'ttl' => 300, // 5 minutesCaches indefinitely until manually cleared.
'strategy' => \Akira\Packagist\Cache\ForeverCache::class,Disables caching entirely.
'strategy' => \Akira\Packagist\Cache\NoneCache::class,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,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());Run the test suite:
composer testRun tests with coverage:
composer test:coverageType coverage check:
composer test:type-coverageFormat code with Pint:
composer lintRefactor with Rector:
composer refactorStatic analysis with PHPStan:
composer test:typesCheck refactoring rules:
composer test:refactorpackage(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
name: stringdescription: stringrepository: ?stringversions: array<string, VersionDTO>maintainers: array<MaintainerDTO>homepage: ?stringlicense: ?stringdownloads: array— Download statistics withtotal,monthly,dailyfavers: int
version: stringname: stringdescription: stringrequire: stringkeywords: arrayhomepage: ?stringlicense: ?stringauthors: array
name: stringemail: stringhomepage: ?string
The MIT License (MIT). See LICENSE file for details.
For issues, questions, or contributions, visit the GitHub repository.