| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Settings\Interfaces\Traits; |
|
|
| use Piwik\Policy\CompliancePolicy; |
|
|
| |
| |
| |
| |
| |
| trait PolicyComparisonTrait |
| { |
| |
| |
| |
| public static function getPolicyRequiredValues(?int $idSite = null): array |
| { |
| $policyValues = static::getPolicyRequirements(); |
|
|
| |
| foreach (array_keys($policyValues) as $policy) { |
| if (!$policy::isActive($idSite)) { |
| $policyValues[$policy] = null; |
| } |
| } |
|
|
| return $policyValues; |
| } |
|
|
| |
| |
| |
| |
| public static function getPolicyValuesAgainstProvided($settingValue, ?int $idSite = null) |
| { |
| $values = static::getPolicyRequiredValues($idSite); |
| $values[] = $settingValue; |
| return static::getStrictestValueFromArray($values); |
| } |
|
|
| |
| |
| |
| |
| |
| protected static function getStrictestValueFromArray(array $policies) |
| { |
| |
| $callback = [__CLASS__, 'compareValuesHandleNull']; |
|
|
| return array_reduce($policies, $callback); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| protected static function compareValuesHandleNull($value1, $value2) |
| { |
| if (is_null($value1)) { |
| return $value2; |
| } |
| if (is_null($value2)) { |
| return $value1; |
| } |
|
|
| return static::compareStrictness($value1, $value2); |
| } |
|
|
| public static function isControlledBySpecificPolicy(string $policy, ?int $idSite = null): bool |
| { |
| return array_key_exists($policy, self::getPolicyRequiredValues($idSite)); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| abstract protected static function compareStrictness($value1, $value2); |
| } |
|
|