<commit_before><?php
declare(strict_types = 1);

namespace Spaze\ContentSecurityPolicy\Bridges\Nette;

/**
 * ContentSecurityPolicy\Config extension.
 *
 * @author <NAME>
 */
class ConfigExtension extends \Nette\DI\CompilerExtension
{

	public function loadConfiguration(): void
	{
		$config = $this->getConfig();
		$builder = $this->getContainerBuilder();

		$cspConfig = $builder->addDefinition($this->prefix('config'))
			->setClass('Spaze\ContentSecurityPolicy\Config')
			->addSetup('setPolicy', array($config['policies'] ?? []))
			->addSetup('setSnippets', array($config['snippets'] ?? []));

		if ($config['supportLegacyBrowsers'] ?? false) {
			$cspConfig->addSetup('supportLegacyBrowsers');
		}
	}

}<commit_msg>Let's also validate config options<commit_after><?php
declare(strict_types = 1);

namespace Spaze\ContentSecurityPolicy\Bridges\Nette;

/**
 * ContentSecurityPolicy\Config extension.
 *
 * @author <NAME>
 */
class ConfigExtension extends \Nette\DI\CompilerExtension
{

	private $defaults = array(
		'snippets' => [],
		'policies' => [],
		'supportLegacyBrowsers' => false,
	);


	public function loadConfiguration(): void
	{
		$this->validateConfig($this->defaults);

		$builder = $this->getContainerBuilder();

		$cspConfig = $builder->addDefinition($this->prefix('config'))
			->setClass('Spaze\ContentSecurityPolicy\Config')
			->addSetup('setPolicy', array($this->config['policies']))
			->addSetup('setSnippets', array($this->config['snippets']));

		if ($this->config['supportLegacyBrowsers']) {
			$cspConfig->addSetup('supportLegacyBrowsers');
		}
	}

}
{'fraction_non_alphanumeric': 0.1781427668982944, 'fraction_numerical': 0.0012634238787113076, 'mean_word_length': 5.65546218487395, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1771208', 'n_tokens_mistral': 539, 'n_tokens_neox': 493, 'n_words': 73}