CoreFiles by mySites.guru
HttpLoader.php42 lines, 1,024 bytes, from Joomla_5.1.0-beta1-Beta-Full_Package.zip
Raw History Compare with 5.0.0-beta3
md5
727e3024097bdca61d48db3aa70c5ed2
sha1
afed4af3a240e7aba6082a4666f8fb83bd30d53c
sha256
2c64f7571179de4938899282c6d83d0de34cd5dcd6287ac2f2b3dc62d5527e9f
<?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
 */
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 2 releases, Joomla 5.1.0-beta1 to 5.1.0-beta2. See them all, or every version of this file.