[ SecuritySettingsRepository::CONTENT_SECURITY_POLICY => 'list', ], ]; /** @var Setting[] */ private $settings; public function __construct(Setting ...$settings) { $this->settings = array_combine( array_map([$this, 'extractKey'], $settings), $settings ); } /** * @return Traversable|Setting[] */ public function getIterator(): Traversable { return new ArrayIterator( array_filter($this->settings, [$this, 'hasMetDependencies']) ); } public function findContentSecurityPolicy(): Setting { return $this->extractSetting(SecuritySettingsRepository::CONTENT_SECURITY_POLICY); } public function findContentSecurityPolicyWhitelist(): Setting { return $this->extractSetting(SecuritySettingsRepository::CONTENT_SECURITY_POLICY_WHITELIST); } public function findTransportSecurity(): Setting { return $this->settings[SecuritySettingsRepository::STRICT_TRANSPORT_SECURITY]; } private function extractKey(Setting $setting): string { return $setting->getKey(); } private function extractSetting(string $key): Setting { return $this->settings[$key] ?? new Setting($key, ''); } private function hasMetDependencies(Setting $setting): bool { foreach (self::DEPENDENT_SETTINGS[$setting->getKey()] ?? [] as $dependencyKey => $dependencyValue) { if ($this->extractSetting($dependencyKey)->getValue() !== $dependencyValue) { return false; } } return true; } }