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 11<?php
22
33return [
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,
1013 ],
11- 'loaderClass ' => \Soap \WorkflowLoader \DatabaseLoader::class,
1214 ],
1315];
Original file line number Diff line number Diff line change 88{
99 public function up ()
1010 {
11- Schema::create ('workflows ' , function (Blueprint $ table ) {
11+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowTableName ();
12+ Schema::create ($ tableName , function (Blueprint $ table ) {
1213 $ table ->id ();
1314 $ 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 ' );
1516 $ table ->string ('type ' )->default ('workflow ' )->comment ('workflow or state_machine ' );
1617 $ table ->text ('description ' )->nullable ();
1718 $ table ->json ('supports ' )->nullable ()->comment ('support models ' );
1819 $ table ->json ('metadata ' )->nullable ()->comment ('metadata ' );
20+ $ table ->boolean ('active ' )->default (true );
1921 $ table ->timestamps ();
2022 });
2123 }
2224
2325 public function down ()
2426 {
25- Schema::dropIfExists ('workflows ' );
27+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowTableName ();
28+ Schema::dropIfExists ($ tableName );
2629 }
2730};
Original file line number Diff line number Diff line change 88{
99 public function up ()
1010 {
11- Schema::create ('workflow_states ' , function (Blueprint $ table ) {
11+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowStateTableName ();
12+ Schema::create ($ tableName , function (Blueprint $ table ) {
1213 $ table ->id ();
1314 $ table ->string ('name ' );
1415 $ table ->tinyInteger ('initial_state ' )->default (0 )->comment ('initial state ' );
@@ -21,6 +22,7 @@ public function up()
2122
2223 public function down ()
2324 {
24- Schema::dropIfExists ('workflow_states ' );
25+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowStateTableName ();
26+ Schema::dropIfExists ($ tableName );
2527 }
2628};
Original file line number Diff line number Diff line change 88{
99 public function up ()
1010 {
11- Schema::create ('workflow_transitions ' , function (Blueprint $ table ) {
11+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowTransitionTableName ();
12+ Schema::create ($ tableName , function (Blueprint $ table ) {
1213 $ table ->id ();
1314 $ table ->string ('name ' );
1415 $ table ->foreignId ('to_state_id ' )->constrained ('workflow_states ' )->onDelete ('cascade ' );
@@ -20,6 +21,7 @@ public function up()
2021
2122 public function down ()
2223 {
23- Schema::dropIfExists ('workflow_transitions ' );
24+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowTransitionTableName ();
25+ Schema::dropIfExists ($ tableName );
2426 }
2527};
Original file line number Diff line number Diff line change 88{
99 public function up ()
1010 {
11- Schema::create ('workflow_state_transitions ' , function (Blueprint $ table ) {
11+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowStateTransitionTableName ();
12+ Schema::create ($ tableName , function (Blueprint $ table ) {
1213 $ table ->id ();
1314 $ table ->foreignId ('workflow_transition_id ' )->constrained ('workflow_transitions ' )->onDelete ('cascade ' );
1415 $ table ->foreignId ('from_state_id ' )->constrained ('workflow_states ' )->onDelete ('cascade ' );
@@ -19,6 +20,7 @@ public function up()
1920
2021 public function down ()
2122 {
22- Schema::dropIfExists ('workflow_state_transitions ' );
23+ $ tableName = app (\Soap \WorkflowLoader \DatabaseLoader::class)->getWorkflowStateTransitionTableName ();
24+ Schema::dropIfExists ($ tableName );
2325 }
2426};
Original file line number Diff line number Diff line change 33namespace App\Providers;
44
55use Illuminate\Support\ServiceProvider;
6- use Soap\WorkflowLoader\DatabaseLoader;
76
87class WorkflowServiceProvider extends ServiceProvider
98{
10- public function register()
11- {
12-
13- }
9+ public function register() {}
1410
1511 public function boot()
1612 {
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);
2117 }
2218 }
2319}
Original file line number Diff line number Diff line change @@ -14,12 +14,15 @@ class DatabaseLoader implements WorkflowDatabaseLoader
1414 */
1515 protected $ config ;
1616
17- public function __construct (?array $ config )
17+ protected $ repo ;
18+
19+ public function __construct (?array $ config , WorkflowRepository $ repo )
1820 {
1921 if (! isset ($ config [self ::KEY_TABLE_NAMES ])) {
2022 throw new \InvalidArgumentException ('Table names not found in config ' );
2123 }
2224 $ this ->config = $ config ;
25+ $ this ->repo = $ repo ;
2326 }
2427
2528 public function getTableNames (): array
@@ -54,15 +57,15 @@ public function getWorkflowStateTransitionTableName(): string
5457
5558 public function load (string $ workflowName ): array
5659 {
57- $ repo = app ()->make (WorkflowRepository::class);
60+ // $repo = app()->make(WorkflowRepository::class);
5861
59- return $ repo ->findByName ($ workflowName );
62+ return $ this -> repo ->findByName ($ workflowName );
6063 }
6164
6265 public function all (): array
6366 {
64- $ repo = app ()->make (WorkflowRepository::class);
67+ // $repo = app()->make(WorkflowRepository::class);
6568
66- return $ repo ->all ();
69+ return $ this -> repo ->all ();
6770 }
6871}
Original file line number Diff line number Diff line change 77/**
88 * @see \Soap\WorkflowLoader\WorkflowLoader
99 */
10- class WorkflowLoader extends Facade
10+ class WorkflowLoaderRegistry extends Facade
1111{
1212 protected static function getFacadeAccessor (): string
1313 {
14- return \ Soap \ WorkflowLoader \WorkflowLoader::class ;
14+ return ' workflowLoaderRegistry ' ;
1515 }
1616}
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ class Workflow extends Model
1717 protected $ casts = [
1818 'supports ' => 'array ' ,
1919 'metadata ' => 'array ' ,
20+ 'marking_store ' => 'array ' ,
2021 'type ' => WorkflowTypeEnum::class,
2122 ];
2223
Original file line number Diff line number Diff line change @@ -50,19 +50,21 @@ protected function makeWorkflowCofig($workflow): array
5050 return $ state ->name ;
5151 })->toArray ();
5252
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 ,
6160 ];
62- })-> toArray ();
61+ }
6362
6463 return [
6564 $ workflow ->name => [
65+ 'marking_store ' => $ workflow ->marking_store ?? [],
66+ 'type ' => $ workflow ->type ? $ workflow ->type ->value : 'workflow ' ,
67+ 'metadata ' => $ workflow ->metadata ,
6668 'supports ' => $ workflow ->supports ,
6769 'places ' => $ places ,
6870 'transitions ' => $ transitions ,
You can’t perform that action at this time.
0 commit comments