File tree Expand file tree Collapse file tree 13 files changed +121
-86
lines changed Expand file tree Collapse file tree 13 files changed +121
-86
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
3
return [
4
- 'databaseLoader ' => [
5
- 'tableNames ' => [
6
- 'workflows ' => 'workflows ' ,
7
- 'workflow_states ' => 'workflow_states ' ,
8
- 'workflow_transitions ' => 'workflow_transitions ' ,
9
- 'workflow_state_transitions ' => 'workflow_state_transitions ' ,
4
+ 'loaders ' => [
5
+ 'database ' => [
6
+ 'tableNames ' => [
7
+ 'workflows ' => 'workflows ' ,
8
+ 'workflow_states ' => 'workflow_states ' ,
9
+ 'workflow_transitions ' => 'workflow_transitions ' ,
10
+ 'workflow_state_transitions ' => 'workflow_state_transitions ' ,
11
+ ],
12
+ 'class ' => \Soap \WorkflowLoader \DatabaseLoader::class,
10
13
],
11
- 'loaderClass ' => \Soap \WorkflowLoader \DatabaseLoader::class,
12
14
],
13
15
];
Original file line number Diff line number Diff line change 8
8
{
9
9
public function up ()
10
10
{
11
- Schema::create ('workflows ' , function (Blueprint $ table ) {
11
+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowTableName ();
12
+ Schema::create ($ tableName , function (Blueprint $ table ) {
12
13
$ table ->id ();
13
14
$ table ->string ('name ' );
14
- $ table ->string ( ' marking_store_attribute ' )->nullable ()->comment ('name of marking store attribute ' );
15
+ $ table ->text ( ' marking_store ' )->nullable ()->comment ('marking store as array ' );
15
16
$ table ->string ('type ' )->default ('workflow ' )->comment ('workflow or state_machine ' );
16
17
$ table ->text ('description ' )->nullable ();
17
18
$ table ->json ('supports ' )->nullable ()->comment ('support models ' );
18
19
$ table ->json ('metadata ' )->nullable ()->comment ('metadata ' );
20
+ $ table ->boolean ('active ' )->default (true );
19
21
$ table ->timestamps ();
20
22
});
21
23
}
22
24
23
25
public function down ()
24
26
{
25
- Schema::dropIfExists ('workflows ' );
27
+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowTableName ();
28
+ Schema::dropIfExists ($ tableName );
26
29
}
27
30
};
Original file line number Diff line number Diff line change 8
8
{
9
9
public function up ()
10
10
{
11
- Schema::create ('workflow_states ' , function (Blueprint $ table ) {
11
+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowStateTableName ();
12
+ Schema::create ($ tableName , function (Blueprint $ table ) {
12
13
$ table ->id ();
13
14
$ table ->string ('name ' );
14
15
$ table ->tinyInteger ('initial_state ' )->default (0 )->comment ('initial state ' );
@@ -21,6 +22,7 @@ public function up()
21
22
22
23
public function down ()
23
24
{
24
- Schema::dropIfExists ('workflow_states ' );
25
+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowStateTableName ();
26
+ Schema::dropIfExists ($ tableName );
25
27
}
26
28
};
Original file line number Diff line number Diff line change 8
8
{
9
9
public function up ()
10
10
{
11
- Schema::create ('workflow_transitions ' , function (Blueprint $ table ) {
11
+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowTransitionTableName ();
12
+ Schema::create ($ tableName , function (Blueprint $ table ) {
12
13
$ table ->id ();
13
14
$ table ->string ('name ' );
14
15
$ table ->foreignId ('to_state_id ' )->constrained ('workflow_states ' )->onDelete ('cascade ' );
@@ -20,6 +21,7 @@ public function up()
20
21
21
22
public function down ()
22
23
{
23
- Schema::dropIfExists ('workflow_transitions ' );
24
+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowTransitionTableName ();
25
+ Schema::dropIfExists ($ tableName );
24
26
}
25
27
};
Original file line number Diff line number Diff line change 8
8
{
9
9
public function up ()
10
10
{
11
- Schema::create ('workflow_state_transitions ' , function (Blueprint $ table ) {
11
+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowStateTransitionTableName ();
12
+ Schema::create ($ tableName , function (Blueprint $ table ) {
12
13
$ table ->id ();
13
14
$ table ->foreignId ('workflow_transition_id ' )->constrained ('workflow_transitions ' )->onDelete ('cascade ' );
14
15
$ table ->foreignId ('from_state_id ' )->constrained ('workflow_states ' )->onDelete ('cascade ' );
@@ -19,6 +20,7 @@ public function up()
19
20
20
21
public function down ()
21
22
{
22
- Schema::dropIfExists ('workflow_state_transitions ' );
23
+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowStateTransitionTableName ();
24
+ Schema::dropIfExists ($ tableName );
23
25
}
24
26
};
Original file line number Diff line number Diff line change 3
3
namespace App\Providers;
4
4
5
5
use Illuminate\Support\ServiceProvider;
6
- use Soap\WorkflowLoader\DatabaseLoader;
7
6
8
7
class WorkflowServiceProvider extends ServiceProvider
9
8
{
10
- public function register()
11
- {
12
-
13
- }
9
+ public function register() {}
14
10
15
11
public function boot()
16
12
{
17
- $registy = app()->make('workflow');
18
- $workflowLoader = app()->make('workflow-loader ');
19
- foreach ($wokflowLoader ->all() as $workflow => $config) {
20
- $registy ->addFromArray($workflow, $config);
13
+ $registry = app()->make('workflow');
14
+ $workflowLoaderRegistry = app()->make('workflowLoaderRegistry ');
15
+ foreach ($workflowLoaderRegistry ->all() as $workflow => $config) {
16
+ $registry ->addFromArray($workflow, $config);
21
17
}
22
18
}
23
19
}
Original file line number Diff line number Diff line change @@ -14,12 +14,15 @@ class DatabaseLoader implements WorkflowDatabaseLoader
14
14
*/
15
15
protected $ config ;
16
16
17
- public function __construct (?array $ config )
17
+ protected $ repo ;
18
+
19
+ public function __construct (?array $ config , WorkflowRepository $ repo )
18
20
{
19
21
if (! isset ($ config [self ::KEY_TABLE_NAMES ])) {
20
22
throw new \InvalidArgumentException ('Table names not found in config ' );
21
23
}
22
24
$ this ->config = $ config ;
25
+ $ this ->repo = $ repo ;
23
26
}
24
27
25
28
public function getTableNames (): array
@@ -54,15 +57,15 @@ public function getWorkflowStateTransitionTableName(): string
54
57
55
58
public function load (string $ workflowName ): array
56
59
{
57
- $ repo = app ()->make (WorkflowRepository::class);
60
+ // $repo = app()->make(WorkflowRepository::class);
58
61
59
- return $ repo ->findByName ($ workflowName );
62
+ return $ this -> repo ->findByName ($ workflowName );
60
63
}
61
64
62
65
public function all (): array
63
66
{
64
- $ repo = app ()->make (WorkflowRepository::class);
67
+ // $repo = app()->make(WorkflowRepository::class);
65
68
66
- return $ repo ->all ();
69
+ return $ this -> repo ->all ();
67
70
}
68
71
}
Original file line number Diff line number Diff line change 7
7
/**
8
8
* @see \Soap\WorkflowLoader\WorkflowLoader
9
9
*/
10
- class WorkflowLoader extends Facade
10
+ class WorkflowLoaderRegistry extends Facade
11
11
{
12
12
protected static function getFacadeAccessor (): string
13
13
{
14
- return \ Soap \ WorkflowLoader \WorkflowLoader::class ;
14
+ return ' workflowLoaderRegistry ' ;
15
15
}
16
16
}
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ class Workflow extends Model
17
17
protected $ casts = [
18
18
'supports ' => 'array ' ,
19
19
'metadata ' => 'array ' ,
20
+ 'marking_store ' => 'array ' ,
20
21
'type ' => WorkflowTypeEnum::class,
21
22
];
22
23
Original file line number Diff line number Diff line change @@ -50,19 +50,21 @@ protected function makeWorkflowCofig($workflow): array
50
50
return $ state ->name ;
51
51
})->toArray ();
52
52
53
- $ transitions = $ workflow ->transitions ->map (function ($ transition ) {
54
- return [
55
- $ transition ->name => [
56
- 'from ' => $ transition ->fromStates ->map (function ($ transitionState ) {
57
- return $ transitionState ->fromState ->name ;
58
- })->toArray (),
59
- 'to ' => $ transition ->toState ->name ,
60
- ],
53
+ $ transitions = [];
54
+ foreach ($ workflow ->transitions as $ transition ) {
55
+ $ transitions [$ transition ->name ] = [
56
+ 'from ' => $ transition ->fromStates ->map (function ($ transitionState ) {
57
+ return $ transitionState ->fromState ->name ;
58
+ })->toArray (),
59
+ 'to ' => $ transition ->toState ->name ,
61
60
];
62
- })-> toArray ();
61
+ }
63
62
64
63
return [
65
64
$ workflow ->name => [
65
+ 'marking_store ' => $ workflow ->marking_store ?? [],
66
+ 'type ' => $ workflow ->type ? $ workflow ->type ->value : 'workflow ' ,
67
+ 'metadata ' => $ workflow ->metadata ,
66
68
'supports ' => $ workflow ->supports ,
67
69
'places ' => $ places ,
68
70
'transitions ' => $ transitions ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Soap \WorkflowLoader ;
4
+
5
+ use Soap \WorkflowLoader \Contracts \WorkflowLoader as WorkflowLoaderContract ;
6
+
7
+ class WorkflowLoaderRegistry
8
+ {
9
+ protected array $ loaders = [];
10
+
11
+ public function __construct (array $ loaders )
12
+ {
13
+ foreach ($ loaders as $ key => $ loader ) {
14
+ if (! isset ($ loader ['class ' ])) {
15
+ throw new \Exception ("Key 'class' configuration not found in {$ key } loader " );
16
+ }
17
+
18
+ if (! class_exists ($ loader ['class ' ])) {
19
+ throw new \Exception ("Class {$ loader ['class ' ]} not found " );
20
+ }
21
+ $ this ->registerLoader ($ key , app ()->make ($ loader ['class ' ]));
22
+ }
23
+ }
24
+
25
+ public function registerLoader (string $ name , WorkflowLoaderContract $ loader )
26
+ {
27
+ $ this ->loaders [$ name ] = $ loader ;
28
+ }
29
+
30
+ public function getLoaders (): array
31
+ {
32
+ return $ this ->loaders ;
33
+ }
34
+
35
+ public function getLoader (string $ name ): WorkflowLoaderContract
36
+ {
37
+ if (! isset ($ this ->loaders [$ name ])) {
38
+ throw new \Exception ("Loader {$ name } not found " );
39
+ }
40
+
41
+ return $ this ->loaders [$ name ];
42
+ }
43
+
44
+ public function all (): array
45
+ {
46
+ if (count ($ this ->loaders ) === 0 ) {
47
+ return [];
48
+ }
49
+
50
+ $ workflows = [];
51
+ foreach ($ this ->loaders as $ name => $ loader ) {
52
+ foreach ($ loader ->all () as $ workflow => $ config ) {
53
+ $ workflows [$ workflow ] = $ config ;
54
+ }
55
+ }
56
+
57
+ return $ workflows ;
58
+ }
59
+ }
Original file line number Diff line number Diff line change @@ -32,10 +32,14 @@ public function packageRegistered()
32
32
{
33
33
$ this ->app ->when (\Soap \WorkflowLoader \DatabaseLoader::class)
34
34
->needs ('$config ' )
35
- ->give (config ('workflow_loader.databaseLoader ' ));
35
+ ->give ($ this -> app -> make ( ' config ' )-> get ('workflow_loader.loaders.database ' ));
36
36
37
- $ this ->app ->singleton ('workflow-loader ' , function ($ app ) {
38
- $ workflowLoader = new WorkflowLoader ($ app ->make (\Soap \WorkflowLoader \DatabaseLoader::class));
39
- });
37
+ $ this ->app ->when (\Soap \WorkflowLoader \WorkflowLoaderRegistry::class)
38
+ ->needs ('$loaders ' )
39
+ ->give ($ this ->app ->make ('config ' )->get ('workflow_loader.loaders ' ));
40
+
41
+ $ this ->app ->bind (\Soap \WorkflowLoader \Contracts \WorkflowDatabaseLoader::class, \Soap \WorkflowLoader \DatabaseLoader::class);
42
+
43
+ $ this ->app ->singleton ('workflowLoaderRegistry ' , \Soap \WorkflowLoader \WorkflowLoaderRegistry::class);
40
44
}
41
45
}
You can’t perform that action at this time.
0 commit comments