-
Notifications
You must be signed in to change notification settings - Fork 137
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
Use case for PHP config return callable? #46
Comments
I guess a use-case would be if you wanted to determine certain config parameters ahead-of-time, say you want to check for an extension, and then set a config value to true or false. What kind of parameter would you pass into it? |
I'm not sure what you could pass through, as I'm not actually sure what's available at that point. But looking at it, there doesn't seem to be any benefit as for example ... <?php
// do some logic
if ($something) {
$value = 'x';
else {
$value = 'y';
}
return [
'conditional_config' => $value
]; or <?php
return function () {
// do some logic
if ($something) {
$value = 'x';
else {
$value = 'y';
}
return [
'conditional_config' => $value
];
}; I'm pretty sure these would have the same outcome. maybe if it was more like this I would see a benefit, but I'm not entirely sure how this would be implemented or what benefit it would have. <?php
return function ($currentConfig) {
// do some logic
if ($currentConfig->get('something')) {
$value = 'x';
else {
$value = 'y';
}
return [
'conditional_config' => $value
];
}; |
Hmm, actually you do make a very good point. I'm not sure how many people use callable functions as their config packages, I've personally never used them. What would you recommend we should do? |
Regardless if many people are using it, it is still a BC break so would need a major version bump if removed. Looking at Packagist there's currently been 6,000+ installs any of which could be dependant on this functionality. I'd probably say create a |
Yep, sounds fair. I do have an idea for a potential use-case: say I'm loading multiple files, perhaps I want to check the current config before I set any values. In that case, the current config could be passed over to the new config callable. Does that sound acceptable? |
Yup that sounds like a fair use case, although at a glance I'm not sure how easy it would be to implement. Maybe at this point passing |
Yep, that's exactly what I was thinking |
Looked into this a bit more. Passing it through as mentioned works fine. But the more I look at it I question the use case. Config is ideally static data so doing conditional logic based on currently loaded data seems out of scope. Let me know what you think. |
To be completely honest, I agree, it is kind of out-of-scope. I'd leave it as-is for now, and we can revisit it for a potential 1.x release at some point |
You can do this with https://github.com/samrap/gestalt by defining custom loaders. Closure and class based loaders are supported: $config = Configuration::load(function() {
$items = parse_ini_file('config/app.ini', true);
return $items;
}); $config = Configuration::load(new IniDirectoryLoader); |
…alex/write-ini-file-2.0.1 Bump magicalex/write-ini-file from 1.2.4 to 2.0.1
Just creating this issue based on PR 43 😄
I'm not sure what the benefit is to being able to return a callable when including the PHP config. We would be able to do any logic within the file before returning an array.
Personally the only time I can see this being valid is if we was going to pass a param in when invoking.
Obviously changing this would break BC so not a major issue with keeping it in, was just wondering what the use case would be.
The text was updated successfully, but these errors were encountered: