/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
dev/tests/api-functional/_files/Magento/TestModuleUsps/Model/MockResponseBodyLoader.php
68 строк
2 KB
Alexandra Zota
ACP2E-4019: CE copyright updates for 2.4.9-beta1
22 окт 2025, 10:44
22 окт 2025, 10:44
264bea2
Код
Авторство
О чём код?
<?php /** * Copyright 2019 Adobe * All Rights Reserved. */ declare(strict_types=1); namespace Magento\TestModuleUsps\Model; use Magento\Framework\Exception\NotFoundException; use Magento\Framework\HTTP\AsyncClient\Request; use Magento\Framework\Module\Dir; use Magento\Framework\Filesystem\Io\File; /** * Load mock response body for USPS rate request */ class MockResponseBodyLoader { private const RESPONSE_FILE_PATTERN = '%s/_files/mock_response_%s.xml'; /** * @var Dir */ private $moduleDirectory; /** * @var File */ private $fileIo; /** * @param Dir $moduleDirectory * @param File $fileIo */ public function __construct( Dir $moduleDirectory, File $fileIo ) { $this->moduleDirectory = $moduleDirectory; $this->fileIo = $fileIo; } /** * Loads mock response xml for a given request * * @param Request $request * @return string * @throws NotFoundException */ public function loadForRequest(Request $request): string { $moduleDir = $this->moduleDirectory->getDir('Magento_TestModuleUsps'); $destination = 'us'; if (strpos($request->getUrl(), 'IntlRateV2Request') !== false) { $destination = 'ca'; } $responsePath = sprintf(static::RESPONSE_FILE_PATTERN, $moduleDir, $destination); if (!$this->fileIo->fileExists($responsePath)) { throw new NotFoundException(__('%1 is not a valid destination country.', $destination)); } return $this->fileIo->read($responsePath); } }