Generate CSP header.

@param array $config

@return array
480661
public static function getCSPHeader(array $config): array
    {
        $directives = [
            'default-src',
            'base-uri',
            'connect-src',
            'font-src',
            'form-action',
            'frame-ancestors',
            'frame-src',
            'img-src',
            'manifest-src',
            'media-src',
            'object-src',
            'plugin-types',
            'require-sri-for',
            'sandbox',
            'script-src',
            'style-src',
            'worker-src',
        ];

        $headers = [];

        foreach ($directives as $directive) {
            if (isset($config[$directive])) {
                $headers[] = self::compileDirective($directive, $config[$directive]);
            }
        }

        if (! empty($config['block-all-mixed-content'])) {
            $headers[] = 'block-all-mixed-content';
        }

        if (! empty($config['upgrade-insecure-requests'])) {
            $headers[] = 'upgrade-insecure-requests';
        }

        if (! empty($config['report-uri'])) {
            $headers[] = sprintf('report-uri %s', $config['report-uri']);
        }

        $key = ! empty($config['report-only'])
            ? 'Content-Security-Policy-Report-Only'
            : 'Content-Security-Policy';

        return [$key => implode('; ', array_filter($headers, 'strlen'))];
    }
737115
public static function getFeaturePolicyHeader(array $config): array
    {
        $directives = [
            'accelerometer',
            'ambient-light-sensor',
            'autoplay',
            'camera',
            'encrypted-media',
            'fullscreen',
            'geolocation',
            'gyroscope',
            'magnetometer',
            'microphone',
            'midi',
            'payment',
            'picture-in-picture',
            'speaker',
            'sync-xhr',
            'usb',
            'var',
        ];

        foreach ($directives as $directive) {
            if (! isset($config[$directive]) || empty($config[$directive])) {
                continue;
            }

            $value = '';

            if ($config[$directive]['none']) {
                $value = "'none'";
            } elseif ($config[$directive]['*']) {
                $value = '*';
            } else {
                if ($config[$directive]['self']) {
                    $value = "'self'";
                }

                foreach ($config[$directive]['allow'] as $url) {
                    if (false !== ($url = filter_var($url, FILTER_SANITIZE_URL))) {
                        $value = sprintf('%s %s', $value, $url);
                    }
                }
            }

            if (strlen($value = trim($value)) > 0) {
                $headers[] = sprintf('%s %s', $directive, $value);
            }
        }

        if (! isset($headers)) {
            return [];
        }

        return ['Feature-Policy' => implode('; ', $headers)];
    }
899813
public static function init($config = [])
    {
        $config = array_merge([
            'accepts' => [],
            'appendTo' => 'body',
            'showBar' => false,
            'editor' => Debugger::$editor,
            'maxDepth' => Debugger::$maxDepth,
            'maxLength' => Debugger::$maxLength,
            'scream' => true,
            'showLocation' => true,
            'strictMode' => true,
            'currentTime' => $_SERVER['REQUEST_TIME_FLOAT'] ?: microtime(true),
            'editorMapping' => isset(Debugger::$editorMapping) === true ? Debugger::$editorMapping : [],
        ], $config);

        Debugger::$editor = $config['editor'];
        Debugger::$maxDepth = $config['maxDepth'];
        Debugger::$maxLength = $config['maxLength'];
        Debugger::$scream = $config['scream'];
        Debugger::$showLocation = $config['showLocation'];
        Debugger::$strictMode = $config['strictMode'];
        Debugger::$time = $config['currentTime'];

        if (isset(Debugger::$editorMapping) === true) {
            Debugger::$editorMapping = $config['editorMapping'];
        }

        return $config;
    }
268821
public function generate(Config $config)
    {
        $parts = array();
        if ($config->parent) {
            $parent = $config->parent->isRepresentant() ? $config->parent->parent : $config->parent;
            $parts[] = $this->generate($parent);
        }

        $parts[] = $this->getPrefix($config);

        return implode('_', array_filter($parts));
    }
1266356
public function build(array $config)
    {
        // Fix path in output dir
        $config['output_dir'] = $this->normalizePath($config['output_dir']);
        $config['output_dir'] = trim($config['output_dir'], DIRECTORY_SEPARATOR);
        if (!strlen($config['output_dir'])) {
            unset($config['output_dir']);
        }
        $output = array();
        if (in_array($config['less_filter'], array('sass', 'scssphp'))) {
            $output += $this->buildCssWithSass($config);
        } elseif ('none' !== $config['less_filter']) {
            $output += $this->buildCssWithLess($config);
        } else {
            $output += $this->buildCss($config);
        }

        $output['bootstrap_css']['output'] = $this->normalizePath(isset($config['output_dir']) ? array($config['output_dir'], 'css/bootstrap.css') : 'css/bootstrap.css');
        if ($config['font_awesome']) {
            $output['font_awesome_css']['output'] = $this->normalizePath(isset($config['output_dir']) ? array($config['output_dir'], 'css/font-awesome.css') : 'css/font-awesome.css');
        }
        $output += $this->buildJs($config);
        return $output;
    }
820021
private function buildHostname(array $config): string
    {
        if (isset($config['cluster'])) {
            foreach ($config['cluster']['nodes'] as $node) {
                $nodes[] = sprintf(
                    '%s:%s',
                    $node['host'] ?? '127.0.0.1',
                    $node['port'] ?? 27017
                );
            }

            return implode(',', $nodes ?? ['127.0.0.1:27017']);
        }

        return sprintf(
            '%s:%s',
            $config['host'] ?? '127.0.0.1',
            $config['port'] ?? 27017
        );
    }
