- How do I install knplabs/packagist-api in Laravel?
- Install the package via Composer using the command composer require knplabs/packagist-api. It requires PHP 8.0 or higher. No Laravel service provider or facade is needed; you can instantiate the client directly in your code.
- Is knplabs/packagist-api compatible with Laravel 10 or 11?
- The package is framework-agnostic and only requires PHP ^8.0, so it works with any Laravel version that runs on PHP 8.0 or higher, including Laravel 10 and 11. There is no Laravel-specific integration to configure.
- How do I search for packages using knplabs/packagist-api?
- Create a new Packagist\Api\Client instance and call the search method with your query string. You can limit the number of pages returned by passing a page count as the third argument, for example $client->search('sylius', [], 2). The method returns an iterable collection of package objects.
- Can I get composer metadata for a package with this package?
- Yes, use the getComposer method to fetch Composer metadata, which is Packagist's preferred and more efficient way to retrieve package details. It returns an indexed array of packages, so you need to select the requested one by name. This response lacks some metadata provided by get() but benefits from efficient caching.
- Does knplabs/packagist-api require authentication or API keys?
- No, the Packagist API endpoints used by this package are public and do not require authentication or API keys. You can use the client out of the box without any credentials. However, be mindful of rate limits and consider caching responses.
- How do I handle rate limiting with knplabs/packagist-api?
- The package itself does not include rate limiting logic. You should implement caching or throttling in your Laravel application to avoid hitting Packagist's rate limits. Laravel's cache and HTTP client features can help you manage this.
- Can I use knplabs/packagist-api in a Laravel service or controller?
- Yes, you can instantiate the Packagist\Api\Client anywhere in your Laravel application, such as in controllers, services, or jobs. Since it is a plain PHP class, you can also bind it in Laravel's service container for dependency injection if you prefer.
- How do I test code that uses knplabs/packagist-api?
- You can mock the Client class or use Laravel's HTTP fake to simulate Packagist API responses in your tests. Since the package uses an HTTP client internally, you can inject a mock or create a fake implementation of the client. This allows you to test your application logic without making real API calls.
- What are the alternatives to knplabs/packagist-api for Laravel?
- Alternatives include using Packagist's official API directly with Laravel's HTTP client, or other PHP wrappers for Packagist. Some developers also use Composer's internal classes, but knplabs/packagist-api offers a simple object-oriented wrapper that is easy to integrate.
- Is knplabs/packagist-api actively maintained?
- Yes, the package is maintained by KnpLabs and has recent releases supporting PHP 8.0 and higher. The GitHub repository shows active build status and issue tracking. You can check the latest stable version on Packagist for updates.