Closed zawyelwin closed 4 years ago
Thanks for reaching out! It was originally never intended to switch contexts for a client instance so it has been assumed you'd have dedicated files for each context necessary.
Can you describe your scenario to help me understand the use case?
I have a config file with multiple clusters and want to loop through the clusters and check some status and grab some contents. Can u give me some suggestions on doing so ? Thanks for the response.
Ah yeah, that's an interesting use case. Probably best to add a method on the config class that iterates the various contexts. Would this hypothetical code suit your needs (generally speaking)?
foreach($config->getContexts() as $context) {
$client = new Client($context);
...
}
@zawyelwin do you intend to run stuff as '1 and done' or are you attempting to build a long-running controller?
That will be a long-running controller.
Ok sounds good. I've got this implemented in master
FYI. Got a couple more things to consider but likely in the state it will be in for the next release.
This is done and snapped in version v0.2.0
.
There are a couple different approaches you can take to the iteration process:
getParsedConfigFile()
which is an array
with a contexts
key which will have all your contexts including the name$config->useContext($contextName)
as appropriatecontextName
to public static function BuildConfigFromFile($path = null, $contextName = null)
or just creating it without params and then invoking useContext($contextName)
on each new objectIf you have any questions let me know, I think it will be pretty self-explanatory.
How Can I change the current context ?