SwaggerUiLibraryDiscoveryException.php in Swagger UI Field Formatter 8.3
File
src/Exception/SwaggerUiLibraryDiscoveryException.php
View source
<?php
declare (strict_types=1);
namespace Drupal\swagger_ui_formatter\Exception;
final class SwaggerUiLibraryDiscoveryException extends \RuntimeException implements SwaggerUiLibraryDiscoveryExceptionInterface {
public const CODE_INVALID_DIR = 1;
public const CODE_REQUIRED_FILE_IS_NOT_FOUND = 2;
public const CODE_CANNOT_READ_PACKAGE_JSON_CONTENT = 3;
public const CODE_CANNOT_DECODE_PACKAGE_JSON = 4;
public const CODE_UNABLE_TO_IDENTIFY_LIBRARY_VERSION = 5;
public const CODE_LIBRARY_VERSION_IS_NOT_SUPPORTED = 6;
private function __construct($message = '', $code = 0, \Throwable $previous = NULL) {
parent::__construct($message, $code, $previous);
}
public static function becauseLibraryDirectoryIsInvalid(string $library_dir) : self {
return new static(sprintf('The provided "%s" Swagger UI library directory is invalid.', $library_dir), self::CODE_INVALID_DIR);
}
public static function becauseRequiredLibraryFileIsNotFound(string $file_path) : self {
return new static(sprintf('The Swagger UI library directory is invalid because the required "%s" file is not found.', $file_path), self::CODE_REQUIRED_FILE_IS_NOT_FOUND);
}
public static function becauseCannotReadPackageJsonContent(string $package_json_path) : self {
return new static(sprintf('Cannot read the content of the Swagger UI library\'s package.json file in "%s".', $package_json_path), self::CODE_CANNOT_READ_PACKAGE_JSON_CONTENT);
}
public static function becausePackageJsonCannotBeDecoded(string $package_json_path, string $json_last_error_msg) : self {
return new static(sprintf('Cannot decode the Swagger UI library\'s package.json file in "%s": "%s".', $package_json_path, $json_last_error_msg), self::CODE_CANNOT_DECODE_PACKAGE_JSON);
}
public static function becauseUnableToIdentifyLibraryVersion(string $package_json_path) : self {
return new static(sprintf('The Swagger UI library version is not found in "%s".', $package_json_path), self::CODE_UNABLE_TO_IDENTIFY_LIBRARY_VERSION);
}
public static function becauseLibraryVersionIsNotSupported(string $library_version, string $library_version_min) : self {
return new static(sprintf('The Swagger UI library version v%s is lower than the minimally supported v%s. Please download <a href="https://github.com/swagger-api/swagger-ui/releases" target="_blank">a newer version</a>.', $library_version, $library_version_min), self::CODE_LIBRARY_VERSION_IS_NOT_SUPPORTED);
}
}