. * --------------------------------------------------------------------- */ namespace Glpi\System\Requirement; if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * @since 9.5.0 */ abstract class AbstractRequirement implements RequirementInterface { /** * Flag that indicates if requirement check has already been done. * * @var bool */ private $has_been_checked = false; /** * Flag that indicates if requirement is considered as optional. * * @var bool */ protected $optional = false; /** * Flag that indicates if requirement is considered as out of context. * * @var bool */ protected $out_of_context = false; /** * Requirement title. * * @var string */ protected $title; /** * Flag that indicates if requirement is validated on system. * * @var bool */ protected $validated; /** * Requirement validation message. * * @var string[] */ protected $validation_messages = []; /** * Check requirement. * * This method will be called once before access to any RequirementInterface method * and should be used to compute $validated and $validation_messages properties. * * @return void */ abstract protected function check(); /** * Run requirement check once. * * @return void */ private function doCheck() { if (!$this->has_been_checked) { $this->check(); $this->has_been_checked = true; } } public function getTitle(): string { $this->doCheck(); return $this->title; } public function getValidationMessages(): array { $this->doCheck(); return $this->validation_messages; } public function isMissing(): bool { $this->doCheck(); return true !== $this->validated; } public function isOptional(): bool { $this->doCheck(); return $this->optional; } public function isOutOfContext(): bool { $this->doCheck(); return $this->out_of_context; } public function isValidated(): bool { $this->doCheck(); return true === $this->validated; } }