Skip to content

Commit

Permalink
Added configProvider
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Richer [email protected] <[email protected]>
  • Loading branch information
visto9259 committed Aug 14, 2024
1 parent 22f54b6 commit 0943e71
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
],
"extra": {
"laminas": {
"module": "LmcCors"
"module": "LmcCors",
"config-provider": "LmcCors\\ConfigProvider"
}
},
"require": {
Expand Down
31 changes: 31 additions & 0 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace LmcCors;

class ConfigProvider
{
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencyConfig(),
'lmc_cors' => $this->getModuleConfig(),
];
}

public function getDependencyConfig(): array
{
return [
'factories' => [
Mvc\CorsRequestListener::class => Factory\CorsRequestListenerFactory::class,
Options\CorsOptions::class => Factory\CorsOptionsFactory::class,
Service\CorsService::class => Factory\CorsServiceFactory::class,
],
];
}

public function getModuleConfig(): array
{
return [
];
}
}
9 changes: 7 additions & 2 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ public function onBootstrap(EventInterface $e): void
/**
* {@inheritDoc}
*/
public function getConfig()
public function getConfig(): array
{
return include __DIR__ . '/../config/module.config.php';
$configProvider = new ConfigProvider();

return [
'service_manager' => $configProvider->getDependencyConfig(),
'lmc_cors' => $configProvider->getModuleConfig(),
];
}
}
18 changes: 18 additions & 0 deletions tests/ConfigProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace LmcCorsTest;

use LmcCors\ConfigProvider;
use PHPUnit\Framework\TestCase;

class ConfigProviderTest extends TestCase
{
public function testProviderExpectedConfiguration()
{
$provider = new ConfigProvider();
$config = $provider();
$this->assertArrayHasKey('dependencies', $config);
$this->assertArrayHasKey('lmc_cors', $config);
$this->assertArrayHasKey('factories', $config['dependencies']);
}
}

0 comments on commit 0943e71

Please sign in to comment.