isValid = true; return; } $this->attrValue = $attrValue; $this->isDefined = true; } /** * Validate the attribute value. * * @param bool $allowAuto Whether or not to allow the 'auto' value as a value. * @param bool $allowFluid Whether or not to allow the 'fluid' value as a value. */ public function validate($allowAuto, $allowFluid) { if ($this->isValid()) { return; } if (self::AUTO === $this->attrValue) { $this->isAuto = true; $this->isValid = $allowAuto; return; } if (self::FLUID === $this->attrValue) { $this->isFluid = true; $this->isValid = $allowFluid; } $pattern = '/^(?\d+(?:\.\d+)?)(?px|em|rem|vh|vw|vmin|vmax)?$/'; if (preg_match($pattern, $this->attrValue, $match)) { $this->isValid = true; $this->numeral = isset($match['numeral']) ? (float)$match['numeral'] : $this->numeral; $this->unit = isset($match['unit']) ? $match['unit'] : $this->unit; } } /** * Whether or not the attribute value is valid. * * @return bool */ public function isValid() { return $this->isValid; } /** * Whether the attribute value is set. * * @return bool */ public function isDefined() { return $this->isDefined; } /** * Whether the attribute value is 'fluid'. * * @return bool */ public function isFluid() { return $this->isFluid; } /** * Whether the attribute value is 'auto'. * * @return bool */ public function isAuto() { return $this->isAuto; } /** * The unit of the attribute. * * @return string */ public function getUnit() { return $this->unit; } /** * The numeral of the attribute. * * @return float */ public function getNumeral() { return $this->numeral; } }