| Server IP : 54.36.91.62 / Your IP : 216.73.217.112 Web Server : Apache System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : coopiak ( 151928) PHP Version : 8.3.23 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/coopiak/amisdesseniors-fr/aix/libraries/vendor/php-tuf/php-tuf/tests/Client/ |
Upload File : |
<?php
namespace Tuf\Tests\Client;
use GuzzleHttp\Promise\Create;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Psr7\Utils;
use Tuf\Exception\RepoFileNotFound;
use Tuf\Loader\LoaderInterface;
/**
* Loads files from a simulated, in-memory server.
*/
class TestLoader extends \ArrayObject implements LoaderInterface
{
/**
* The $maxBytes arguments passed to ::load(), keyed by file name.
*
* This is used to confirm that the updater passes the expected file names
* and maximum download lengths.
*
* @var int[][]
*/
public array $maxBytes = [];
/**
* Populates this object with a fixture's server-side metadata.
*
* @param string $basePath
* The path of the fixture to read from.
*/
public function populateFromFixture(string $basePath): void
{
$this->exchangeArray([]);
// Store the file contents in memory so they can be easily altered.
$fixturesPath = "$basePath/server";
$files = glob("$fixturesPath/metadata/*.json");
$targetsPath = "$fixturesPath/targets";
if (is_dir($targetsPath)) {
$files = array_merge($files, glob("$targetsPath/*"));
}
foreach ($files as $file) {
$baseName = basename($file);
if ($this->offsetExists($baseName)) {
throw new \UnexpectedValueException("For testing fixtures target files should not use metadata file names");
}
$this[$baseName] = file_get_contents($file);
}
}
/**
* {@inheritDoc}
*/
public function load(string $locator, int $maxBytes): PromiseInterface
{
$this->maxBytes[$locator][] = $maxBytes;
if ($this->offsetExists($locator)) {
$stream = Utils::streamFor($this[$locator]);
return Create::promiseFor($stream);
} else {
return Create::rejectionFor(new RepoFileNotFound("File $locator not found."));
}
}
}