@@ -10,11 +10,6 @@ class WorkflowLoaderServiceProvider extends PackageServiceProvider
1010{
1111 public function configurePackage (Package $ package ): void
1212 {
13- /*
14- * This class is a Package Service Provider
15- *
16- * More info: https://github.com/spatie/laravel-package-tools
17- */
1813 $ package
1914 ->name ('laravel-workflow-loader ' )
2015 ->hasConfigFile ('workflow_loader ' )
@@ -30,16 +25,41 @@ public function configurePackage(Package $package): void
3025
3126 public function packageRegistered ()
3227 {
33- $ this -> app -> when (\ Soap \ WorkflowLoader \ DatabaseLoader::class)
34- -> needs ( ' $config ' )
35- -> give ( $ this -> app -> make ( 'config ' ) ->get ('workflow_loader.loaders.database ' ) );
28+ // Register DatabaseLoader with safe config retrieval
29+ $ this -> app -> singleton (DatabaseLoader::class, function ( $ app ) {
30+ $ config = $ app[ 'config ' ] ->get ('workflow_loader.loaders.database ' , [] );
3631
37- $ this ->app ->when (\Soap \WorkflowLoader \WorkflowLoaderRegistry::class)
38- ->needs ('$loaders ' )
39- ->give ($ this ->app ->make ('config ' )->get ('workflow_loader.loaders ' ));
32+ // Provide default config if not found
33+ if (empty ($ config ) || ! isset ($ config ['tableNames ' ])) {
34+ $ config = [
35+ 'tableNames ' => [
36+ 'workflows ' => 'workflows ' ,
37+ 'workflow_states ' => 'workflow_states ' ,
38+ 'workflow_transitions ' => 'workflow_transitions ' ,
39+ 'workflow_state_transitions ' => 'workflow_state_transitions ' ,
40+ ],
41+ ];
42+ }
4043
41- $ this ->app ->bind (\Soap \WorkflowLoader \Contracts \WorkflowDatabaseLoader::class, \Soap \WorkflowLoader \DatabaseLoader::class);
44+ return new DatabaseLoader (
45+ $ config ,
46+ $ app ->make (Repositories \WorkflowRepository::class)
47+ );
48+ });
4249
43- $ this ->app ->singleton ('workflowLoaderRegistry ' , \Soap \WorkflowLoader \WorkflowLoaderRegistry::class);
50+ // Register WorkflowLoaderRegistry
51+ $ this ->app ->singleton (WorkflowLoaderRegistry::class, function ($ app ) {
52+ $ loaders = $ app ['config ' ]->get ('workflow_loader.loaders ' , []);
53+
54+ return new WorkflowLoaderRegistry ($ loaders );
55+ });
56+
57+ // Bind contracts
58+ $ this ->app ->bind (
59+ Contracts \WorkflowDatabaseLoader::class,
60+ DatabaseLoader::class
61+ );
62+
63+ $ this ->app ->singleton ('workflowLoaderRegistry ' , WorkflowLoaderRegistry::class);
4464 }
4565}
0 commit comments