├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json └── src ├── Facades └── Packagist.php └── PackagistServiceProvider.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Release Notes 2 | 3 | ## [Unreleased](https://github.com/markwalet/laravel-packagist/compare/v1.7.1...master) 4 | 5 | ## [v1.7.1 (2025-02-03)](https://github.com/markwalet/laravel-packagist/compare/v1.7.0...v1.7.1) 6 | 7 | ### Added 8 | - Added support for Laravel 12 9 | 10 | ## [v1.7.0 (2024-04-05)](https://github.com/markwalet/laravel-packagist/compare/v1.6.0...v1.7.0) 11 | 12 | ### Added 13 | - Added support for Laravel 11 14 | 15 | ### Changed 16 | - Upgraded to PHPUnit 10 17 | 18 | ### Removed 19 | - Removed support for PHP 8.0 20 | - Removed support for Laravel 8 21 | - Removed support for Laravel 9 22 | 23 | ## [v1.6.0 (2023-11-29)](https://github.com/markwalet/laravel-packagist/compare/v1.5.0...v1.6.0) 24 | 25 | ### Added 26 | - Added Dependabot integration. 27 | - Added support for PHP 8.3 28 | 29 | ## [v1.5.0 (2022-03-02)](https://github.com/markwalet/laravel-packagist/compare/v1.4.0...v1.5.0) 30 | 31 | ### Added 32 | - Added Laravel 10 support. 33 | 34 | ## Fixed 35 | - Fixed build status badge in readme 36 | 37 | ### Removed 38 | - Removed PHP 7.4 support. 39 | - Removed Laravel 6 support. 40 | - Removed Laravel 7 support. 41 | 42 | ## [v1.4.0 (2022-02-08)](https://github.com/markwalet/laravel-packagist/compare/v1.3.0...v1.4.0) 43 | 44 | ### Added 45 | - Added Laravel 9 support. 46 | 47 | ## [v1.3.0 (2021-12-07)](https://github.com/markwalet/laravel-packagist/compare/v1.2.0...v1.3.0) 48 | 49 | ## Added 50 | - Added PHP 8.1 support. 51 | - Upgraded to PHPUnit 9. 52 | 53 | ## Removed 54 | - Removed PHP 7.2 support. 55 | - Removed PHP 7.3 support. 56 | 57 | ## [v1.2.0 (2020-12-13)](https://github.com/markwalet/laravel-packagist/compare/v1.1.0...v1.2.0) 58 | 59 | ### Added 60 | - Added PHP 8 support. 61 | 62 | ## [v1.1.0 (2020-10-01)](https://github.com/markwalet/laravel-packagist/compare/v1.0.0...v1.1.0) 63 | 64 | ### Added 65 | - Added Laravel 8 support. 66 | 67 | ## v1.0.0 (2020-04-08) 68 | 69 | Initial release 70 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Mark Walet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Packagist 2 | 3 | [![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 4 | [![Latest Stable Version](https://poser.pugx.org/markwalet/laravel-packagist/v/stable)](https://packagist.org/packages/markwalet/laravel-packagist) 5 | [![Build status](https://img.shields.io/github/actions/workflow/status/markwalet/laravel-packagist/tests.yml?branch=master)](https://github.com/markwalet/laravel-git-state/actions) 6 | [![Coverage](https://codecov.io/gh/markwalet/laravel-packagist/branch/master/graph/badge.svg)](https://codecov.io/gh/markwalet/laravel-packagist) 7 | [![StyleCI](https://github.styleci.io/repos/254053836/shield?branch=master)](https://github.styleci.io/repos/254053836) 8 | [![Total Downloads](https://poser.pugx.org/markwalet/laravel-packagist/downloads)](https://packagist.org/packages/markwalet/laravel-packagist) 9 | 10 | A Laravel wrapper for the [spatie/packagist-api](https://github.com/spatie/packagist-api) package. 11 | 12 | ## Installation 13 | You can install this package with composer: 14 | 15 | ```shell 16 | composer require markwalet/laravel-packagist 17 | ``` 18 | 19 | Laravel uses Package auto-discovery, so you don't have to register the service provider. If you want to register the service provider manually, add the following line to your `config/app.php` file: 20 | 21 | ```php 22 | MarkWalet\Packagist\PackagistServiceProvider::class, 23 | ``` 24 | 25 | ## Usage 26 | 27 | There are two main ways how you can make Packagist calls: 28 | 29 | **Using the application container** 30 | 31 | ```php 32 | /** @var \Spatie\Packagist\PackagistClient $client */ 33 | $client = app(\Spatie\Packagist\PackagistClient::class); 34 | 35 | $client->getPackage('markwalet', 'laravel-packagist'); 36 | ``` 37 | 38 | **Using the facade** 39 | ```php 40 | Packagist::getPackage('markwalet', 'laravel-packagist'); 41 | ``` 42 | ### Available methods 43 | 44 | **List package names** 45 | ```php 46 | // All packages 47 | Packagist::getPackagesNames(); 48 | 49 | // Filter on type. 50 | Packagist::getPackagesNamesByType('composer-plugin'); 51 | 52 | // Filter on organization 53 | Packagist::getPackagesNamesByVendor('markwalet'); 54 | ``` 55 | 56 | **Searching for packages** 57 | ```php 58 | // Search packages by name. 59 | Packagist::searchPackagesByName('packagist'); 60 | 61 | // Search packages by tag. 62 | Packagist::searchPackagesByTags('psr-3'); 63 | 64 | // Search packages by type. 65 | Packagist::searchPackagesByType('composer-plugin'); 66 | 67 | // Combined search. 68 | Packagist::searchPackages('packagist', ['type' => 'library']); 69 | ``` 70 | 71 | **Pagination** 72 | 73 | Searching for packages returns a paginated result. You can change the pagination settings by adding more parameters. 74 | 75 | ```php 76 | // Get the third page, 10 items per page. 77 | Packagist::searchPackagesByName('packagist', 3, 10); 78 | ``` 79 | 80 | **Getting package data.** 81 | ```php 82 | // Using the Composer metadata. (faster, but less data) 83 | Packagist::getPackageMetadata('markwalet/laravel-packagist'); 84 | Packagist::getPackageMetadata('markwalet', 'laravel-packagist'); 85 | 86 | // Using the API. (slower, cached for 12 hours by Packagist. 87 | Packagist::getPackage('markwalet/laravel-packagist'); 88 | Packagist::getPackage('markwalet', 'laravel-packagist'); 89 | ``` 90 | 91 | **Get Statistics** 92 | ```php 93 | $packagist->getStatistics(); 94 | ``` 95 | 96 | ## Configuration 97 | By default, the api url for Packagist is set to `https://packagist.org`. If you want to override that, you can add the following code block to your `config/services.php` file: 98 | 99 | ```php 100 | 'packagist' => [ 101 | 'base_url' => 'https://packagist.org', 102 | 'repo_url' => 'https://repo.packagist.org', 103 | ], 104 | ``` 105 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "markwalet/laravel-packagist", 3 | "description": "A Laravel wrapper for the `spatie/packagist-api` package.", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Mark Walet", 9 | "email": "mark.walet@gmail.com", 10 | "homepage": "https://markwalet.me", 11 | "role": "Owner" 12 | } 13 | ], 14 | "require": { 15 | "php": "^8.1", 16 | "ext-json": "*", 17 | "laravel/framework": "^10.0|^11.0|^12.0", 18 | "phpoption/phpoption": ">=1.8", 19 | "spatie/packagist-api": "^2.0" 20 | }, 21 | "require-dev": { 22 | "phpunit/phpunit": "^10.5|^11.0", 23 | "orchestra/testbench": "8.*|9.*|10.*" 24 | }, 25 | "autoload": { 26 | "psr-4": { 27 | "MarkWalet\\Packagist\\": "src/" 28 | } 29 | }, 30 | "autoload-dev": { 31 | "psr-4": { 32 | "MarkWalet\\Packagist\\Tests\\": "tests/" 33 | } 34 | }, 35 | "config": { 36 | "sort-packages": true 37 | }, 38 | "minimum-stability": "dev", 39 | "prefer-stable": true, 40 | "extra": { 41 | "laravel": { 42 | "providers": [ 43 | "MarkWalet\\Packagist\\PackagistServiceProvider" 44 | ], 45 | "aliases": { 46 | "Packagist": "MarkWalet\\Packagist\\Facades\\Packagist" 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Facades/Packagist.php: -------------------------------------------------------------------------------- 1 | app->bind(PackagistClient::class, function (Application $app) { 24 | $urlGenerator = $app->make(PackagistUrlGenerator::class); 25 | 26 | return new PackagistClient(new Client(), $urlGenerator); 27 | }); 28 | 29 | $this->app->bind(PackagistUrlGenerator::class, function (Application $app) { 30 | /** @var Repository $config */ 31 | $config = $app['config']; 32 | 33 | return new PackagistUrlGenerator( 34 | $config->get('services.packagist.base_url', null), 35 | $config->get('services.packagist.repo_url', null) 36 | ); 37 | }); 38 | } 39 | 40 | /** 41 | * Get the services provided by the provider. 42 | * 43 | * @return array 44 | */ 45 | public function provides() 46 | { 47 | return [ 48 | PackagistClient::class, 49 | PackagistUrlGenerator::class, 50 | ]; 51 | } 52 | } 53 | --------------------------------------------------------------------------------