242010
private function buildHorizontalConfig(array $config): array
    {
        $horizontalConfig = $this->environment->getConfig()->get('form.layouts.horizontal.classes', []);

        foreach (['row', 'label', 'control', 'offset'] as $key) {
            if (!empty($config['bs_' . $key])) {
                $horizontalConfig[$key] = $config['bs_' . $key];
            }
        }

        return $horizontalConfig;
    }
872546
public static function config($config = []) {
		if (!$config) {
			return ['rules' => static::$_rules];
		}
		foreach ($config as $key => $val) {
			if (isset(static::${'_' . $key})) {
				static::${'_' . $key} = $val + static::${'_' . $key};
			}
		}
	}
1281863
private function prepareUploadConfig(Config $config)
    {
        $options = [];

        if (isset($this->config['encrypt']) && $this->config['encrypt']) {
            $options['params']['ServerSideEncryption'] = 'AES256';
        }

        if ($config->has('params')) {
            $options['params'] = $config->get('params');
        }

        if ($config->has('visibility')) {
            $options['params']['ACL'] = $this->normalizeVisibility($config->get('visibility'));
        }

        return $options;
    }
896808
public function generate(array $config)
    {
        $defaultHTTPCodes = $this->getDefaultHTTPCodes($config);
        $defaultOptions = $this->getDefaultOptions($config);

        return $this->createUrlChainFromConfig(
            $config,
            $defaultHTTPCodes,
            $defaultOptions
        );
    }
896487
protected function generateConfigContent(array $config)
    {
        /* This code is taken from ZF2s' classmap_generator.php script. */

        // Create a file with the class/file map.
        // Stupid syntax highlighters make separating < from PHP declaration necessary
        $content = '<' . "?php\n"
                   . "\n"
                   . 'return ' . var_export($config, true) . ';';

        // Fix \' strings from injected DIRECTORY_SEPARATOR usage in iterator_apply op
        $content = str_replace("\\'", "'", $content);


        // Remove unnecessary double-backslashes
        $content = str_replace('\\\\', '\\', $content);

        // Exchange "array (" width "array("
        $content = str_replace('array (', 'array(', $content);

        // Make the file end by EOL
        $content = rtrim($content, "\n") . "\n";

        var_export($config, true);

        return $content;
    }
388271
private function generateArray(array $config)
    {
        ++$this->indent;

        foreach ($config as $key => $value) {
            if (is_null($value)) {
                if (is_string($key)) {
                    $this->writeLine(sprintf("'%s' => %s,", $key, 'null'));
                } else {
                    $this->writeLine(sprintf('%s,', 'null'));
                }
            } elseif (is_bool($value)) {
                if (is_string($key)) {
                    $this->writeLine(sprintf("'%s' => %s,", $key, $value ? 'true' : 'false'));
                } else {
                    $this->writeLine(sprintf('%s,', $value ? 'true' : 'false'));
                }
            } elseif (is_string($value)) {
                if (is_string($key)) {
                    $this->writeLine(sprintf("'%s' => '%s',", $key, $value));
                } else {
                    $this->writeLine(sprintf("'%s',", $value));
                }
            } elseif (is_array($value)) {
                if (is_string($key)) {
                    $this->writeLine(sprintf("'%s' => [", $key));
                } else {
                    $this->writeLine('[');
                }

                $this->generateArray($value);

                $this->writeLine('],');
            } elseif ($value instanceof ClassName) {
                if (is_string($key)) {
                    $this->writeLine(sprintf("'%s' => %s,", $key, (string) $value));
                } else {
                    $this->writeLine(sprintf('%s,', (string) $value));
                }
            } else {
                if (is_string($key)) {
                    $this->writeLine(sprintf("'%s' => %s,", $key, $value));
                } else {
                    $this->writeLine($value.',');
                }
            }
        }

        --$this->indent;
    }
848691
public function build(array $config)
    {
        $output = [];

        // Fix path in output dir
        if ('/' !== substr($config['output_dir'], -1) && strlen($config['output_dir']) > 0) {
            $config['output_dir'] .= '/';
        }

        $output['helper_css'] = $this->buildCss($config);

        return $output;
    }
496436
protected function parseConfig(array $config): array
    {
        $result = [];
        foreach ($config as $key => $type) {
            if (\is_array($type)) {
                if ($arrayOfType = $this->factory->checkArrayOfType($type)) {
                    $result[$key] = $arrayOfType;
                } else {
                    $result[$key] = new self($type, $this->factory, $this->strict);
                }
            } elseif ($type instanceof CastInterface) {
                $result[$key] = $type;
            } else {
                $result[$key] = $this->factory->createType($type);
            }
        }

        return $result;
    }
958420
public function make(array $config)
    {
        Arr::requires($config, ['token']);

        $client = new Client();

        return new PagerdutyGateway($client, $config);
    }
510034
protected function createReadWriteConnection(array $config)
    {
        $connection = $this->createSingleConnection($this->getWriteConfig($config));

        return $connection->setReadPdo($this->createReadPdo($config));
    }
456427
public static function buildConfig($config = array())
    {
        $default = static::getDefaultParameters();
        $required = static::getRequiredParameters();
        $config = Collection::fromConfig($config, $default, $required);

        $standardHeaders = array(
            'Accept-Charset' => 'utf-8',
            'Accept'         => 'application/json',
        );

        $requestOptions = array(
            'headers' => $standardHeaders,
        );

        $config->add('request.options', $requestOptions);

        return $config;
    }