CoreFiles by mySites.guru
HttpLoader.php45 lines, 1,253 bytes, from Joomla_5.1.0-rc1-Release_Candidate-Full_Package.zip
Raw History Compare with 5.0.3-rc1
md5
1a4403dcc0ea0a7dae7470117d6763af
sha1
62a1c6438178b74d0af036683b1ed6f127f7384f
sha256
6b01b26c4f60bbd5f94ccdcb1ba4ca4af27ca52e61701b3554a64139525b8c35
<?php

/**
 * Joomla! Content Management System
 *
 * @copyright  (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\CMS\TUF;

use GuzzleHttp\Promise\Create;
use GuzzleHttp\Promise\PromiseInterface;
use Joomla\Http\Http;
use Tuf\Exception\RepoFileNotFound;
use Tuf\Loader\LoaderInterface;

/**
 * @since  5.1.0
 *
 * @internal Currently this class is only used for Joomla! updates and will be extended in the future to support 3rd party updates
 *           Don't extend this class in your own code, it is subject to change without notice.
 */
class HttpLoader implements LoaderInterface
{
    public function __construct(private readonly string $repositoryPath, private readonly Http $http)
    {
    }

    public function load(string $locator, int $maxBytes): PromiseInterface
    {
        /** @var Http $client */
        $response = $this->http->get($this->repositoryPath . $locator);

        if ($response->code !== 200) {
            throw new RepoFileNotFound();
        }

        // Rewind to start
        $response->getBody()->rewind();

        // Return response
        return Create::promiseFor($response->getBody());
    }
}

The same content is in 3 releases, Joomla 5.1.0-rc1 to 5.1.0. See them all, or every version of this file.