Skip to content

Commit c1b9147

Browse files
author
Bhavik MacBook PRO 16
committed
First Rel
0 parents  commit c1b9147

File tree

12 files changed

+424
-0
lines changed

12 files changed

+424
-0
lines changed

.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
* text=auto
2+
3+
/.github export-ignore
4+
/tests export-ignore
5+
.gitattributes export-ignore
6+
.gitignore export-ignore
7+
.styleci.yml export-ignore
8+
phpunit.xml export-ignore

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.idea
2+
vendor
3+
/composer.lock
4+
composer.phar
5+
clover.json
6+
clover.xml
7+
.phpunit.result.cache

.styleci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
preset: laravel
2+
3+
disabled:
4+
- laravel_phpdoc_alignment
5+
- laravel_phpdoc_separation

CHANGELOG.md

Whitespace-only changes.

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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.

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Laravel Packagist
2+
3+
[![Latest Stable Version](https://poser.pugx.org/ingress-it-solutions/laravel-packagist/v/stable)](https://packagist.org/packages/ingress-it-solutions/laravel-packagist)
4+
[![Total Downloads](https://poser.pugx.org/ingress-it-solutions/laravel-packagist/downloads)](https://packagist.org/packages/ingress-it-solutions/laravel-packagist)
5+
6+
A Laravel wrapper for the [spatie/packagist-api](https://github.com/spatie/packagist-api) package.
7+
8+
## Installation
9+
You can install this package with composer:
10+
11+
```shell
12+
composer require ingress-it-solutions/laravel-packagist
13+
```
14+
15+
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:
16+
17+
```php
18+
IngressITSolutions\Packagist\PackagistServiceProvider::class,
19+
```
20+
21+
## Usage
22+
23+
There are two main ways how you can make Packagist calls:
24+
25+
**Using the application container**
26+
27+
```php
28+
/** @var \Spatie\Packagist\PackagistClient $client */
29+
$client = app(\Spatie\Packagist\PackagistClient::class);
30+
31+
$client->getPackage('ingress-it-solutions', 'laravel-packagist');
32+
```
33+
34+
**Using the facade**
35+
```php
36+
Packagist::getPackage('ingress-it-solutions', 'laravel-packagist');
37+
```
38+
### Available methods
39+
40+
**List package names**
41+
```php
42+
// All packages
43+
Packagist::getPackagesNames();
44+
45+
// Filter on type.
46+
Packagist::getPackagesNamesByType('composer-plugin');
47+
48+
// Filter on organization
49+
Packagist::getPackagesNamesByVendor('ingress-it-solutions');
50+
```
51+
52+
**Searching for packages**
53+
```php
54+
// Search packages by name.
55+
Packagist::searchPackagesByName('packagist');
56+
57+
// Search packages by tag.
58+
Packagist::searchPackagesByTags('psr-3');
59+
60+
// Search packages by type.
61+
Packagist::searchPackagesByType('composer-plugin');
62+
63+
// Combined search.
64+
Packagist::searchPackages('packagist', ['type' => 'library']);
65+
```
66+
67+
**Pagination**
68+
69+
Searching for packages returns a paginated result. You can change the pagination settings by adding more parameters.
70+
71+
```php
72+
// Get the third page, 10 items per page.
73+
Packagist::searchPackagesByName('packagist', 3, 10);
74+
```
75+
76+
**Getting package data.**
77+
```php
78+
// Using the Composer metadata. (faster, but less data)
79+
Packagist::getPackageMetadata('ingress-it-solutions/laravel-packagist');
80+
Packagist::getPackageMetadata('ingress-it-solutions', 'laravel-packagist');
81+
82+
// Using the API. (slower, cached for 12 hours by Packagist.
83+
Packagist::getPackage('ingress-it-solutions/laravel-packagist');
84+
Packagist::getPackage('ingress-it-solutions', 'laravel-packagist');
85+
```
86+
87+
**Get Statistics**
88+
```php
89+
$packagist->getStatistics();
90+
```
91+
92+
## Configuration
93+
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:
94+
95+
```php
96+
'packagist' => [
97+
'base_url' => 'https://packagist.org',
98+
'repo_url' => 'https://repo.packagist.org',
99+
],
100+
```

composer.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "ingress-it-solutions/laravel-packagist",
3+
"description": "A Laravel wrapper for the `spatie/packagist-api` package.",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Ingress Team",
9+
"email": "[email protected]",
10+
"homepage": "https://www.ingressit.com",
11+
"role": "Owner"
12+
}
13+
],
14+
"require": {
15+
"php": "8.*",
16+
"ext-json": "*",
17+
"laravel/framework": "8.*|^9.0|^10.0",
18+
"phpoption/phpoption": ">=1.8",
19+
"spatie/packagist-api": "^2.0"
20+
},
21+
"require-dev": {
22+
"phpunit/phpunit": "~9.3",
23+
"orchestra/testbench": "~6.22|7.*|8.*"
24+
},
25+
"autoload": {
26+
"psr-4": {
27+
"IngressITSolutions\\Packagist\\": "src/"
28+
}
29+
},
30+
"autoload-dev": {
31+
"psr-4": {
32+
"IngressITSolutions\\Packagist\\Tests\\": "tests/"
33+
}
34+
},
35+
"config": {
36+
"sort-packages": true
37+
},
38+
"extra": {
39+
"laravel": {
40+
"providers": [
41+
"IngressITSolutions\\Packagist\\PackagistServiceProvider"
42+
],
43+
"aliases": {
44+
"Packagist": "IngressITSolutions\\Packagist\\Facades\\Packagist"
45+
}
46+
}
47+
}
48+
}

phpunit.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
bootstrap="vendor/autoload.php"
4+
backupGlobals="false"
5+
backupStaticAttributes="false"
6+
colors="true"
7+
verbose="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
11+
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
12+
<include>
13+
<directory suffix=".php">./src</directory>
14+
</include>
15+
<exclude>
16+
<directory suffix=".php">./src/Exceptions/*</directory>
17+
</exclude>
18+
</coverage>
19+
<testsuites>
20+
<testsuite name="Laravel Packagist Test Suite">
21+
<directory suffix="Test.php">./tests/</directory>
22+
</testsuite>
23+
</testsuites>
24+
</phpunit>

src/Facades/Packagist.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace IngressITSolutions\Packagist\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
use Spatie\Packagist\PackagistClient;
7+
8+
/**
9+
* Class Packagist.
10+
*
11+
* @method static array|null getPackagesNames(?string $type = null, ?string $vendor = null)
12+
* @method static array|null getPackagesNamesByType(string $type)
13+
* @method static array|null getPackagesNamesByVendor(string $vendor)
14+
* @method static array|null searchPackages($name = null, array $filters = [], ?int $page = 1, int $perPage = 15)
15+
* @method static array|null searchPackagesByName(string $name, ?int $page = 1, int $perPage = 15):
16+
* @method static array|null searchPackagesByTags(string $tags, ?string $name = null, ?int $page = 1, int $perPage = 15)
17+
* @method static array|null searchPackagesByType(string $type, ?string $name = null, ?int $page = 1, int $perPage = 15)
18+
* @method static array|null getPackage(string $vendor, ?string $package = null)
19+
* @method static array|null getPackageMetadata(string $vendor, ?string $package = null)
20+
* @method static array|null getStatistics()
21+
* @see PackagistClient
22+
*/
23+
class Packagist extends Facade
24+
{
25+
/**
26+
* Get the registered name of the component.
27+
*
28+
* @return string
29+
*/
30+
protected static function getFacadeAccessor()
31+
{
32+
return PackagistClient::class;
33+
}
34+
}

src/PackagistServiceProvider.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace IngressITSolutions\Packagist;
4+
5+
use GuzzleHttp\Client;
6+
use Illuminate\Config\Repository;
7+
use Illuminate\Contracts\Foundation\Application;
8+
use Illuminate\Contracts\Support\DeferrableProvider;
9+
use Illuminate\Support\ServiceProvider;
10+
use Spatie\Packagist\PackagistClient;
11+
use Spatie\Packagist\PackagistUrlGenerator;
12+
13+
class PackagistServiceProvider extends ServiceProvider implements DeferrableProvider
14+
{
15+
/**
16+
* Register any application services.
17+
*
18+
* @return void
19+
*/
20+
public function register()
21+
{
22+
// Bind manager to application.
23+
$this->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+
}

0 commit comments

Comments
 (0)