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

3.2.x Grouped Config #12884

Merged
merged 2 commits into from
Jun 17, 2017
Merged

Conversation

Fenikkusu
Copy link
Contributor

@Fenikkusu Fenikkusu commented Jun 7, 2017

Hello!

  • Type: new feature
  • Link to issue: NA

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the Contributing Guidelines?
  • I have checked that another pull request for this purpose does not exist.
  • I wrote some tests for this PR.

Small description of change:

Many systems use the concept of distribution config files where config.conf is added to the repo but config.dist.conf is ignored. These changes allow us to easily accomplish the same concept in Phalcon. Additionally, this leverages the existing Config Factory to allow us to combine either a specifc adapter or multiple different adapters.

$configFiles = [
  [
    'adapter' => 'ini', //This specifically uses the ini adapter.
    'filePath' => '/usr/www/conf.ini'
  ],
  __DIR__ . '/etc/config.json' //This will use the default adapter.
];

if (file_exists([__DIR__ . '/etc/config.dist.json']) {
    $configFiles[] = __DIR__ . '/etc/config.dist.json'; //This will use the default adapter.
}

$configFiles[] = [
  'adapter' => 'array', //This will use the traditional \Phalcon\Config object.
  'config'   => [
    'debug' => true
  ]
];

//Initialize Config using the Json adapter as the default.
$config = new \Phalcon\Config\Adapter\Grouped($configFiles, 'json');

Thanks

@sergeyklay sergeyklay added this to the unplanned milestone Jun 7, 2017
@sergeyklay sergeyklay added the new feature request Planned Feature or New Feature Request label Jun 7, 2017
@sergeyklay
Copy link
Contributor

Could you please update the CHANGELOG.md

* [
* [
* "filePath" => "path/to/config.php",
* "adapter" => "php""path/to/config.dist.php"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"adapter" => "php""path/to/config.dist.php" => "adapter" => "php"

//Set To Default Adapter If Passed As String
if typeof configName === "string" {
let configInstance = ["filePath" : configName, "adapter" : defaultAdapter];
} elseif !isset(configInstance["adapter"]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!isset(configInstance["adapter"]) => !isset configInstance["adapter"]

}

if configInstance["adapter"] === "array" {
if !isset(configInstance["config"]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same

* User: fenikkusu
* Date: 6/6/17
* Time: 8:05 PM
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please remove this

@Fenikkusu
Copy link
Contributor Author

Changes Applied

@sergeyklay sergeyklay merged commit 8796898 into phalcon:3.2.x Jun 17, 2017
@sergeyklay
Copy link
Contributor

Thank you

@Fenikkusu Fenikkusu deleted the 3.2.x-multi-config branch June 22, 2017 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature request Planned Feature or New Feature Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants