55class JasperPHP
66{
77 protected $ executable = 'jasperstarter ' ; //executable jasperstarter
8- protected $ path_executable = __DIR__ . ' /../JasperStarter/bin/ ' ; //Path to executable
8+ protected $ path_executable;
99 protected $ the_command ;
1010 protected $ redirect_output ;
1111 protected $ background ;
@@ -16,11 +16,12 @@ class JasperPHP
1616
1717 function __construct ($ resource_dir = false )
1818 {
19+ $ this ->path_executable = __DIR__ . '/../JasperStarter/bin ' ; //Path to executable
1920 if (strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' )
20- $ this ->windows = true ;
21+ $ this ->windows = true ;
2122
2223 if (!$ resource_dir ) {
23- $ this ->resource_directory = __DIR__ . '/../../../vendor/lavela/phpjasper /src/JasperStarter/bin ' ;
24+ $ this ->resource_directory = __DIR__ . '/../../../vendor/cossou/jasperphp /src/JasperStarter/bin ' ;
2425 } else {
2526 if (!file_exists ($ resource_dir ))
2627 throw new \Exception ('Invalid resource directory. ' , 1 );
@@ -40,7 +41,7 @@ public static function __callStatic($method, $parameters)
4041
4142 public function compile ($ input_file , $ output_file = false , $ background = true , $ redirect_output = true )
4243 {
43- if (is_null ($ input_file ) || empty ($ input_file ))
44+ if (is_null ($ input_file ) || empty ($ input_file ))
4445 throw new \Exception ('No input file ' , 1 );
4546
4647 $ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
@@ -49,31 +50,29 @@ public function compile($input_file, $output_file = false, $background = true, $
4950
5051 $ command .= "\"$ input_file \"" ;
5152
52- if ( $ output_file !== false )
53+ if ( $ output_file !== false )
5354 $ command .= ' -o ' . "\"$ output_file \"" ;
5455
55- $ this ->redirect_output = $ redirect_output ;
56- $ this ->background = $ background ;
57- $ this ->the_command = $ command ;
56+ $ this ->redirect_output = $ redirect_output ;
57+ $ this ->background = $ background ;
58+ $ this ->the_command = $ command ;
5859
5960 return $ this ;
6061 }
6162
6263 public function process ($ input_file , $ output_file = false , $ format = array ('pdf ' ), $ parameters = array (), $ db_connection = array (), $ background = true , $ redirect_output = true )
6364 {
64- if (is_null ($ input_file ) || empty ($ input_file ))
65+ if (is_null ($ input_file ) || empty ($ input_file ))
6566 throw new \Exception ('No input file ' , 1 );
6667
67- if ( is_array ($ format ) )
68- {
69- foreach ($ format as $ key )
70- {
71- if ( !in_array ($ key , $ this ->formats ))
68+ if (is_array ($ format )) {
69+ foreach ($ format as $ key ) {
70+ if (!in_array ($ key , $ this ->formats ))
7271 throw new \Exception ('Invalid format! ' , 1 );
7372 }
7473 } else {
75- if ( !in_array ($ format , $ this ->formats ))
76- throw new \Exception ('Invalid format! ' , 1 );
74+ if ( !in_array ($ format , $ this ->formats ))
75+ throw new \Exception ('Invalid format! ' , 1 );
7776 }
7877
7978 $ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
@@ -82,78 +81,75 @@ public function process($input_file, $output_file = false, $format = array('pdf'
8281
8382 $ command .= "\"$ input_file \"" ;
8483
85- if ( $ output_file !== false )
84+ if ( $ output_file !== false )
8685 $ command .= ' -o ' . "\"$ output_file \"" ;
8786
88- if ( is_array ($ format ) )
87+ if ( is_array ($ format ))
8988 $ command .= ' -f ' . join (' ' , $ format );
9089 else
9190 $ command .= ' -f ' . $ format ;
9291 /*
9392 // Resources dir
9493 $command .= " -r " . $this->resource_directory;
9594 */
96- if ( count ($ parameters ) > 0 )
97- {
95+ if (count ($ parameters ) > 0 ) {
9896 $ command .= ' -P ' ;
9997
100- foreach ($ parameters as $ key => $ value )
101- {
98+ foreach ($ parameters as $ key => $ value ) {
10299 $ param = $ key . '=" ' . $ value . '" ' ;
103- $ command .= " " .$ param . " " ;
100+ $ command .= " " . $ param . " " ;
104101 }
105102
106103 }
107104
108- if ( count ($ db_connection ) > 0 )
109- {
105+ if (count ($ db_connection ) > 0 ) {
110106 $ command .= ' -t ' . $ db_connection ['driver ' ];
111107
112- if (isset ($ db_connection ['username ' ]))
108+ if (isset ($ db_connection ['username ' ]))
113109 $ command .= " -u " . $ db_connection ['username ' ];
114110
115- if ( isset ($ db_connection ['password ' ]) && !empty ($ db_connection ['password ' ]) )
111+ if ( isset ($ db_connection ['password ' ]) && !empty ($ db_connection ['password ' ]))
116112 $ command .= ' -p ' . $ db_connection ['password ' ];
117113
118- if ( isset ($ db_connection ['host ' ]) && !empty ($ db_connection ['host ' ]) )
114+ if ( isset ($ db_connection ['host ' ]) && !empty ($ db_connection ['host ' ]))
119115 $ command .= ' -H ' . $ db_connection ['host ' ];
120116
121- if ( isset ($ db_connection ['database ' ]) && !empty ($ db_connection ['database ' ]) )
117+ if ( isset ($ db_connection ['database ' ]) && !empty ($ db_connection ['database ' ]))
122118 $ command .= ' -n ' . $ db_connection ['database ' ];
123119
124- if ( isset ($ db_connection ['port ' ]) && !empty ($ db_connection ['port ' ]) )
120+ if ( isset ($ db_connection ['port ' ]) && !empty ($ db_connection ['port ' ]))
125121 $ command .= ' --db-port ' . $ db_connection ['port ' ];
126122
127- if ( isset ($ db_connection ['jdbc_driver ' ]) && !empty ($ db_connection ['jdbc_driver ' ]) )
123+ if ( isset ($ db_connection ['jdbc_driver ' ]) && !empty ($ db_connection ['jdbc_driver ' ]))
128124 $ command .= ' --db-driver ' . $ db_connection ['jdbc_driver ' ];
129125
130- if ( isset ($ db_connection ['jdbc_url ' ]) && !empty ($ db_connection ['jdbc_url ' ]) )
126+ if ( isset ($ db_connection ['jdbc_url ' ]) && !empty ($ db_connection ['jdbc_url ' ]))
131127 $ command .= ' --db-url ' . $ db_connection ['jdbc_url ' ];
132128
133- if ( isset ($ db_connection ['jdbc_dir ' ]) && !empty ($ db_connection ['jdbc_dir ' ]) )
129+ if (isset ($ db_connection ['jdbc_dir ' ]) && !empty ($ db_connection ['jdbc_dir ' ]))
134130 $ command .= ' --jdbc-dir ' . $ db_connection ['jdbc_dir ' ];
135131
136- if ( isset ($ db_connection ['db_sid ' ]) && !empty ($ db_connection ['db_sid ' ]) )
132+ if (isset ($ db_connection ['db_sid ' ]) && !empty ($ db_connection ['db_sid ' ]))
137133 $ command .= ' --db-sid ' . $ db_connection ['db_sid ' ];
138134
139- if ( isset ($ db_connection ['xml_xpath ' ]) )
135+ if (isset ($ db_connection ['xml_xpath ' ]))
140136 $ command .= ' --xml-xpath ' . $ db_connection ['xml_xpath ' ];
141137
142- if ( isset ($ db_connection ['data_file ' ]) )
138+ if (isset ($ db_connection ['data_file ' ]))
143139 $ command .= ' --data-file ' . $ db_connection ['data_file ' ];
144140
145141 }
146142
147- $ this ->redirect_output = $ redirect_output ;
148- $ this ->background = $ background ;
149- $ this ->the_command = $ command ;
143+ $ this ->redirect_output = $ redirect_output ;
144+ $ this ->background = $ background ;
145+ $ this ->the_command = $ command ;
150146
151147 return $ this ;
152148 }
153149
154150 public function list_parameters ($ input_file )
155151 {
156- if (is_null ($ input_file ) || empty ($ input_file ))
152+ if (is_null ($ input_file ) || empty ($ input_file ))
157153 throw new \Exception ('No input file ' , 1 );
158154
159155 $ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
@@ -175,22 +171,22 @@ public function output()
175171 public function execute ($ run_as_user = false )
176172 {
177173
178- if ( $ run_as_user !== false && strlen ($ run_as_user > 0 ) && !$ this ->windows )
174+ if ( $ run_as_user !== false && strlen ($ run_as_user > 0 ) && !$ this ->windows )
179175 $ this ->the_command = 'su -u ' . $ run_as_user . " -c \"" . $ this ->the_command . "\"" ;
180176
181177 $ output = array ();
182178 $ return_var = 0 ;
183179
184- if (is_dir ($ this ->path_executable )){
180+ if (is_dir ($ this ->path_executable )) {
185181 chdir ($ this ->path_executable );
186182 exec ($ this ->the_command , $ output , $ return_var );
187183 } else {
188184 throw new \Exception ('Invalid resource directory. ' , 1 );
189185 }
190186
191- if ($ return_var != 0 )
187+ if ($ return_var != 0 )
192188 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 );
193-
189+
194190 return $ output ;
195191 }
196- }
192+ }
0 commit comments