2023-11-06 07:24:04 -05:00
|
|
|
<?php
|
|
|
|
|
2024-11-03 02:19:55 -05:00
|
|
|
namespace App\Console\Commands\BlueprintFramework;
|
2023-11-06 07:24:04 -05:00
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
2024-11-03 02:19:55 -05:00
|
|
|
use App\BlueprintFramework\Libraries\ExtensionLibrary\Console\BlueprintConsoleLibrary as BlueprintExtensionLibrary;
|
2023-11-06 07:24:04 -05:00
|
|
|
|
|
|
|
class LatestCommand extends Command
|
|
|
|
{
|
2024-08-30 12:15:41 -04:00
|
|
|
protected $description = 'Get the version name of the newest release of Blueprint.';
|
2023-11-06 07:24:04 -05:00
|
|
|
protected $signature = 'bp:latest';
|
|
|
|
|
|
|
|
/**
|
2024-02-16 10:05:42 -05:00
|
|
|
* LatestCommand constructor.
|
2023-11-06 07:24:04 -05:00
|
|
|
*/
|
|
|
|
public function __construct(
|
2024-04-18 12:13:37 -04:00
|
|
|
private BlueprintPlaceholderService $PlaceholderService,
|
2023-11-06 07:24:04 -05:00
|
|
|
) { parent::__construct(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle execution of command.
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2024-04-18 12:13:37 -04:00
|
|
|
$api_url = $this->PlaceholderService->api_url()."/api/latest";
|
2023-11-06 07:24:04 -05:00
|
|
|
$context = stream_context_create([
|
|
|
|
'http' => [
|
|
|
|
'method' => 'GET',
|
|
|
|
'header' => 'User-Agent: BlueprintFramework',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
$response = file_get_contents($api_url, false, $context);
|
|
|
|
if ($response) {
|
|
|
|
$cleaned_response = preg_replace('/[[:^print:]]/', '', $response);
|
|
|
|
$data = json_decode($cleaned_response, true);
|
2024-02-16 10:05:42 -05:00
|
|
|
if (isset($data['name'])) {
|
|
|
|
$latest_version = $data['name'];
|
2023-11-06 07:24:04 -05:00
|
|
|
echo "$latest_version";
|
2024-02-16 10:05:42 -05:00
|
|
|
return "$latest_version";
|
2023-11-06 07:24:04 -05:00
|
|
|
} else {
|
|
|
|
echo "Error: Unable to fetch the latest release version.";
|
2024-02-16 10:05:42 -05:00
|
|
|
return "Error";
|
2023-11-06 07:24:04 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo "Error: Failed to make the API request.";
|
2024-02-16 10:05:42 -05:00
|
|
|
return "Error";
|
2023-11-06 07:24:04 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|