قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-10-08 01:48:25 +00:00

* WIP PoC * Turn into a plugin that can be activated in plugin administration * Move getters to a separate folder * Limit plugin.setting explode to 2 items to keep possible dots in setting name intact * Add example controller and README * Add hasValue methods to Settings plugin * Add and use `hasSetting` method * Use default hierarchy * poc * saving progress * update * finish PoC with working example * v2 with working example * remove unnecessary additions * remove commented code * ws / cs / cleanup * Reuse existing "getPluginName" lookup * Require interfaces with trait usage * Connect new settings with old settings * Connect compliance settings and dashboard * Add optional template types to settings * rearrange code into different core folders * rename policies folder to policy to match core * hooked new settings up to dashboard * add required imports for phpstan * ws / cs * Remove return type override from API * Connect title/inlinehelp to settings pages * Stub actual feature usage of new "disable visitor log" setting * implement dashboard as full mvp (#23593) * reuse system and measurable traits to save policy status * complete implementing mvp dashboard * update existing tests and add new unit tests (#23594) * fix vue issue * update existing system tests * fix vue * fix missing test files * Build vue files * update broken UI tests * update policymanager to handle more generic functions * begin adding new unit tests * update unit tests to work correctly * fix return type issue and also fix some mocking * PHPCS * more PHPCS * simplify some code to make the tests run better * phpcs * add unit tests for some new setting code * cover extra function in policyComparisonTrait --------- Co-authored-by: innocraft-automation <innocraft-automation@users.noreply.github.com> * undo some example code * more undoing * add translations, remove example code * fix visitorlog isCompliant condition * fix merging issue * phpcs * Build vue files * update broken test * update broken tests * update broken tests * fix broken UI tests * add extra translations * abstract null checks in compareStrictness function * PHPCS * new PHPCS comma changes * update UI test images * Fix UI test selector * Update UI test screenshot --------- Co-authored-by: Michal Kleiner <michal@innocraft.com> Co-authored-by: Matt <1169490+caddoo@users.noreply.github.com> Co-authored-by: Marc Neudert <marc@innocraft.com> Co-authored-by: innocraft-automation <innocraft-automation@users.noreply.github.com>
99 خطوط
2.6 KiB
PHP
99 خطوط
2.6 KiB
PHP
<?php
|
|
|
|
namespace Piwik\Policy;
|
|
|
|
use Exception;
|
|
use Piwik\Plugin\Manager;
|
|
use Piwik\Settings\Interfaces\PolicyComparisonInterface;
|
|
use Piwik\Settings\Interfaces\SettingValueInterface;
|
|
|
|
class PolicyManager
|
|
{
|
|
/**
|
|
* @return array<class-string<CompliancePolicy>>
|
|
*/
|
|
public static function getAllPolicies(): array
|
|
{
|
|
return [
|
|
CnilPolicy::class,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<array<string, string>>
|
|
*/
|
|
public static function getAllPoliciesDetails(): array
|
|
{
|
|
$policies = static::getAllPolicies();
|
|
return array_map(function ($policyClass) {
|
|
return $policyClass::getDetails();
|
|
}, $policies);
|
|
}
|
|
|
|
/**
|
|
* @return class-string<CompliancePolicy>|null
|
|
*/
|
|
public static function getPolicyByName(string $policyName): ?string
|
|
{
|
|
$policies = static::getAllPolicies();
|
|
foreach ($policies as $policyClass) {
|
|
if ($policyName === $policyClass::getName()) {
|
|
return $policyClass;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return array<class-string<PolicyComparisonInterface<mixed>&SettingValueInterface<mixed>>>
|
|
*/
|
|
public static function getAllSettings(?int $idSite = null): array
|
|
{
|
|
$settings = Manager::getInstance()->findMultipleComponents('Settings', SettingValueInterface::class);
|
|
$underPolicy = [];
|
|
|
|
foreach ($settings as $setting) {
|
|
if (!is_a($setting, PolicyComparisonInterface::class, true)) {
|
|
continue;
|
|
}
|
|
|
|
$underPolicy[] = $setting;
|
|
}
|
|
|
|
return $underPolicy;
|
|
}
|
|
|
|
/**
|
|
* @param class-string<CompliancePolicy> $policyClass
|
|
* @return array<class-string<PolicyComparisonInterface<mixed>&SettingValueInterface<mixed>>>
|
|
*/
|
|
public static function getAllControlledSettings(string $policyClass, ?int $idSite = null): array
|
|
{
|
|
$settings = static::getAllSettings($idSite);
|
|
$underPolicy = [];
|
|
|
|
foreach ($settings as $setting) {
|
|
if (!$setting::isControlledBySpecificPolicy($policyClass, $idSite)) {
|
|
continue;
|
|
}
|
|
|
|
$underPolicy[] = $setting;
|
|
}
|
|
|
|
return $underPolicy;
|
|
}
|
|
|
|
/**
|
|
* @param class-string<CompliancePolicy> $policyClass
|
|
* @throws \Exception when $policyClass is not a valid policy
|
|
*/
|
|
public static function isPolicyActive(string $policyClass, ?int $idSite = null): bool
|
|
{
|
|
if (!is_a($policyClass, CompliancePolicy::class, true)) {
|
|
throw new Exception('Invalid compliance policy.');
|
|
}
|
|
return $policyClass::isActive($idSite);
|
|
}
|
|
}
|