1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace jeremykenedy\LaravelPackagist\App\Traits; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Cache; |
|
|
|
|
6
|
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
|
7
|
|
|
|
8
|
|
|
trait PackagistApiTrait |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Curl the Packagist API. |
12
|
|
|
* |
13
|
|
|
* @param string $baseUrl The base url |
14
|
|
|
* |
15
|
|
|
* @return object || string || null description_of_the_return_value |
|
|
|
|
16
|
|
|
*/ |
17
|
|
|
private static function curlPackagist($baseUrl) |
18
|
|
|
{ |
19
|
|
|
$curl = curl_init(); |
20
|
|
|
curl_setopt_array($curl, [ |
|
|
|
|
21
|
|
|
CURLOPT_URL => $baseUrl, |
22
|
|
|
CURLOPT_RETURNTRANSFER => true, |
23
|
|
|
CURLOPT_ENCODING => '', |
24
|
|
|
CURLOPT_MAXREDIRS => config('laravelpackagist.curl.maxredirects'), |
|
|
|
|
25
|
|
|
CURLOPT_TIMEOUT => config('laravelpackagist.curl.timeout'), |
26
|
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
27
|
|
|
CURLOPT_CUSTOMREQUEST => 'GET', |
28
|
|
|
CURLOPT_HTTPHEADER => [ |
29
|
|
|
'Accept: application/json', |
30
|
|
|
'cache-control: no-cache', |
31
|
|
|
], |
32
|
|
|
]); |
33
|
|
|
$response = curl_exec($curl); |
|
|
|
|
34
|
|
|
$err = curl_error($curl); |
|
|
|
|
35
|
|
|
curl_close($curl); |
|
|
|
|
36
|
|
|
if ($err) { |
37
|
|
|
if (config('laravelpackagist.logging.curlErrors')) { |
38
|
|
|
Log::error($err); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $response; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Check if packagist vendor list exists in the cache. |
49
|
|
|
* |
50
|
|
|
* @return bool |
51
|
|
|
*/ |
52
|
|
|
private static function checkIfItemIsCached($key = null) |
53
|
|
|
{ |
54
|
|
|
$cachingEnabled = config('laravelpackagist.caching.enabled'); |
|
|
|
|
55
|
|
|
|
56
|
|
|
if (!$cachingEnabled) { |
57
|
|
|
return false; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if (Cache::has($key)) { |
61
|
|
|
return true; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return false; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Set the vendor cache key. |
69
|
|
|
* |
70
|
|
|
* @param string $key The key |
71
|
|
|
*/ |
72
|
|
|
private static function assignVendorCacheKey($key) |
73
|
|
|
{ |
74
|
|
|
$keyPlug = 'packagistVendorKey'; |
75
|
|
|
|
76
|
|
|
return $key.$keyPlug; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Gets the specific package detail. |
81
|
|
|
* |
82
|
|
|
* @param string $vendorAndPackage The vendor and package |
83
|
|
|
* @param string $detail The detail |
84
|
|
|
* |
85
|
|
|
* @return string The specific package detail. |
86
|
|
|
*/ |
87
|
|
|
private static function getSpecificPackageDetail($vendorAndPackage, $detail = null) |
88
|
|
|
{ |
89
|
|
|
$packageDetails = self::getVendorsPackageDetails($vendorAndPackage); |
90
|
|
|
|
91
|
|
|
if (!is_array($packageDetails)) { |
92
|
|
|
return $packageDetails; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $packageDetails[$detail]; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Gets the vendor list cache time. |
100
|
|
|
* |
101
|
|
|
* @param int $minutes The Minutes |
102
|
|
|
* |
103
|
|
|
* @return dateTime The vendor list cache time. |
|
|
|
|
104
|
|
|
*/ |
105
|
|
|
private static function getVendorListCacheTime($minutes = null) |
106
|
|
|
{ |
107
|
|
|
if ($minutes === null) { |
108
|
|
|
$minutes = config('laravelpackagist.caching.vendorListCacheTime'); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return now()->addMinutes($minutes); |
|
|
|
|
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths