xref: /web-bugs/src/Utils/Versions/Client.php (revision 465b7221)
1<?php
2
3namespace App\Utils\Versions;
4
5/**
6 * API client for sending requests to PHP API pages.
7 */
8class Client
9{
10    /**
11     * API URL for fetching development PHP versions.
12     *
13     * @var string
14     */
15    private $devVersionsUrl = 'https://qa.php.net/api.php?type=qa-releases&format=json&only=dev_versions';
16
17    /**
18     * API URL for fetching active PHP versions.
19     *
20     * @var string
21     */
22    private $stableVersionsUrl = 'https://php.net/releases/active.php';
23
24    /**
25     * Fetches data from remote URL.
26     */
27    public function fetchDevVersions(): array
28    {
29        $json = file_get_contents($this->devVersionsUrl);
30
31        return json_decode($json, true) ?? [];
32    }
33
34    /**
35     * Fetch stable versions from remote URL.
36     */
37    public function fetchStableVersions(): array
38    {
39        $json = file_get_contents($this->stableVersionsUrl);
40
41        return json_decode($json, true) ?? [];
42    }
43}
44