Skip to content

Commit

Permalink
Config class should use config constant instead of using config key #9 (
Browse files Browse the repository at this point in the history
  • Loading branch information
elie29 committed Jun 4, 2018
1 parent a2f9dfc commit 739921b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ All notable changes to this project will be documented in this file, in reverse

### Changed

- Nothing.
- [#9](https://github.com/elie29/zend-di-config/issues/9) Config class should use config constant instead of using config key.

### Deprecated

Expand All @@ -29,7 +29,7 @@ All notable changes to this project will be documented in this file, in reverse

### Added

- [#8](https://github.com/elie29/zend-di-config/issues/8) Update composer.
- [#8](https://github.com/elie29/zend-di-config/issues/8) Updated composer.
- [#7](https://github.com/elie29/zend-di-config/issues/7) Renamed test folder.

### Changed
Expand Down
10 changes: 5 additions & 5 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Config implements ConfigInterface

public function __construct(array $config)
{
$this->definitions = ['config' => $config];
$this->definitions = [$this::CONFIG => $config];
}

public function configureContainer(ContainerBuilder $builder): void
Expand All @@ -34,7 +34,7 @@ public function configureContainer(ContainerBuilder $builder): void

private function setDependencies(): void
{
$this->dependencies = $this->definitions['config']['dependencies'] ?? [];
$this->dependencies = $this->definitions[$this::CONFIG]['dependencies'] ?? [];
}

private function addDefinitions(ContainerBuilder $builder): void
Expand Down Expand Up @@ -104,14 +104,14 @@ private function addDelegators(): void

private function enableCompilation(ContainerBuilder $builder): void
{
if (! empty($this->definitions['config'][static::DI_CACHE_PATH])) {
$builder->enableCompilation($this->definitions['config'][static::DI_CACHE_PATH]);
if (! empty($this->definitions[$this::CONFIG][$this::DI_CACHE_PATH])) {
$builder->enableCompilation($this->definitions[$this::CONFIG][$this::DI_CACHE_PATH]);
}
}

private function enableCache(ContainerBuilder $builder): void
{
if (! empty($this->definitions['config'][static::ENABLE_CACHE_DEFINITION])) {
if (! empty($this->definitions[$this::CONFIG][$this::ENABLE_CACHE_DEFINITION])) {
$builder->enableDefinitionCache();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

interface ConfigInterface
{

const CONFIG = 'config';
const DI_CACHE_PATH = 'di_cache_path';
const ENABLE_CACHE_DEFINITION = 'enable_cache_definition';

Expand Down
4 changes: 2 additions & 2 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testConfigurationKeysValues()

$container = $this->getContainer($config);

$config = $container->get('config');
$config = $container->get(Config::CONFIG);

self::assertNotEmpty($config);
self::assertInstanceOf(\DateTime::class, $config['a']);
Expand All @@ -40,7 +40,7 @@ public function testConfigurationEnableCompilation()

$container = $this->getContainer($config);

$config = $container->get('config');
$config = $container->get(Config::CONFIG);

self::assertNotEmpty($config);
self::assertSame(__DIR__, $config[Config::DI_CACHE_PATH]);
Expand Down

0 comments on commit 739921b

Please sign in to comment.