44
55class JasperPHP
66{
7- protected $ executable = " jasperstarter " ; //executable jasperstarter
7+ protected $ executable = ' jasperstarter ' ; //executable jasperstarter
88 protected $ path_executable = __DIR__ . '/../JasperStarter/bin/ ' ; //Path to executable
99 protected $ the_command ;
1010 protected $ redirect_output ;
@@ -20,10 +20,10 @@ function __construct($resource_dir = false)
2020 $ this ->windows = true ;
2121
2222 if (!$ resource_dir ) {
23- $ this ->resource_directory = __DIR__ . " /../../../vendor/cossou/jasperphp/src/JasperStarter/bin " ;
23+ $ this ->resource_directory = __DIR__ . ' /../../../vendor/cossou/jasperphp/src/JasperStarter/bin ' ;
2424 } else {
2525 if (!file_exists ($ resource_dir ))
26- throw new \Exception (" Invalid resource directory. " , 1 );
26+ throw new \Exception (' Invalid resource directory. ' , 1 );
2727
2828 $ this ->resource_directory = $ resource_dir ;
2929 }
@@ -41,16 +41,16 @@ public static function __callStatic($method, $parameters)
4141 public function compile ($ input_file , $ output_file = false , $ background = true , $ redirect_output = true )
4242 {
4343 if (is_null ($ input_file ) || empty ($ input_file ))
44- throw new \Exception (" No input file " , 1 );
44+ throw new \Exception (' No input file ' , 1 );
4545
4646 $ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
4747
48- $ command .= " compile " ;
48+ $ command .= ' compile ' ;
4949
5050 $ command .= "\"$ input_file \"" ;
5151
5252 if ( $ output_file !== false )
53- $ command .= " -o " . "\"$ output_file \"" ;
53+ $ command .= ' -o ' . "\"$ output_file \"" ;
5454
5555 $ this ->redirect_output = $ redirect_output ;
5656 $ this ->background = $ background ;
@@ -59,85 +59,83 @@ public function compile($input_file, $output_file = false, $background = true, $
5959 return $ this ;
6060 }
6161
62- public function process ($ input_file , $ output_file = false , $ format = array (" pdf " ), $ parameters = array (), $ db_connection = array (), $ background = true , $ redirect_output = true )
62+ public function process ($ input_file , $ output_file = false , $ format = array (' pdf ' ), $ parameters = array (), $ db_connection = array (), $ background = true , $ redirect_output = true )
6363 {
6464 if (is_null ($ input_file ) || empty ($ input_file ))
65- throw new \Exception (" No input file " , 1 );
65+ throw new \Exception (' No input file ' , 1 );
6666
6767 if ( is_array ($ format ) )
6868 {
6969 foreach ($ format as $ key )
7070 {
7171 if ( !in_array ($ key , $ this ->formats ))
72- throw new \Exception (" Invalid format! " , 1 );
72+ throw new \Exception (' Invalid format! ' , 1 );
7373 }
7474 } else {
7575 if ( !in_array ($ format , $ this ->formats ))
76- throw new \Exception (" Invalid format! " , 1 );
76+ throw new \Exception (' Invalid format! ' , 1 );
7777 }
7878
7979 $ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
8080
81- $ command .= " process " ;
81+ $ command .= ' process ' ;
8282
8383 $ command .= "\"$ input_file \"" ;
8484
8585 if ( $ output_file !== false )
86- $ command .= " -o " . "\"$ output_file \"" ;
86+ $ command .= ' -o ' . "\"$ output_file \"" ;
8787
8888 if ( is_array ($ format ) )
89- $ command .= " -f " . join (" " , $ format );
89+ $ command .= ' -f ' . join (' ' , $ format );
9090 else
91- $ command .= " -f " . $ format ;
91+ $ command .= ' -f ' . $ format ;
9292 /*
9393 // Resources dir
9494 $command .= " -r " . $this->resource_directory;
9595 */
9696 if ( count ($ parameters ) > 0 )
9797 {
98- $ command .= " -P " ;
98+ $ command .= ' -P ' ;
9999 foreach ($ parameters as $ key => $ value )
100100 {
101- $ command .= " " . $ key . "= " . $ value ;
101+ $ param = $ key . '= ' . $ value . ' ' ;
102+ $ command .= "\"$ param \"" ;
102103 }
103104 }
104105
105106 if ( count ($ db_connection ) > 0 )
106107 {
107- $ command .= " -t " . $ db_connection ['driver ' ];
108+ $ command .= ' -t ' . $ db_connection ['driver ' ];
108109
109110 if (isset ($ db_connection ['username ' ]))
110111 $ command .= " -u " . $ db_connection ['username ' ];
111112
112113 if ( isset ($ db_connection ['password ' ]) && !empty ($ db_connection ['password ' ]) )
113- $ command .= " -p " . $ db_connection ['password ' ];
114+ $ command .= ' -p ' . $ db_connection ['password ' ];
114115
115116 if ( isset ($ db_connection ['host ' ]) && !empty ($ db_connection ['host ' ]) )
116- $ command .= " -H " . $ db_connection ['host ' ];
117+ $ command .= ' -H ' . $ db_connection ['host ' ];
117118
118119 if ( isset ($ db_connection ['database ' ]) && !empty ($ db_connection ['database ' ]) )
119- $ command .= " -n " . $ db_connection ['database ' ];
120+ $ command .= ' -n ' . $ db_connection ['database ' ];
120121
121122 if ( isset ($ db_connection ['port ' ]) && !empty ($ db_connection ['port ' ]) )
122- $ command .= " --db-port " . $ db_connection ['port ' ];
123+ $ command .= ' --db-port ' . $ db_connection ['port ' ];
123124
124125 if ( isset ($ db_connection ['jdbc_driver ' ]) && !empty ($ db_connection ['jdbc_driver ' ]) )
125- $ command .= " --db-driver " . $ db_connection ['jdbc_driver ' ];
126+ $ command .= ' --db-driver ' . $ db_connection ['jdbc_driver ' ];
126127
127128 if ( isset ($ db_connection ['jdbc_url ' ]) && !empty ($ db_connection ['jdbc_url ' ]) )
128- $ command .= " --db-url " . $ db_connection ['jdbc_url ' ];
129+ $ command .= ' --db-url ' . $ db_connection ['jdbc_url ' ];
129130
130131 if ( isset ($ db_connection ['jdbc_dir ' ]) && !empty ($ db_connection ['jdbc_dir ' ]) )
131132 $ command .= ' --jdbc-dir ' . $ db_connection ['jdbc_dir ' ];
132133
133134 if ( isset ($ db_connection ['db_sid ' ]) && !empty ($ db_connection ['db_sid ' ]) )
134135 $ command .= ' --db-sid ' . $ db_connection ['db_sid ' ];
135136
136- if ( isset ($ db_connection ['xml_xpath ' ]) )
137- $ command .= ' --xml-xpath ' . $ db_connection ['xml_xpath ' ];
138-
139- if ( isset ($ db_connection ['data_file ' ]) )
140- $ command .= ' --data-file ' . "\"" .$ db_connection ['data_file ' ]."\"" ;
137+ if ( isset ($ db_connection ['data_file ' ]) )
138+ $ command .= ' --data-file ' . $ db_connection ['data_file ' ];
141139
142140 }
143141
@@ -151,11 +149,11 @@ public function process($input_file, $output_file = false, $format = array("pdf"
151149 public function list_parameters ($ input_file )
152150 {
153151 if (is_null ($ input_file ) || empty ($ input_file ))
154- throw new \Exception (" No input file " , 1 );
152+ throw new \Exception (' No input file ' , 1 );
155153
156154 $ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
157155
158- $ command .= " list_parameters " ;
156+ $ command .= ' list_parameters ' ;
159157
160158 $ command .= "\"$ input_file \"" ;
161159
@@ -173,7 +171,7 @@ public function execute($run_as_user = false)
173171 {
174172
175173 if ( $ run_as_user !== false && strlen ($ run_as_user > 0 ) && !$ this ->windows )
176- $ this ->the_command = " su -u " . $ run_as_user . " -c \"" . $ this ->the_command . "\"" ;
174+ $ this ->the_command = ' su -u ' . $ run_as_user . " -c \"" . $ this ->the_command . "\"" ;
177175
178176 $ output = array ();
179177 $ return_var = 0 ;
@@ -182,11 +180,11 @@ public function execute($run_as_user = false)
182180 chdir ($ this ->path_executable );
183181 exec ($ this ->the_command , $ output , $ return_var );
184182 } else {
185- throw new \Exception (" Invalid resource directory. " , 1 );
183+ throw new \Exception (' Invalid resource directory. ' , 1 );
186184 }
187185
188186 if ($ return_var != 0 )
189- 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 );
187+ 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 );
190188
191189 return $ output ;
192190 }
0 commit comments