From: Raphaƫl Gertz <git@rapsys.eu>
Date: Sun, 8 Dec 2024 05:27:25 +0000 (+0100)
Subject: Move stream context array in context parameter
X-Git-Tag: 0.5.4~8
X-Git-Url: https://git.rapsys.eu/packbundle/commitdiff_plain/569db7a24c07ddc92ca69be46ae6a90d3c0d04a8

Move stream context array in context parameter
---

diff --git a/Controller.php b/Controller.php
index 148d37c..77a3e14 100644
--- a/Controller.php
+++ b/Controller.php
@@ -63,15 +63,7 @@ class Controller extends AbstractController implements ServiceSubscriberInterfac
 		$this->config = $container->getParameter($this->alias = RapsysPackBundle::getAlias());
 
 		//Set ctx
-		$this->ctx = stream_context_create(
-			[
-				'http' => [
-					'max_redirects' => $_ENV['RAPSYSPACK_REDIRECT'] ?? 20,
-					'timeout' => $_ENV['RAPSYSPACK_TIMEOUT'] ?? (($timeout = ini_get('default_socket_timeout')) !== false && $timeout !== '' ? (float)$timeout : 60),
-					'user_agent' => $_ENV['RAPSYSPACK_AGENT'] ?? (($agent = ini_get('user_agent')) !== false && $agent !== '' ? (string)$agent : $this->alias.'/'.($this->version = RapsysPackBundle::getVersion()))
-				]
-			]
-		);
+		$this->ctx = stream_context_create($this->config['context']);
 	}
 
 	/**
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 8f3beb2..af0c83e 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -50,6 +50,13 @@ class Configuration implements ConfigurationInterface {
 				'thickness' => 2,
 				'width' => 192
 			],
+			'context' => [
+				'http' => [
+					'max_redirects' => $_ENV['RAPSYSPACK_REDIRECT'] ?? 20,
+					'timeout' => $_ENV['RAPSYSPACK_TIMEOUT'] ?? (($timeout = ini_get('default_socket_timeout')) !== false && $timeout !== '' ? (float)$timeout : 60),
+					'user_agent' => $_ENV['RAPSYSPACK_AGENT'] ?? (($agent = ini_get('user_agent')) !== false && $agent !== '' ? (string)$agent : $alias.'/'.($version = RapsysPackBundle::getVersion()))
+				]
+			],
 			'facebook' => [
 				'align' => 'center',
 				'fill' => 'white',
@@ -193,6 +200,18 @@ class Configuration implements ConfigurationInterface {
 							->scalarNode('width')->cannotBeEmpty()->defaultValue($defaults['captcha']['width'])->end()
 						->end()
 					->end()
+					->arrayNode('context')
+						->addDefaultsIfNotSet()
+						->children()
+							->arrayNode('http')
+							->addDefaultsIfNotSet()
+							->children()
+								->scalarNode('max_redirects')->defaultValue($defaults['captcha']['max_redirects'])->end()
+								->scalarNode('timeout')->defaultValue($defaults['captcha']['timeout'])->end()
+								->scalarNode('user_agent')->cannotBeEmpty()->defaultValue($defaults['captcha']['user_agent'])->end()
+							->end()
+						->end()
+					->end()
 					->arrayNode('facebook')
 						->addDefaultsIfNotSet()
 						->children()