Issue
I had to use the Swagger-php package to use an api and I installed this package in the composer service and it was included in the composer.json file, but when using the methods This package gives me an class ... not found error, the first time I encounter this problem and I could not find a useful answer through Google search.
Note: I installed this package in the same way as the previous packages and all packages respond to each other (composer require [package name])
- The contents of the
composer.jsonfile
{
"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"
}
- The contents of the file
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;
}
}
- Error text:
Fatal error: Uncaught Error: Class "Swagger\Client\Configuration" not found ...
- Things I did:
1 - I update composer
2 - I insert package repository to composer.json
,"repositories": [
{
"type": "vcs",
"url": "git@bitbucket.org:vendor/my-private-repo.git"
}
]
3 - composer dumpautoload and composer run
- idont change
psr4,because I did not know how to do it
my code:
<?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;
}
?>
Solution
According to your composer.json, you are using zircote/swagger-php in v3. The code you are using looks like something that is not compatible with v3, as the maintainers changed their namespace from Swagger to OpenApi
You either need to follow a tutorial that is made for v3, or downgrade the package you are using to v2
Answered By - Nico Haase
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.