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

Load Config from Database #29

Open
Yarandi opened this issue Jun 11, 2018 · 7 comments
Open

Load Config from Database #29

Yarandi opened this issue Jun 11, 2018 · 7 comments

Comments

@Yarandi
Copy link

Yarandi commented Jun 11, 2018

Hi,
I'm using Laravel 5.6,
How can i fill transitions config from database?
I want to save my transitions on database and fill config file from that?
Is it possible to load a model in an anonymous function?

Thanks in advance

@dezashibi
Copy link

@brexis Hi man, I'm also searching for this, I tried to override the service provider but didn't worked, you know the thing I want to do is to tell the workflowRegistry to check if the workflowData is an array or a closure, so that if it's a closure it would run it and get the returned data, I did that in the main package files and it worked, now I want to have it on my application folder to override your package to make it available after composer update command.

@brexis
Copy link
Owner

brexis commented Jun 13, 2018

Hi guys.
@Yarandi I'm not sure that database config will be loaded before Workflow config.
@dezashibi I was checking if this is possible and I was wondering if this change will break how the config cache works https://laravel.com/docs/5.6/configuration#configuration-caching

@dezashibi
Copy link

@brexis Hey dude, thank you for answering.
well I could manage to override WorkflowRegistry.php to make it interact with workflow key in config file as a function if the type is not array.
but I think it can be even better, you know, the workflow system can be good enough if we will be able to load workflows by sending arrays, and being able to create as many instance as we want from the Workflow class

@brexis
Copy link
Owner

brexis commented Aug 19, 2019

hi @dezashibi Can you please share an example of how it would work?

@dezashibi
Copy link

dezashibi commented Aug 19, 2019

@brexis
Hey man, it's for almost a year ago,
I remember it was something like the code below that I've changed in WorkflowRegistry.php

public function __construct(array $config)
  {
    $this->registry = new Registry();
    $this->config = $config;
    $this->dispatcher = new EventDispatcher();
    $subscriber = new WorkflowSubscriber();
    $this->dispatcher->addSubscriber($subscriber);
    foreach ($this->config as $name => $workflowData) {
      $workflowData = gettype($workflowData) != 'array' ? $workflowData() : $workflowData;
      $this->addFromArray($name, $workflowData);
    }
  }

this helps to have closure function instead of array for config which in it we can make queries and get data from DB for example structure of transactions, etc.
This is what I did, as I remembered. hope it helped

@brexis
Copy link
Owner

brexis commented Aug 19, 2019

Sorry for the delay. I see. I think it doable. Will be able to work on it. Thank you.

@dezashibi
Copy link

@brexis
Don’t mention it, glad it helped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants