| <?php |
|
|
| namespace Piwik\Plugins\Diagnostics\Diagnostic; |
|
|
| class RequiredPhpSetting implements \JsonSerializable |
| { |
| |
| private $setting; |
|
|
| |
| private $requiredValues; |
|
|
| |
| private $errorResult = DiagnosticResult::STATUS_ERROR; |
|
|
| |
| |
| |
| |
| |
| public function __construct($setting, $requiredValue, $operator = '=') |
| { |
| $this->setting = $setting; |
| $this->addRequiredValue($requiredValue, $operator); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function addRequiredValue($requiredValue, $operator) |
| { |
| if (!is_int($requiredValue)) { |
| throw new \InvalidArgumentException('Required value must be an integer.'); |
| } |
|
|
| $this->requiredValues[] = array( |
| 'requiredValue' => $requiredValue, |
| 'operator' => $operator, |
| 'isValid' => null, |
| ); |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| |
| |
| public function setErrorResult($errorResult) |
| { |
| if ($errorResult !== DiagnosticResult::STATUS_WARNING && $errorResult !== DiagnosticResult::STATUS_ERROR) { |
| throw new \InvalidArgumentException('Error result must be either DiagnosticResult::STATUS_WARNING or DiagnosticResult::STATUS_ERROR.'); |
| } |
|
|
| $this->errorResult = $errorResult; |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| public function getErrorResult() |
| { |
| return $this->errorResult; |
| } |
|
|
| |
| |
| |
| |
| |
| public function check() |
| { |
| $currentValue = (int) ini_get($this->setting); |
|
|
| $return = false; |
| foreach ($this->requiredValues as $key => $requiredValue) { |
| $this->requiredValues[$key]['isValid'] = version_compare($currentValue, $requiredValue['requiredValue'], $requiredValue['operator']); |
|
|
| if ($this->requiredValues[$key]['isValid']) { |
| $return = true; |
| } |
| } |
|
|
| return $return; |
| } |
|
|
| public function __toString(): string |
| { |
| $checks = array(); |
| foreach ($this->requiredValues as $requiredValue) { |
| $checks[] = $requiredValue['operator'] . ' ' . $requiredValue['requiredValue']; |
| } |
|
|
| return $this->setting . ' ' . implode(' OR ', $checks); |
| } |
|
|
| public function jsonSerialize(): string |
| { |
| return $this->__toString(); |
| } |
| } |
|
|