2022-05-23 03:25:47 -04:00
|
|
|
<?php
|
|
|
|
|
|
2023-10-09 11:30:08 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2023-10-09 11:30:08 -04:00
|
|
|
*/
|
|
|
|
|
|
2022-05-23 03:25:47 -04:00
|
|
|
namespace OCP\SetupCheck;
|
|
|
|
|
|
2024-01-09 10:25:25 -05:00
|
|
|
use OCP\RichObjectStrings\IValidator;
|
|
|
|
|
|
2022-05-23 03:25:47 -04:00
|
|
|
/**
|
|
|
|
|
* @brief This class is used for storing the result of a setup check
|
|
|
|
|
*
|
2023-09-28 10:04:28 -04:00
|
|
|
* @since 28.0.0
|
2022-05-23 03:25:47 -04:00
|
|
|
*/
|
|
|
|
|
class SetupResult implements \JsonSerializable {
|
2024-02-14 14:48:27 -05:00
|
|
|
/**
|
|
|
|
|
* @since 28.0.0
|
|
|
|
|
*/
|
2023-09-28 10:04:28 -04:00
|
|
|
public const SUCCESS = 'success';
|
2024-02-14 14:48:27 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @since 28.0.0
|
|
|
|
|
*/
|
2023-09-28 10:04:28 -04:00
|
|
|
public const INFO = 'info';
|
2024-02-14 14:48:27 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @since 28.0.0
|
|
|
|
|
*/
|
2023-09-28 10:04:28 -04:00
|
|
|
public const WARNING = 'warning';
|
2024-02-14 14:48:27 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @since 28.0.0
|
|
|
|
|
*/
|
2023-09-28 10:04:28 -04:00
|
|
|
public const ERROR = 'error';
|
2022-05-23 03:25:47 -04:00
|
|
|
|
2023-11-06 10:21:15 -05:00
|
|
|
/**
|
|
|
|
|
* @param string $name Translated name to display to the user
|
|
|
|
|
*/
|
|
|
|
|
private ?string $name = null;
|
|
|
|
|
|
2022-05-23 03:25:47 -04:00
|
|
|
/**
|
2023-10-16 11:23:47 -04:00
|
|
|
* @brief Private constructor, use success()/info()/warning()/error() instead
|
2023-09-28 10:04:28 -04:00
|
|
|
* @param self::SUCCESS|self::INFO|self::WARNING|self::ERROR $severity
|
2024-09-09 14:38:34 -04:00
|
|
|
* @param array<string, array<string, string>> $descriptionParameters
|
2024-01-22 11:46:38 -05:00
|
|
|
* @throws \OCP\RichObjectStrings\InvalidObjectExeption
|
2023-09-28 10:04:28 -04:00
|
|
|
* @since 28.0.0
|
2024-01-04 10:27:18 -05:00
|
|
|
* @since 28.0.2 Optional parameter ?array $descriptionParameters
|
2024-01-09 10:46:42 -05:00
|
|
|
* @since 28.0.2 throws \OCP\RichObjectStrings\InvalidObjectExeption
|
2022-05-23 03:25:47 -04:00
|
|
|
*/
|
2023-10-16 11:23:47 -04:00
|
|
|
private function __construct(
|
2023-09-28 10:04:28 -04:00
|
|
|
private string $severity,
|
|
|
|
|
private ?string $description = null,
|
2024-01-04 10:27:18 -05:00
|
|
|
private ?array $descriptionParameters = null,
|
2023-09-28 10:04:28 -04:00
|
|
|
private ?string $linkToDoc = null,
|
|
|
|
|
) {
|
2024-01-09 10:25:25 -05:00
|
|
|
if ($description !== null && $descriptionParameters !== null) {
|
|
|
|
|
\OCP\Server::get(IValidator::class)->validate($description, $descriptionParameters);
|
|
|
|
|
}
|
2022-05-23 03:25:47 -04:00
|
|
|
}
|
|
|
|
|
|
2023-10-16 11:23:47 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Create a success result object
|
2023-11-06 10:21:15 -05:00
|
|
|
* @param ?string $description Translated detailed description to display to the user
|
|
|
|
|
* @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project
|
2024-01-22 11:46:38 -05:00
|
|
|
* @throws \OCP\RichObjectStrings\InvalidObjectExeption
|
2023-10-16 11:23:47 -04:00
|
|
|
* @since 28.0.0
|
2024-01-04 10:27:18 -05:00
|
|
|
* @since 28.0.2 Optional parameter ?array $descriptionParameters
|
2024-01-22 11:46:38 -05:00
|
|
|
* @since 28.0.2 throws \OCP\RichObjectStrings\InvalidObjectExeption
|
2023-10-16 11:23:47 -04:00
|
|
|
*/
|
2024-01-04 10:27:18 -05:00
|
|
|
public static function success(?string $description = null, ?string $linkToDoc = null, ?array $descriptionParameters = null): self {
|
|
|
|
|
return new self(self::SUCCESS, $description, $descriptionParameters, $linkToDoc);
|
2023-10-16 11:23:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Create an info result object
|
2023-11-06 10:21:15 -05:00
|
|
|
* @param ?string $description Translated detailed description to display to the user
|
|
|
|
|
* @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project
|
2024-01-22 11:46:38 -05:00
|
|
|
* @throws \OCP\RichObjectStrings\InvalidObjectExeption
|
2023-10-16 11:23:47 -04:00
|
|
|
* @since 28.0.0
|
2024-01-04 10:27:18 -05:00
|
|
|
* @since 28.0.2 Optional parameter ?array $descriptionParameters
|
2024-01-22 11:46:38 -05:00
|
|
|
* @since 28.0.2 throws \OCP\RichObjectStrings\InvalidObjectExeption
|
2023-10-16 11:23:47 -04:00
|
|
|
*/
|
2024-01-04 10:27:18 -05:00
|
|
|
public static function info(?string $description = null, ?string $linkToDoc = null, ?array $descriptionParameters = null): self {
|
|
|
|
|
return new self(self::INFO, $description, $descriptionParameters, $linkToDoc);
|
2023-10-16 11:23:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Create a warning result object
|
2023-11-06 10:21:15 -05:00
|
|
|
* @param ?string $description Translated detailed description to display to the user
|
|
|
|
|
* @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project
|
2024-01-22 11:46:38 -05:00
|
|
|
* @throws \OCP\RichObjectStrings\InvalidObjectExeption
|
2023-10-16 11:23:47 -04:00
|
|
|
* @since 28.0.0
|
2024-01-04 10:27:18 -05:00
|
|
|
* @since 28.0.2 Optional parameter ?array $descriptionParameters
|
2024-01-22 11:46:38 -05:00
|
|
|
* @since 28.0.2 throws \OCP\RichObjectStrings\InvalidObjectExeption
|
2023-10-16 11:23:47 -04:00
|
|
|
*/
|
2024-01-04 10:27:18 -05:00
|
|
|
public static function warning(?string $description = null, ?string $linkToDoc = null, ?array $descriptionParameters = null): self {
|
|
|
|
|
return new self(self::WARNING, $description, $descriptionParameters, $linkToDoc);
|
2023-10-16 11:23:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Create an error result object
|
2023-11-06 10:21:15 -05:00
|
|
|
* @param ?string $description Translated detailed description to display to the user
|
|
|
|
|
* @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project
|
2024-01-22 11:46:38 -05:00
|
|
|
* @throws \OCP\RichObjectStrings\InvalidObjectExeption
|
2023-10-16 11:23:47 -04:00
|
|
|
* @since 28.0.0
|
2024-01-04 10:27:18 -05:00
|
|
|
* @since 28.0.2 Optional parameter ?array $descriptionParameters
|
2024-01-22 11:46:38 -05:00
|
|
|
* @since 28.0.2 throws \OCP\RichObjectStrings\InvalidObjectExeption
|
2023-10-16 11:23:47 -04:00
|
|
|
*/
|
2024-01-04 10:27:18 -05:00
|
|
|
public static function error(?string $description = null, ?string $linkToDoc = null, ?array $descriptionParameters = null): self {
|
|
|
|
|
return new self(self::ERROR, $description, $descriptionParameters, $linkToDoc);
|
2023-10-16 11:23:47 -04:00
|
|
|
}
|
|
|
|
|
|
2022-05-23 03:25:47 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Get the severity for the setup check result
|
|
|
|
|
*
|
2023-09-28 10:04:28 -04:00
|
|
|
* @return self::SUCCESS|self::INFO|self::WARNING|self::ERROR
|
|
|
|
|
* @since 28.0.0
|
2022-05-23 03:25:47 -04:00
|
|
|
*/
|
|
|
|
|
public function getSeverity(): string {
|
|
|
|
|
return $this->severity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Get the description for the setup check result
|
|
|
|
|
*
|
2023-09-28 10:04:28 -04:00
|
|
|
* @since 28.0.0
|
2022-05-23 03:25:47 -04:00
|
|
|
*/
|
|
|
|
|
public function getDescription(): ?string {
|
|
|
|
|
return $this->description;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-04 10:27:18 -05:00
|
|
|
/**
|
|
|
|
|
* @brief Get the description parameters for the setup check result
|
|
|
|
|
*
|
|
|
|
|
* If this returns null, description must not be treated as rich text
|
|
|
|
|
*
|
|
|
|
|
* @since 28.0.2
|
|
|
|
|
*/
|
|
|
|
|
public function getDescriptionParameters(): ?array {
|
|
|
|
|
return $this->descriptionParameters;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-06 10:21:15 -05:00
|
|
|
/**
|
|
|
|
|
* @brief Get the name for the setup check
|
|
|
|
|
*
|
|
|
|
|
* @since 28.0.0
|
|
|
|
|
*/
|
|
|
|
|
public function getName(): ?string {
|
|
|
|
|
return $this->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Set the name from the setup check
|
|
|
|
|
*
|
|
|
|
|
* @since 28.0.0
|
|
|
|
|
*/
|
|
|
|
|
public function setName(string $name): void {
|
|
|
|
|
$this->name = $name;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 03:25:47 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Get a link to the doc for the explanation.
|
|
|
|
|
*
|
2023-09-28 10:04:28 -04:00
|
|
|
* @since 28.0.0
|
2022-05-23 03:25:47 -04:00
|
|
|
*/
|
|
|
|
|
public function getLinkToDoc(): ?string {
|
|
|
|
|
return $this->linkToDoc;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-02 07:53:44 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Get an array representation of the result for API responses
|
|
|
|
|
*
|
|
|
|
|
* @since 28.0.0
|
|
|
|
|
*/
|
2023-09-28 10:04:28 -04:00
|
|
|
public function jsonSerialize(): array {
|
2022-05-23 03:25:47 -04:00
|
|
|
return [
|
2023-11-06 10:21:15 -05:00
|
|
|
'name' => $this->name,
|
2022-05-23 03:25:47 -04:00
|
|
|
'severity' => $this->severity,
|
|
|
|
|
'description' => $this->description,
|
2024-01-04 10:27:18 -05:00
|
|
|
'descriptionParameters' => $this->descriptionParameters,
|
2022-05-23 03:25:47 -04:00
|
|
|
'linkToDoc' => $this->linkToDoc,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|