Permalink
Browse files

[SymfonyDI] configuration fixes

  • Loading branch information...
TomasVotruba committed Jun 9, 2017
1 parent 2e13e37 commit 3f328101f5ee3e69701f50af47f55599d4f9d566
View
@@ -0,0 +1,4 @@
parameters:
title: "ApiGen It-self"
visibilityLevels: [public, protected]
baseUrl: http://apigen.org
@@ -7,5 +7,5 @@
/**
* @return mixed[]
*/
public function provide(): array;
public function provide();
}
@@ -4,28 +4,31 @@
use ApiGen\ModularConfiguration\Contract\Parameter\ParameterProviderInterface;
use Nette\DI\Container;
use Nette\Utils\Strings;
use Symfony\Component\DependencyInjection\Container as SymfonyContainer;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
final class ParameterProvider implements ParameterProviderInterface
{
/**
* @var mixed[]|ParameterBagInterface
* @var mixed[]
*/
private $parameters = [];
public function __construct(?SymfonyContainer $symfonyContainer = null, ?Container $netteContainer = null)
public function __construct(SymfonyContainer $symfonyContainer, ?Container $netteContainer = null)
{
if ($symfonyContainer !== null) {
$this->parameters = $symfonyContainer->getParameterBag();
$containerParameters = $symfonyContainer->getParameterBag()->all();
$this->parameters = $this->unsetSymfonyDefaultParameters($containerParameters);
} elseif ($netteContainer !== null) {
$containerParameters = $netteContainer->getParameters();
$this->parameters = $this->unsedNetteDefaultParameters($containerParameters);
$this->parameters = $this->unsetNetteDefaultParameters($containerParameters);
}
}
/**
* @return mixed[]|ParameterBagInterface
* @return mixed[]
*/
public function provide(): array
{
@@ -36,7 +39,7 @@ public function provide(): array
* @param mixed[] $containerParameters
* @return mixed[]
*/
private function unsedNetteDefaultParameters(array $containerParameters): array
private function unsetNetteDefaultParameters(array $containerParameters): array
{
unset(
$containerParameters['appDir'], $containerParameters['wwwDir'],
@@ -46,4 +49,18 @@ private function unsedNetteDefaultParameters(array $containerParameters): array
return $containerParameters;
}
/**
* @param mixed[] $containerParameters
* @return mixed[]
*/
private function unsetSymfonyDefaultParameters(array $containerParameters): array
{
foreach ($containerParameters as $name => $value) {
if (Strings::startsWith($name, 'kernel')) {
unset ($containerParameters[$name]);
}
}
return $containerParameters;
}
}
@@ -47,7 +47,14 @@ public function resolveOptions(array $options): array
$configParameters = $this->parameterProvider->provide();
$options = array_merge($configParameters, $options);
return $this->options = $this->configurationResolver->resolveValuesWithDefaults($options);
$resolvedOptions = $this->configurationResolver->resolveValuesWithDefaults($options);
// hack to remove duplicated lowercased value
unset ($resolvedOptions[strtolower(VisibilityLevelOption::NAME)]);
$resolvedOptions[BaseUrlOption::NAME] = $resolvedOptions[strtolower(BaseUrlOption::NAME)];
unset ($resolvedOptions[strtolower(BaseUrlOption::NAME)]);
return $this->options = $resolvedOptions;
}
/**
@@ -10,6 +10,11 @@
final class AppKernel extends Kernel
{
/**
* @var string
*/
private const CONFIG_NAME = 'apigen.yml';
public function __construct()
{
parent::__construct('dev',true);
@@ -18,6 +23,11 @@ public function __construct()
public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(__DIR__ . '/../config/services.yml');
$localConfig = getcwd() . '/' . self::CONFIG_NAME;
if (file_exists($localConfig)) {
$loader->load($localConfig);
}
}
/**
View
@@ -7,6 +7,9 @@ services:
Symfony\Component\Console\Application: ~
ApiGen\Application\ApiGenApplication: ~
ApiGen\ModularConfiguration\Parameter\ParameterProvider:
arguments: ['@service_container']
# 3rd party services (cannot be autowired)
Symfony\Component\Console\Output\ConsoleOutput: ~
@@ -33,15 +33,17 @@ public function testResolve(): void
DestinationOption::NAME => TEMP_DIR
]);
$this->assertCount(8, $options);
$this->assertSame([
TitleOption::NAME => 'ApiGen It-self',
VisibilityLevelOption::NAME => 768,
BaseUrlOption::NAME => 'http://apigen.org',
SourceOption::NAME => [],
DestinationOption::NAME => TEMP_DIR,
AnnotationGroupsOption::NAME => [],
BaseUrlOption::NAME => 'http://apigen.org',
OverwriteOption::NAME => false,
ThemeDirectoryOption::NAME => realpath(__DIR__ . '/../../packages/ThemeDefault/src'),
VisibilityLevelOption::NAME => 768,
], $options);
}

0 comments on commit 3f32810

Please sign in to comment.