Skip to content

Commit

Permalink
Allow to configure test/sandbox environment
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Aug 8, 2024
1 parent 0c63662 commit bb2e586
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ public function getConfigTreeBuilder(): TreeBuilder
$rootNode
->addDefaultsIfNotSet()
->children()
->scalarNode('api_key')
->defaultValue('%env(PEAK_WMS_API_KEY)%')
->cannotBeEmpty()
->arrayNode('api')
->addDefaultsIfNotSet()
->children()
->booleanNode('sandbox')
->defaultValue('%kernel.debug%')
->end()
->scalarNode('api_key')
->defaultValue('%env(PEAK_WMS_API_KEY)%')
->cannotBeEmpty()
;

$this->addResourcesSection($rootNode);
Expand Down
5 changes: 3 additions & 2 deletions src/DependencyInjection/SetonoSyliusPeakExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function load(array $configs, ContainerBuilder $container): void
/**
* @psalm-suppress PossiblyNullArgument
*
* @var array{api_key: string, resources: array} $config
* @var array{ api: array{ sandbox: bool, api_key: string }, resources: array } $config
*/
$config = $this->processConfiguration($this->getConfiguration([], $container), $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
Expand All @@ -38,7 +38,8 @@ public function load(array $configs, ContainerBuilder $container): void
->addTag('setono_sylius_peak.webhook_handler')
;

$container->setParameter('setono_sylius_peak.api_key', $config['api_key']);
$container->setParameter('setono_sylius_peak.api.sandbox', $config['api']['sandbox']);
$container->setParameter('setono_sylius_peak.api.api_key', $config['api']['api_key']);

$this->registerResources(
'setono_sylius_peak',
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/config/services/client.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<service id="Setono\PeakWMS\Client\ClientInterface" alias="Setono\PeakWMS\Client\Client"/>

<service id="Setono\PeakWMS\Client\Client">
<argument>%setono_sylius_peak.api_key%</argument>
<argument>%setono_sylius_peak.api.api_key%</argument>

<call method="setLogger">
<argument type="service" id="logger"/>
</call>
<call method="useSandbox">
<argument>%kernel.debug%</argument>
<argument>%setono_sylius_peak.api.sandbox%</argument>
</call>
</service>
</services>
Expand Down

0 comments on commit bb2e586

Please sign in to comment.