在php文件中找不到用于get API的Swagger类

rqcrx0a6  于 2023-10-18  发布在  PHP
关注(0)|答案(1)|浏览(137)

我不得不使用Swagger-php包来使用api,我在composer服务中安装了这个包,它包含在composer.json文件中,但是当使用方法时,这个包给了我一个class ... not found错误,我第一次遇到这个问题,我无法通过Google搜索找到有用的答案。
注意:我安装这个软件包的方式与之前的软件包相同,所有软件包都相互响应(composer require [package name]

  • composer.json文件的内容
{
    "require": {
        "guzzlehttp/guzzle": "^7.0",
        "phpmailer/phpmailer": "^6.2",
        "swiftmailer/swiftmailer": "^6.0",
        "zircote/swagger-php": "^3.1",
        "doctrine/annotations": "^1.11",
        "sendinblue/api-v3-sdk": "7.x.x"
   }
  • 文件autoload_real.php的内容
<?php
class ComposerAutoloaderInit9a732474ebcdab3ca8b0d72c7250c12c
{
    private static $loader;

    public static function loadClassLoader($class)
    {
        if ('Composer\Autoload\ClassLoader' === $class) {
            require __DIR__ . '/ClassLoader.php';
        }
    }

    /**
     * @return \Composer\Autoload\ClassLoader
     */
    public static function getLoader()
    {
        if (null !== self::$loader) {
            return self::$loader;
        }

        require __DIR__ . '/platform_check.php';

        spl_autoload_register(array('ComposerAutoloaderInit9a732474ebcdab3ca8b0d72c7250c12c', 'loadClassLoader'), true, true);
        self::$loader = $loader = new \Composer\Autoload\ClassLoader();
        spl_autoload_unregister(array('ComposerAutoloaderInit9a732474ebcdab3ca8b0d72c7250c12c', 'loadClassLoader'));

        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
        if ($useStaticLoader) {
            require __DIR__ . '/autoload_static.php';

            call_user_func(\Composer\Autoload\ComposerStaticInit9a732474ebcdab3ca8b0d72c7250c12c::getInitializer($loader));
        } else {
            $map = require __DIR__ . '/autoload_namespaces.php';
            foreach ($map as $namespace => $path) {
                $loader->set($namespace, $path);
            }

            $map = require __DIR__ . '/autoload_psr4.php';
            foreach ($map as $namespace => $path) {
                $loader->setPsr4($namespace, $path);
            }

            $classMap = require __DIR__ . '/autoload_classmap.php';
            if ($classMap) {
                $loader->addClassMap($classMap);
            }
        }

        $loader->register(true);

        if ($useStaticLoader) {
            $includeFiles = Composer\Autoload\ComposerStaticInit9a732474ebcdab3ca8b0d72c7250c12c::$files;
        } else {
            $includeFiles = require __DIR__ . '/autoload_files.php';
        }
        foreach ($includeFiles as $fileIdentifier => $file) {
            composerRequire9a732474ebcdab3ca8b0d72c7250c12c($fileIdentifier, $file);
        }

        return $loader;
    }
}
function composerRequire9a732474ebcdab3ca8b0d72c7250c12c($fileIdentifier, $file)
{
    if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
        require $file;

        $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
    }
}
  • 错误文本:
Fatal error: Uncaught Error: Class "Swagger\Client\Configuration" not found ...
  • 我做的事情:

1 -我更新 composer
2 -我将包存储库插入composer.json

,"repositories": [
        {
            "type": "vcs",
            "url":  "git@bitbucket.org:vendor/my-private-repo.git"
        }
    ]

3 -composer dumpautoloadcomposer run

  • 我不想改变psr4,因为我不知道怎么做

我的代码:

<?php
require_once("/home/milad/vendor/autoload.php");

// Configure API key authorization: apieco-key
Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('7UHoMOuKT0bgYv0FmG9xFi70d11DVP0C', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('apieco-key', 'Bearer');

$api_instance = new Swagger\Client\Api\ConditionsApi();
$apiecoKey = "7UHoMOuKT0bgYv0FmG9xFi70d11DVP0C"; // String | 
$age = "40"; // String | age
$enableTriage5 = true; // Boolean | enable 5-level triage values

try {
    $result = $api_instance->conditions($apiecoKey, $age, $enableTriage5);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling ConditionsApi->conditions: ', $e->getMessage(), PHP_EOL;
}
?>
kupeojn6

kupeojn61#

根据您的composer.json,您正在v3中使用zircote/swagger-php。您正在使用的代码看起来与v3不兼容,因为维护人员将其名称空间从Swagger更改为OpenApi
您需要遵循为v3制作的教程,或者将您正在使用的软件包降级到v2

相关问题