You are here

final class SwaggerUiLibraryDiscoveryException in Swagger UI Field Formatter 8.3

Base exception for Swagger UI library discovery.

Hierarchy

Expanded class hierarchy of SwaggerUiLibraryDiscoveryException

3 files declare their use of SwaggerUiLibraryDiscoveryException
SwaggerUiLibraryDiscovery.php in src/Service/SwaggerUiLibraryDiscovery.php
SwaggerUiLibraryDiscovery.php in tests/modules/swagger_ui_formatter_test/src/Service/SwaggerUiLibraryDiscovery.php
SwaggerUiLibraryDiscoveryTest.php in tests/src/Unit/SwaggerUiLibraryDiscoveryTest.php

File

src/Exception/SwaggerUiLibraryDiscoveryException.php, line 10

Namespace

Drupal\swagger_ui_formatter\Exception
View source
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;

  /**
   * {@inheritdoc}
   *
   * phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod.Found
   */
  private function __construct($message = '', $code = 0, \Throwable $previous = NULL) {
    parent::__construct($message, $code, $previous);
  }

  /**
   * Thrown when the Swagger UI library directory path is invalid.
   *
   * @param string $library_dir
   *   The path of the Swagger UI library directory.
   *
   * @return self
   *   The exception.
   */
  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);
  }

  /**
   * Thrown when a required Swagger UI library file is not found.
   *
   * @param string $file_path
   *   The path of the required Swagger UI library file.
   *
   * @return self
   *   The exception.
   */
  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);
  }

  /**
   * Thrown when cannot read the Swagger UI library's package.json file.
   *
   * @param string $package_json_path
   *   The Swagger UI library's package.json file path.
   *
   * @return self
   *   The exception.
   */
  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);
  }

  /**
   * Thrown when the Swagger UI library's package.json file cannot be decoded.
   *
   * @param string $package_json_path
   *   The Swagger UI library's package.json file path.
   * @param string $json_last_error_msg
   *   The error message of the last json_decode() call.
   *
   * @return self
   *   The exception.
   */
  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);
  }

  /**
   * Thrown when the library version is not found in the package.json file.
   *
   * @param string $package_json_path
   *   The Swagger UI library's package.json file path.
   *
   * @return self
   *   The exception.
   */
  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);
  }

  /**
   * Thrown when the library version is lower than the minimum supported one.
   *
   * @param string $library_version
   *   The actual version of the Swagger UI library.
   * @param string $library_version_min
   *   The minimum supported version of the Swagger UI library.
   *
   * @return self
   *   The exception.
   */
  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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SwaggerUiLibraryDiscoveryException::becauseCannotReadPackageJsonContent public static function Thrown when cannot read the Swagger UI library's package.json file.
SwaggerUiLibraryDiscoveryException::becauseLibraryDirectoryIsInvalid public static function Thrown when the Swagger UI library directory path is invalid.
SwaggerUiLibraryDiscoveryException::becauseLibraryVersionIsNotSupported public static function Thrown when the library version is lower than the minimum supported one.
SwaggerUiLibraryDiscoveryException::becausePackageJsonCannotBeDecoded public static function Thrown when the Swagger UI library's package.json file cannot be decoded.
SwaggerUiLibraryDiscoveryException::becauseRequiredLibraryFileIsNotFound public static function Thrown when a required Swagger UI library file is not found.
SwaggerUiLibraryDiscoveryException::becauseUnableToIdentifyLibraryVersion public static function Thrown when the library version is not found in the package.json file.
SwaggerUiLibraryDiscoveryException::CODE_CANNOT_DECODE_PACKAGE_JSON public constant
SwaggerUiLibraryDiscoveryException::CODE_CANNOT_READ_PACKAGE_JSON_CONTENT public constant
SwaggerUiLibraryDiscoveryException::CODE_INVALID_DIR public constant
SwaggerUiLibraryDiscoveryException::CODE_LIBRARY_VERSION_IS_NOT_SUPPORTED public constant
SwaggerUiLibraryDiscoveryException::CODE_REQUIRED_FILE_IS_NOT_FOUND public constant
SwaggerUiLibraryDiscoveryException::CODE_UNABLE_TO_IDENTIFY_LIBRARY_VERSION public constant
SwaggerUiLibraryDiscoveryException::__construct private function phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod.Found