-
-
Notifications
You must be signed in to change notification settings - Fork 18
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 custom exporters for enhanced features #30
Comments
Another solution would be to introduce post-config processors that are called after the cache loading for Performance wise that processor would need to $envVarsPostCachedConfigProcessor = function (array $config) {
array_walk_recursive(
$config,
function (&$value) {
// Replace '%env(EXAMPLE)%' with value of getenv('EXAMPLE')
if (is_string($value) && preg_match('{%env\(([a-zA-Z_][a-zA-Z0-9_]*)\)%}', $value, $envVars) === 1) {
$value = getenv($envVars[1]);
}
}
);
return $config;
}; |
Hi! While I understand the use case and adding an extension point does not look too difficult, I'm wondering what prevents you from creating the Basically: $data = ['bar' => fn() => getenv('FOO')];
$exported = VarExporter::export($data, VarExporter::ADD_RETURN | VarExporter::CLOSURE_SNAPSHOT_USES); You could have even have |
That wont be self calling when loaded. In my example in the initial code, there would be "bar='bar'" in my $data. So the way we use this component is to dump a large array to the fs which is then required each request. So I do want the require to then load the data via getenv. Only on mobile and thus not sure if I could point out the use case correct. So what is not possible is to have a self calling closure as it would be - self calling and thus the $data would already contain the env var rather than fetching it when using require on the dumped array file. |
Ah sorry, I know what you mean now. Indeed there is no way to do that at the moment. We could introduce an interface to allow you to bypass any exporter (I don't think there is a point in doing a custom export for scalars other than I'm thinking of something like: interface CustomExporter
{
public function export(mixed $value): ?string;
} If Two potential pain points come to mind:
|
I think, once we are going for that change, I think having dedicated exporters registered for each type would make more sense. regarding the object identity - I am unsure if that is even needed or even possible and thus I think lets see when it comes to that point, wdyt? Oh and ofc, you can pass the indentation Level as you do with ur own logic. I would keep that signatures in the interfaces tbh. |
I have a similar use case, writing Drupal settings, where i want arbitrary expressions referencing vars like I don't like the habit of magic strings like '%env' or '@ service' though, and have bad feelings with encouraging that. There are better ways, even in yaml (see custom tags). Also i don't like to put too much magic into the exporter. If magic is needed, put it into a preprocess step, and don't touch the semantics of the export data. With that opinionated approach, i created MR #32. Eager to know what you think and if this suits your use cases too. |
Hey there,
I am thinking about adding support to
laminas/laminas-config-aggregator
to actually export self calling closures.The main idea is to allow some kind of
string
which is then interpreted by the exporter in a way that it replaces that string with a self calling function:This would probably result in:
So once "importing" this data, it will always execute the callable so that the environment variable is always loaded from the environment at the time the file is being required.
As of now, this is not possible as there is no extension point of this component.
Do you think, this component would be the proper extension point to introduce such a feature or should we try to somehow work-around it in the laminas component instead?
As far as I understand #15, this component is to create data which can then be used without this component so this would actually still hold that statement I guess.
I'd really love to see this feature in here so that we can add a custom
string
exporter which would do something like:But not sure if you want this kind of complexity so see this more as a question rather than a demand :-)
Thanks for your time.
Max
The text was updated successfully, but these errors were encountered: