CoreFiles by mySites.guru
HttpLoader.php50 lines, 1,494 bytes, from Joomla_6.0.0-alpha1-Alpha-Full_Package.zip
Raw History Compare with 5.4.0-alpha3
md5
eeb3b20ff43835ab848d362519fe41a8
sha1
9f0d7a81dc222f3a665b382f300c27791d29e5c3
sha256
3f304265950a334b897394138d0876fde6ea55446ef8f7c145270c71746d5f5c
<?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
    {
        try {
            /** @var Http $client */
            $response = $this->http->get($this->repositoryPath . $locator);
        } catch (\Exception $e) {
            // We convert the generic exception thrown in the Http library into a TufException
            throw new HttpLoaderException($e->getMessage(), $e->getCode(), $e);
        }

        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 55 releases, Joomla 5.1.1-rc1 to 6.0.0-alpha3. See them all, or every version of this file.