CoreFiles by mySites.guru
HttpLoader.php50 lines, 1,505 bytes, from Joomla_6.0.0-beta1-Beta-Full_Package.zip
Raw History Compare with 5.4.0-beta3
md5
5a8a0bf2eecda36c60c1ed337ac49600
sha1
2cfc4e5df56294130d3e8391668d41e3c3d98523
sha256
c8d052d499b73acfc33e814a9612df4dbc12e55f2c7ceae4616b9bae7ee9e2cd
<?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->getStatusCode() !== 200) {
            throw new RepoFileNotFound();
        }

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

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

The same content is in 73 releases, Joomla 5.4.0-beta1 to 6.2.1-rc1. See them all, or every version of this file.