@@ -17,14 +17,16 @@ class JasperPHP
1717 function __construct ($ resource_dir = false )
1818 {
1919 $ 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+ }
2223
2324 if (!$ resource_dir ) {
2425 $ this ->resource_directory = __DIR__ . '/../../../vendor/geekcom/jasperphp/src/JasperStarter/bin ' ;
2526 } 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+ }
2830
2931 $ this ->resource_directory = $ resource_dir ;
3032 }
@@ -41,17 +43,19 @@ public static function __callStatic($method, $parameters)
4143
4244 public function compile ($ input_file , $ output_file = false , $ background = true , $ redirect_output = true )
4345 {
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+ }
4649
4750 $ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
4851
4952 $ command .= ' compile ' ;
5053
5154 $ command .= "\"$ input_file \"" ;
5255
53- if ($ output_file !== false )
54- $ command .= ' -o ' . "\"$ output_file \"" ;
56+ if ($ output_file !== false ) {
57+ $ command .= ' -o ' . "\"$ output_file \"" ;
58+ }
5559
5660 $ this ->redirect_output = $ redirect_output ;
5761 $ this ->background = $ background ;
@@ -62,17 +66,20 @@ public function compile($input_file, $output_file = false, $background = true, $
6266
6367 public function process ($ input_file , $ output_file = false , $ format = array ('pdf ' ), $ parameters = array (), $ db_connection = array (), $ locale = false , $ background = true , $ redirect_output = true )
6468 {
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+ }
6772
6873 if (is_array ($ format )) {
6974 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+ }
7278 }
7379 } 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+ }
7683 }
7784
7885 $ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
@@ -83,13 +90,15 @@ public function process($input_file, $output_file = false, $format = array('pdf'
8390
8491 $ command .= "\"$ input_file \"" ;
8592
86- if ($ output_file !== false )
87- $ command .= ' -o ' . "\"$ output_file \"" ;
93+ if ($ output_file !== false ) {
94+ $ command .= ' -o ' . "\"$ output_file \"" ;
95+ }
8896
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+ }
93102
94103
95104 if (count ($ parameters ) > 0 ) {
@@ -105,41 +114,53 @@ public function process($input_file, $output_file = false, $format = array('pdf'
105114 if (count ($ db_connection ) > 0 ) {
106115 $ command .= ' -t ' . $ db_connection ['driver ' ];
107116
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+ }
110120
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+ }
113124
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+ }
116128
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+ }
119132
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+ }
122136
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+ }
125140
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+ }
128144
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+ }
131148
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+ }
134152
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+ }
137156
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+ }
140160
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+ }
143164 }
144165
145166 $ this ->redirect_output = $ redirect_output ;
@@ -151,8 +172,9 @@ public function process($input_file, $output_file = false, $format = array('pdf'
151172
152173 public function list_parameters ($ input_file )
153174 {
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+ }
156178
157179 $ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
158180
@@ -173,8 +195,9 @@ public function output()
173195 public function execute ($ run_as_user = false )
174196 {
175197
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+ }
178201
179202 $ output = array ();
180203 $ return_var = 0 ;
@@ -186,8 +209,9 @@ public function execute($run_as_user = false)
186209 throw new \Exception ('Invalid resource directory. ' , 1 );
187210 }
188211
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+ }
191215
192216 return $ output ;
193217 }
0 commit comments