Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow grouped config loader to determine adaptor from file extension. #13762

Merged
merged 9 commits into from
Feb 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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