3
3
namespace Blueprint \Generators \Statements ;
4
4
5
5
use Blueprint \Blueprint ;
6
- use Blueprint \Contracts \ Generator ;
6
+ use Blueprint \Generators \ StatementGenerator ;
7
7
use Blueprint \Models \Statements \SendStatement ;
8
8
9
- class NotificationGenerator implements Generator
9
+ class NotificationGenerator extends StatementGenerator
10
10
{
11
- /**
12
- * @
13
- \Illuminate\Contracts\Filesystem\Filesystem
14
- */
15
- private $ files ;
16
-
17
- public function __construct ($ files )
18
- {
19
- $ this ->files = $ files ;
20
- }
11
+ protected $ new_instance = 'new message instance ' ;
21
12
22
13
public function output (array $ tree ): array
23
14
{
@@ -29,11 +20,11 @@ public function output(array $tree): array
29
20
foreach ($ tree ['controllers ' ] as $ controller ) {
30
21
foreach ($ controller ->methods () as $ method => $ statements ) {
31
22
foreach ($ statements as $ statement ) {
32
- if (! $ statement instanceof SendStatement) {
23
+ if (!$ statement instanceof SendStatement) {
33
24
continue ;
34
25
}
35
26
36
- if (! $ statement ->isNotification ()) {
27
+ if (!$ statement ->isNotification ()) {
37
28
continue ;
38
29
}
39
30
@@ -43,7 +34,7 @@ public function output(array $tree): array
43
34
continue ;
44
35
}
45
36
46
- if (! $ this ->files ->exists (dirname ($ path ))) {
37
+ if (!$ this ->files ->exists (dirname ($ path ))) {
47
38
$ this ->files ->makeDirectory (dirname ($ path ), 0755 , true );
48
39
}
49
40
@@ -64,61 +55,15 @@ public function types(): array
64
55
65
56
protected function getPath (string $ name )
66
57
{
67
- return Blueprint::appPath (). '/Notification/ ' . $ name. '.php ' ;
58
+ return Blueprint::appPath () . '/Notification/ ' . $ name . '.php ' ;
68
59
}
69
60
70
61
protected function populateStub (string $ stub , SendStatement $ sendStatement )
71
62
{
72
- $ stub = str_replace ('DummyNamespace ' , config ('blueprint.namespace ' ). '\\Notification ' , $ stub );
63
+ $ stub = str_replace ('DummyNamespace ' , config ('blueprint.namespace ' ) . '\\Notification ' , $ stub );
73
64
$ stub = str_replace ('DummyClass ' , $ sendStatement ->mail (), $ stub );
74
65
$ stub = str_replace ('// properties... ' , $ this ->buildConstructor ($ sendStatement ), $ stub );
75
66
76
67
return $ stub ;
77
68
}
78
-
79
- private function buildConstructor (SendStatement $ sendStatement )
80
- {
81
- static $ constructor = null ;
82
-
83
- if (is_null ($ constructor )) {
84
- $ constructor = str_replace ('new instance ' , 'new message instance ' , $ this ->files ->stub ('partials/constructor.stub ' ));
85
- }
86
-
87
- if (empty ($ sendStatement ->data ())) {
88
- return trim ($ constructor );
89
- }
90
-
91
- $ stub = $ this ->buildProperties ($ sendStatement ->data ()).PHP_EOL .PHP_EOL ;
92
- $ stub .= str_replace ('__construct() ' , '__construct( ' .$ this ->buildParameters ($ sendStatement ->data ()).') ' , $ constructor );
93
- $ stub = str_replace ('// ' , $ this ->buildAssignments ($ sendStatement ->data ()), $ stub );
94
-
95
- return $ stub ;
96
- }
97
-
98
- private function buildProperties (array $ data )
99
- {
100
- return trim (array_reduce ($ data , function ($ output , $ property ) {
101
- $ output .= ' public $ ' .$ property .'; ' .PHP_EOL .PHP_EOL ;
102
-
103
- return $ output ;
104
- }, '' ));
105
- }
106
-
107
- private function buildParameters (array $ data )
108
- {
109
- $ parameters = array_map (function ($ parameter ) {
110
- return '$ ' .$ parameter ;
111
- }, $ data );
112
-
113
- return implode (', ' , $ parameters );
114
- }
115
-
116
- private function buildAssignments (array $ data )
117
- {
118
- return trim (array_reduce ($ data , function ($ output , $ property ) {
119
- $ output .= ' $this-> ' .$ property .' = $ ' .$ property .'; ' .PHP_EOL ;
120
-
121
- return $ output ;
122
- }, '' ));
123
- }
124
69
}
0 commit comments