@@ -17,14 +17,16 @@ class JasperPHP
17
17
function __construct ($ resource_dir = false )
18
18
{
19
19
$ this ->path_executable = __DIR__ . '/../JasperStarter/bin ' ; //Path to executable
20
- if (strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' )
21
- $ this ->windows = true ;
20
+ if (strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ) {
21
+ $ this ->windows = true ;
22
+ }
22
23
23
24
if (!$ resource_dir ) {
24
25
$ this ->resource_directory = __DIR__ . '/../../../vendor/geekcom/jasperphp/src/JasperStarter/bin ' ;
25
26
} else {
26
- if (!file_exists ($ resource_dir ))
27
- throw new \Exception ('Invalid resource directory. ' , 1 );
27
+ if (!file_exists ($ resource_dir )) {
28
+ throw new \Exception ('Invalid resource directory. ' , 1 );
29
+ }
28
30
29
31
$ this ->resource_directory = $ resource_dir ;
30
32
}
@@ -41,17 +43,19 @@ public static function __callStatic($method, $parameters)
41
43
42
44
public function compile ($ input_file , $ output_file = false , $ background = true , $ redirect_output = true )
43
45
{
44
- if (is_null ($ input_file ) || empty ($ input_file ))
45
- throw new \Exception ('No input file ' , 1 );
46
+ if (is_null ($ input_file ) || empty ($ input_file )) {
47
+ throw new \Exception ('No input file ' , 1 );
48
+ }
46
49
47
50
$ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
48
51
49
52
$ command .= ' compile ' ;
50
53
51
54
$ command .= "\"$ input_file \"" ;
52
55
53
- if ($ output_file !== false )
54
- $ command .= ' -o ' . "\"$ output_file \"" ;
56
+ if ($ output_file !== false ) {
57
+ $ command .= ' -o ' . "\"$ output_file \"" ;
58
+ }
55
59
56
60
$ this ->redirect_output = $ redirect_output ;
57
61
$ this ->background = $ background ;
@@ -62,17 +66,20 @@ public function compile($input_file, $output_file = false, $background = true, $
62
66
63
67
public function process ($ input_file , $ output_file = false , $ format = array ('pdf ' ), $ parameters = array (), $ db_connection = array (), $ locale = false , $ background = true , $ redirect_output = true )
64
68
{
65
- if (is_null ($ input_file ) || empty ($ input_file ))
66
- throw new \Exception ('No input file ' , 1 );
69
+ if (is_null ($ input_file ) || empty ($ input_file )) {
70
+ throw new \Exception ('No input file ' , 1 );
71
+ }
67
72
68
73
if (is_array ($ format )) {
69
74
foreach ($ format as $ key ) {
70
- if (!in_array ($ key , $ this ->formats ))
71
- throw new \Exception ('Invalid format! ' , 1 );
75
+ if (!in_array ($ key , $ this ->formats )) {
76
+ throw new \Exception ('Invalid format! ' , 1 );
77
+ }
72
78
}
73
79
} else {
74
- if (!in_array ($ format , $ this ->formats ))
75
- throw new \Exception ('Invalid format! ' , 1 );
80
+ if (!in_array ($ format , $ this ->formats )) {
81
+ throw new \Exception ('Invalid format! ' , 1 );
82
+ }
76
83
}
77
84
78
85
$ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
@@ -83,13 +90,15 @@ public function process($input_file, $output_file = false, $format = array('pdf'
83
90
84
91
$ command .= "\"$ input_file \"" ;
85
92
86
- if ($ output_file !== false )
87
- $ command .= ' -o ' . "\"$ output_file \"" ;
93
+ if ($ output_file !== false ) {
94
+ $ command .= ' -o ' . "\"$ output_file \"" ;
95
+ }
88
96
89
- if (is_array ($ format ))
90
- $ command .= ' -f ' . join (' ' , $ format );
91
- else
92
- $ command .= ' -f ' . $ format ;
97
+ if (is_array ($ format )) {
98
+ $ command .= ' -f ' . join (' ' , $ format );
99
+ } else {
100
+ $ command .= ' -f ' . $ format ;
101
+ }
93
102
94
103
95
104
if (count ($ parameters ) > 0 ) {
@@ -105,41 +114,53 @@ public function process($input_file, $output_file = false, $format = array('pdf'
105
114
if (count ($ db_connection ) > 0 ) {
106
115
$ command .= ' -t ' . $ db_connection ['driver ' ];
107
116
108
- if (isset ($ db_connection ['username ' ]))
109
- $ command .= " -u " . $ db_connection ['username ' ];
117
+ if (isset ($ db_connection ['username ' ])) {
118
+ $ command .= " -u " . $ db_connection ['username ' ];
119
+ }
110
120
111
- if (isset ($ db_connection ['password ' ]) && !empty ($ db_connection ['password ' ]))
112
- $ command .= ' -p ' . $ db_connection ['password ' ];
121
+ if (isset ($ db_connection ['password ' ]) && !empty ($ db_connection ['password ' ])) {
122
+ $ command .= ' -p ' . $ db_connection ['password ' ];
123
+ }
113
124
114
- if (isset ($ db_connection ['host ' ]) && !empty ($ db_connection ['host ' ]))
115
- $ command .= ' -H ' . $ db_connection ['host ' ];
125
+ if (isset ($ db_connection ['host ' ]) && !empty ($ db_connection ['host ' ])) {
126
+ $ command .= ' -H ' . $ db_connection ['host ' ];
127
+ }
116
128
117
- if (isset ($ db_connection ['database ' ]) && !empty ($ db_connection ['database ' ]))
118
- $ command .= ' -n ' . $ db_connection ['database ' ];
129
+ if (isset ($ db_connection ['database ' ]) && !empty ($ db_connection ['database ' ])) {
130
+ $ command .= ' -n ' . $ db_connection ['database ' ];
131
+ }
119
132
120
- if (isset ($ db_connection ['port ' ]) && !empty ($ db_connection ['port ' ]))
121
- $ command .= ' --db-port ' . $ db_connection ['port ' ];
133
+ if (isset ($ db_connection ['port ' ]) && !empty ($ db_connection ['port ' ])) {
134
+ $ command .= ' --db-port ' . $ db_connection ['port ' ];
135
+ }
122
136
123
- if (isset ($ db_connection ['jdbc_driver ' ]) && !empty ($ db_connection ['jdbc_driver ' ]))
124
- $ command .= ' --db-driver ' . $ db_connection ['jdbc_driver ' ];
137
+ if (isset ($ db_connection ['jdbc_driver ' ]) && !empty ($ db_connection ['jdbc_driver ' ])) {
138
+ $ command .= ' --db-driver ' . $ db_connection ['jdbc_driver ' ];
139
+ }
125
140
126
- if (isset ($ db_connection ['jdbc_url ' ]) && !empty ($ db_connection ['jdbc_url ' ]))
127
- $ command .= ' --db-url ' . $ db_connection ['jdbc_url ' ];
141
+ if (isset ($ db_connection ['jdbc_url ' ]) && !empty ($ db_connection ['jdbc_url ' ])) {
142
+ $ command .= ' --db-url ' . $ db_connection ['jdbc_url ' ];
143
+ }
128
144
129
- if (isset ($ db_connection ['jdbc_dir ' ]) && !empty ($ db_connection ['jdbc_dir ' ]))
130
- $ command .= ' --jdbc-dir ' . $ db_connection ['jdbc_dir ' ];
145
+ if (isset ($ db_connection ['jdbc_dir ' ]) && !empty ($ db_connection ['jdbc_dir ' ])) {
146
+ $ command .= ' --jdbc-dir ' . $ db_connection ['jdbc_dir ' ];
147
+ }
131
148
132
- if (isset ($ db_connection ['db_sid ' ]) && !empty ($ db_connection ['db_sid ' ]))
133
- $ command .= ' --db-sid ' . $ db_connection ['db_sid ' ];
149
+ if (isset ($ db_connection ['db_sid ' ]) && !empty ($ db_connection ['db_sid ' ])) {
150
+ $ command .= ' --db-sid ' . $ db_connection ['db_sid ' ];
151
+ }
134
152
135
- if (isset ($ db_connection ['xml_xpath ' ]))
136
- $ command .= ' --xml-xpath ' . $ db_connection ['xml_xpath ' ];
153
+ if (isset ($ db_connection ['xml_xpath ' ])) {
154
+ $ command .= ' --xml-xpath ' . $ db_connection ['xml_xpath ' ];
155
+ }
137
156
138
- if (isset ($ db_connection ['data_file ' ]))
139
- $ command .= ' --data-file ' . $ db_connection ['data_file ' ];
157
+ if (isset ($ db_connection ['data_file ' ])) {
158
+ $ command .= ' --data-file ' . $ db_connection ['data_file ' ];
159
+ }
140
160
141
- if (isset ($ db_connection ['json_query ' ]))
142
- $ command .= ' --json-query ' . $ db_connection ['json_query ' ];
161
+ if (isset ($ db_connection ['json_query ' ])) {
162
+ $ command .= ' --json-query ' . $ db_connection ['json_query ' ];
163
+ }
143
164
}
144
165
145
166
$ this ->redirect_output = $ redirect_output ;
@@ -151,8 +172,9 @@ public function process($input_file, $output_file = false, $format = array('pdf'
151
172
152
173
public function list_parameters ($ input_file )
153
174
{
154
- if (is_null ($ input_file ) || empty ($ input_file ))
155
- throw new \Exception ('No input file ' , 1 );
175
+ if (is_null ($ input_file ) || empty ($ input_file )) {
176
+ throw new \Exception ('No input file ' , 1 );
177
+ }
156
178
157
179
$ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
158
180
@@ -173,8 +195,9 @@ public function output()
173
195
public function execute ($ run_as_user = false )
174
196
{
175
197
176
- if ($ run_as_user !== false && strlen ($ run_as_user > 0 ) && !$ this ->windows )
177
- $ this ->the_command = 'su -u ' . $ run_as_user . " -c \"" . $ this ->the_command . "\"" ;
198
+ if ($ run_as_user !== false && strlen ($ run_as_user > 0 ) && !$ this ->windows ) {
199
+ $ this ->the_command = 'su -u ' . $ run_as_user . " -c \"" . $ this ->the_command . "\"" ;
200
+ }
178
201
179
202
$ output = array ();
180
203
$ return_var = 0 ;
@@ -186,8 +209,9 @@ public function execute($run_as_user = false)
186
209
throw new \Exception ('Invalid resource directory. ' , 1 );
187
210
}
188
211
189
- if ($ return_var != 0 )
190
- throw new \Exception ('Your report has an error and couldn \'t be processed!\ Try to output the command using the function `output();` and run it manually in the console. ' , 1 );
212
+ if ($ return_var != 0 ) {
213
+ throw new \Exception ('Your report has an error and couldn \'t be processed!\ Try to output the command using the function `output();` and run it manually in the console. ' , 1 );
214
+ }
191
215
192
216
return $ output ;
193
217
}
0 commit comments