Skip to content

Commit

Permalink
Making the headers configurabel
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankraemer committed Mar 28, 2024
1 parent 9232c2f commit e2da806
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 45 deletions.
30 changes: 15 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
services:
Phauthentic\CorrelationIdBundle\EventSubscriber\CorrelationIdSubscriber:
arguments:
$config: '%correlation_id%'
$config:
response_header_name: '%correlation_id.response_header_name%'
request_header_name: '%correlation_id.request_header_name%'
pass_through: '%correlation_id.pass_through%'
tags:
- { name: 'kernel.event_subscriber' }
36 changes: 18 additions & 18 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="tests/bootstrap.php" cacheDirectory=".phpunit.cache">
<php>
<ini name="display_errors" value="1"/>
<ini name="error_reporting" value="-1"/>
<server name="APP_ENV" value="test" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
<server name="SYMFONY_PHPUNIT_VERSION" value="10.5.15"/>
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<php>
<ini name="display_errors" value="1"/>
<ini name="error_reporting" value="-1"/>
<server name="APP_ENV" value="test" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
<server name="SYMFONY_PHPUNIT_VERSION" value="10.5.15"/>
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
5 changes: 3 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('correlation_id');

/* @phpstan-ignore-next-line */
$treeBuilder->getRootNode()
->children()
->booleanNode('passthrough')
->children()
->booleanNode('pass_through')
->defaultValue(false)
->end()
->scalarNode('response_header_name')
Expand Down
14 changes: 7 additions & 7 deletions src/DependencyInjection/CorrelationIdExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ class CorrelationIdExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$container->setParameter('correlation_id.request_header_name', $config['response_header_name']);
$container->setParameter('correlation_id.response_header_name', $config['response_header_name']);
$container->setParameter('correlation_id.pass_through', $config['pass_through']);

$yamlLoader = new Loader\YamlFileLoader(
$container,
new FileLocator(__DIR__ . '/../../config')
);

$yamlLoader->load('services.yaml');

$configuration = new Configuration();

$config = $this->processConfiguration($configuration, $configs);

$container->setParameter('correlation_id.request_header_name', $config['response_header_name']);
$container->setParameter('correlation_id.response_header_name', $config['response_header_name']);
}
}
4 changes: 2 additions & 2 deletions src/EventSubscriber/CorrelationIdSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public function __construct(array $config = [])
$this->responseHeaderName = (string)$config['response_header_name'];
}

if (isset($config['response_header_name'])) {
$this->passthrough = (bool)$config['passthrough'];
if (isset($config['pass_through'])) {
$this->passthrough = (bool)$config['pass_through'];
}
}

Expand Down

0 comments on commit e2da806

Please sign in to comment.