diff --git a/core/lib/Drupal/Core/Extension/Requirement/BaseRequirement.php b/core/lib/Drupal/Core/Extension/Requirement/BaseRequirement.php new file mode 100644 index 0000000000..93ae5d1e13 --- /dev/null +++ b/core/lib/Drupal/Core/Extension/Requirement/BaseRequirement.php @@ -0,0 +1,209 @@ +severity; + } + + /** + * Gets the title. + * + * @return string + */ + public function getTitle() { + return $this->title; + } + + /** + * Sets the title. + * + * @param string $title + * + * @return $this + */ + public function setTitle($title) { + $this->title = $title; + return $this; + } + + /** + * Gets the value. + * + * @return string + */ + public function getValue() { + return $this->value; + } + + /** + * Sets the value. + * + * @param string $value + * + * @return $this + */ + public function setValue($value) { + $this->value = $value; + return $this; + } + + /** + * Gets the description. + * + * @return string + */ + public function getDescription() { + return $this->description; + } + + /** + * Sets the description. + * + * @param string $description + * + * @return $this + */ + public function setDescription($description) { + $this->description = $description; + return $this; + } + + public function offsetExists($offset) { + if (in_array($offset, [ + 'description', + 'title', + 'value', + 'severity', + ], TRUE)) { + return TRUE; + } + return FALSE; + } + + /** + * {@inheritdoc} + * + * This is for BC support only. + */ + public function offsetGet($offset) { + switch ($offset) { + case 'description': + return $this->getDescription(); + case 'title': + return $this->getTitle(); + case 'value': + return $this->getValue(); + case 'severity': + return $this->getSeverity(); + default: + return NULL; + } + } + + /** + * {@inheritdoc} + * + * This is for BC support only. + */ + public function offsetSet($offset, $value) { + switch ($offset) { + case 'description': + $this->setDescription($value); + return NULL; + case 'title': + $this->setTitle($value); + return NULL; + case 'value': + $this->setValue($value); + return NULL; + case 'severity': + $this->severity = $value; + return NULL; + } + } + + /** + * {@inheritdoc} + * + * This is for BC support only. + */ + public function offsetUnset($offset) { + switch ($offset) { + case 'description': + $this->setDescription(NULL); + return NULL; + case 'title': + $this->setTitle(NULL); + return NULL; + case 'value': + $this->setValue(NULL); + return NULL; + case 'severity': + $this->severity = self::SEVERITY_OK; + return NULL; + } + } + +} diff --git a/core/lib/Drupal/Core/Extension/Requirement/BaseRequirementOk.php b/core/lib/Drupal/Core/Extension/Requirement/BaseRequirementOk.php new file mode 100644 index 0000000000..e03b0b7095 --- /dev/null +++ b/core/lib/Drupal/Core/Extension/Requirement/BaseRequirementOk.php @@ -0,0 +1,17 @@ +definition = $values; - } - - /** - * Create a new requirement. - * - * @return static - * A new requirementDefinition object. - */ - public static function create() { - $definition = []; - return new static($definition); - } - - /** - * Set the title of the requirement. - * - * @param string $title - * The title. - * - * @return static - * The object itself for chaining. - */ - public function setTitle($title) { - $this->definition['title'] = $title; - return $this; - } - - /** - * Set the current value (e.g., version, time, level, etc). - * - * During install phase, this should only be used for version numbers, do not - * set it if not applicable. - * - * @param string $value - * The current value. - * - * @return static - * The object itself for chaining. - */ - public function setValue($value) { - $this->definition['value'] = $value; - return $this; - } - - /** - * Set the description of the requirement/status. - * - * @param string $description - * The description. - * - * @return static - * The object itself for chaining. - */ - public function setDescription($description) { - $this->definition['description'] = $description; - return $this; - } - - /** - * Set the requirement's result/severity level. - * - * Must be one of: - * - REQUIREMENT_INFO: For info only. - * - REQUIREMENT_OK: The requirement is satisfied. - * - REQUIREMENT_WARNING: The requirement failed with a warning. - * - REQUIREMENT_ERROR: The requirement failed with an error. - * - * @param string $severity - * The severity. - * - * @return static - * The object itself for chaining. - */ - public function setSeverity($severity) { - $this->definition['severity'] = $severity; - return $this; - } - - /** - * {@inheritdoc} - * - * This is for BC support only. - */ - public function offsetExists($offset) { - // PHP's array access does not work correctly with isset(), so we have to - // bake isset() in here. See https://bugs.php.net/bug.php?id=41727. - return array_key_exists($offset, $this->definition) && isset($this->definition[$offset]); - } - - /** - * {@inheritdoc} - * - * This is for BC support only. - */ - public function &offsetGet($offset) { - if (!isset($this->definition[$offset])) { - $this->definition[$offset] = NULL; - } - return $this->definition[$offset]; - } - - /** - * {@inheritdoc} - * - * This is for BC support only. - */ - public function offsetSet($offset, $value) { - $this->definition[$offset] = $value; - } - - /** - * {@inheritdoc} - * - * This is for BC support only. - */ - public function offsetUnset($offset) { - unset($this->definition[$offset]); - } - -} diff --git a/core/lib/Drupal/Core/Extension/Requirement/RequirementError.php b/core/lib/Drupal/Core/Extension/Requirement/RequirementError.php new file mode 100644 index 0000000000..04e30141b8 --- /dev/null +++ b/core/lib/Drupal/Core/Extension/Requirement/RequirementError.php @@ -0,0 +1,17 @@ +setTitle("Alice in Wonderland") ->setDescription("It's no use going back to yesterday, because I was a different person then.") - ->setValue("small") - ->setSeverity(Requirement::SEVERITY_WARNING); + ->setValue("small"); // Test array access. $this->assertEquals("Alice in Wonderland", $requirement['title']); $this->assertEquals("It's no use going back to yesterday, because I was a different person then.", $requirement['description']); $this->assertEquals("small", $requirement['value']); - $this->assertEquals(Requirement::SEVERITY_WARNING, $requirement['severity']); + $this->assertEquals(BaseRequirement::SEVERITY_OK, $requirement['severity']); } }