Skip to content
This repository has been archived by the owner on Apr 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #19 from Muetze42/development
Browse files Browse the repository at this point in the history
refactor: use curl to get dependencies
  • Loading branch information
Muetze42 authored Oct 22, 2023
2 parents 3193152 + 7930833 commit e38469a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"require": {
"php": "^8.0",
"ext-curl": "*",
"illuminate/cache": "^9.43|^10.0",
"illuminate/config": "^9.43|^10.0",
"illuminate/console": "^9.0|^10.0",
Expand Down
33 changes: 26 additions & 7 deletions src/LuraInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ abstract public function runLura(mixed $command);
*/
protected static ?array $dependenciesVersions = null;

/**
* @var string
*/
protected static string $versionsUrl = 'https://raw.githubusercontent.com/Muetze42/data/main/storage/versions.json';

/**
* Add a dependencies to json.
*
Expand Down Expand Up @@ -60,14 +65,28 @@ protected static function addDependency(
protected static function getDependenciesVersions(): array
{
if (is_null(static::$dependenciesVersions)) {
if (
$contents = file_get_contents(
'https://raw.githubusercontent.com/Muetze42/data/main/storage/versions.json'
)
) {
if (Str::isJson($contents)) {
static::$dependenciesVersions = json_decode($contents, true);
try {
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => static::$versionsUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 6,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));

$response = curl_exec($curl);

curl_close($curl);
if ($response && is_string($response) && Str::isJson($response)) {
static::$dependenciesVersions = json_decode($response, true);
}
} catch (\Exception) {
// silent
}
}
if (is_null(static::$dependenciesVersions)) {
Expand Down

0 comments on commit e38469a

Please sign in to comment.