@@ -2,6 +2,7 @@ package gotask
2
2
3
3
import (
4
4
"bytes"
5
+ "fmt"
5
6
"io/ioutil"
6
7
"os"
7
8
"path/filepath"
@@ -105,19 +106,24 @@ func body(namespace *string, class *Class) string {
105
106
func generatePHP (receiver interface {}) error {
106
107
namespace := property (receiver , "PHPNamespace" , "App\\ GoTask" )
107
108
class := reflectStruct (receiver )
108
- dirPath := property (receiver , "PHPPath" , "./../app/GoTask" )
109
- err := os .MkdirAll (dirPath , os .FileMode (0755 ))
110
- if err != nil {
111
- return errors .Wrap (err , "cannot create dir for php files" )
112
- }
113
- fullPath , err := filepath .Abs (filepath .Clean (dirPath ) + "/" + class .Name + ".php" )
114
- if err != nil {
115
- return errors .Wrap (err , "invalid file path" )
116
- }
117
109
out := body (& namespace , class )
118
- err = ioutil .WriteFile (fullPath , []byte (out ), os .FileMode (0755 ))
119
- if err != nil {
120
- return errors .Wrap (err , "failed to generate PHP file" )
110
+ dirPath := property (receiver , "PHPPath" , "" )
111
+ if dirPath != "" {
112
+ err := os .MkdirAll (dirPath , os .FileMode (0755 ))
113
+ if err != nil {
114
+ return errors .Wrap (err , "cannot create dir for php files" )
115
+ }
116
+ fullPath , err := filepath .Abs (filepath .Clean (dirPath ) + "/" + class .Name + ".php" )
117
+ if err != nil {
118
+ return errors .Wrap (err , "invalid file path" )
119
+ }
120
+
121
+ err = ioutil .WriteFile (fullPath , []byte (out ), os .FileMode (0755 ))
122
+ if err != nil {
123
+ return errors .Wrap (err , "failed to generate PHP file" )
124
+ }
125
+ } else {
126
+ fmt .Print (out )
121
127
}
122
128
return nil
123
129
}
0 commit comments