Skip to content

Commit

Permalink
Move stream context array in context parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Gertz committed Dec 8, 2024
1 parent 6b88d91 commit 569db7a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
10 changes: 1 addition & 9 deletions Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,7 @@ function __construct(protected ContainerInterface $container, protected ImageUti
$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']);
}

/**
Expand Down
19 changes: 19 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public function getConfigTreeBuilder(): TreeBuilder {
'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',
Expand Down Expand Up @@ -193,6 +200,18 @@ public function getConfigTreeBuilder(): TreeBuilder {
->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()
Expand Down

0 comments on commit 569db7a

Please sign in to comment.