Skip to content

Commit

Permalink
Allow grouped config loader to determine adaptor from file extension. (
Browse files Browse the repository at this point in the history
…#13762)

* Pass through string handling when adapter not set.

* Update changelog.

* Updated test for coverage of new feature but I doubt it conforms to standards (two tests doing one thing esspecially).

* Fix to use the right class name.

* Whitespace fix.

* Fix the build.

* Less of a handfull parameter passing.

* Switch to using empty string rather than null.
  • Loading branch information
joeyhub authored and niden committed Feb 24, 2019
1 parent 187a2a4 commit 2e85d6e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@
- Changed `Phalcon\Exception` to implement `\Throwable` interface.[#13750](https://github.com/phalcon/cphalcon/issues/13758)
- Changed `Phalcon\Http\Cookie`. The `httpOnly` property is no longer initialised with a value [#13464](https://github.com/phalcon/cphalcon/issues/13464)
- Changed the default action for no arguments of `Phalcon\Acl\Memory`to be `Acl::DENY` instead of `Acl::ALLOW` [#13769](https://github.com/phalcon/cphalcon/issues/13769)
- Changed the implementation of `Phalcon\Filter`. It uses a service locator and a service locator factory now. It has more sanitizers now. [#13060](https://github.com/phalcon/cphalcon/issues/13060)
- Changed handling of `Phalcon\Config\Adapter\Grouped::_construct()` when receiving an configuration file as a string from the `arrayConfig` parameter
to automatically attempt and the parameter `defaultAdapter` is set to an empty string, to determine the adapter from the file extension,
producing the same behaviour as `Phalcon\Config\Factory::load()` [#13762](https://github.com/phalcon/cphalcon/pull/13762)

## Removed
- Removed `Phalcon\Mvc\User\Component`, `Phalcon\Mvc\User\Module` and `Phalcon\Mvc\User\Plugin` [#13749](https://github.com/phalcon/cphalcon/pull/13749)
Expand Down
5 changes: 5 additions & 0 deletions phalcon/config/adapter/grouped.zep
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ class Grouped extends Config

// Set to default adapter if passed as string
if typeof configName === "string" {
if defaultAdapter === "" {
this->_merge(Factory::load(configName));
continue;
}

let configInstance = ["filePath" : configName, "adapter" : defaultAdapter];
} elseif !isset configInstance["adapter"] {
let configInstance["adapter"] = defaultAdapter;
Expand Down
31 changes: 16 additions & 15 deletions tests/unit/Config/Adapter/Grouped/ConstructCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,25 @@ public function configAdapterGroupedConstructComplexInstance(UnitTester $I)
$I->wantToTest("Config\Adapter\Grouped - construct - complex");
$this->config["test"]["property2"] = "something-else";

$config = new Grouped(
$config = [
dataFolder('assets/config/config.php'),
[
dataFolder('assets/config/config.php'),
[
'filePath' => dataFolder('assets/config/config.json'),
'adapter' => 'json',
],
[
'adapter' => 'array',
'config' => [
"test" => [
"property2" => "something-else",
],
'filePath' => dataFolder('assets/config/config.json'),
'adapter' => 'json',
],
[
'adapter' => 'array',
'config' => [
"test" => [
"property2" => "something-else",
],
],
]
);
$this->compareConfig($I, $this->config, $config);
],
];

foreach ([[], ['']] as $parameters) {
$this->compareConfig($I, $this->config, new Grouped($config, ...$parameters));
}
}

/**
Expand Down

0 comments on commit 2e85d6e

Please sign in to comment.