PHP code example of akira / laravel-packagist

1. Go to this page and download the library: Download akira/laravel-packagist library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

akira / laravel-packagist example snippets


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'];
}

'strategy' => \Akira\Packagist\Cache\RevalidateCache::class,

'strategy' => \Akira\Packagist\Cache\RememberCache::class,
'ttl' => 300, // 5 minutes

'strategy' => \Akira\Packagist\Cache\ForeverCache::class,

'strategy' => \Akira\Packagist\Cache\NoneCache::class,

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
    }
}

'strategy' => CustomCache::class,

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
    }
}

$manager = new PackagistManager(config('packagist'));
$manager->withClient(new CustomClient());
bash
php artisan vendor:publish --provider="Akira\Packagist\Providers\PackagistServiceProvider"