4
4
5
5
class JasperPHP
6
6
{
7
- protected $ executable = " jasperstarter " ; //executable jasperstarter
7
+ protected $ executable = ' jasperstarter ' ; //executable jasperstarter
8
8
protected $ path_executable = __DIR__ . '/../JasperStarter/bin/ ' ; //Path to executable
9
9
protected $ the_command ;
10
10
protected $ redirect_output ;
@@ -20,10 +20,10 @@ function __construct($resource_dir = false)
20
20
$ this ->windows = true ;
21
21
22
22
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 ' ;
24
24
} else {
25
25
if (!file_exists ($ resource_dir ))
26
- throw new \Exception (" Invalid resource directory. " , 1 );
26
+ throw new \Exception (' Invalid resource directory. ' , 1 );
27
27
28
28
$ this ->resource_directory = $ resource_dir ;
29
29
}
@@ -41,16 +41,16 @@ public static function __callStatic($method, $parameters)
41
41
public function compile ($ input_file , $ output_file = false , $ background = true , $ redirect_output = true )
42
42
{
43
43
if (is_null ($ input_file ) || empty ($ input_file ))
44
- throw new \Exception (" No input file " , 1 );
44
+ throw new \Exception (' No input file ' , 1 );
45
45
46
46
$ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
47
47
48
- $ command .= " compile " ;
48
+ $ command .= ' compile ' ;
49
49
50
50
$ command .= "\"$ input_file \"" ;
51
51
52
52
if ( $ output_file !== false )
53
- $ command .= " -o " . "\"$ output_file \"" ;
53
+ $ command .= ' -o ' . "\"$ output_file \"" ;
54
54
55
55
$ this ->redirect_output = $ redirect_output ;
56
56
$ this ->background = $ background ;
@@ -59,85 +59,83 @@ public function compile($input_file, $output_file = false, $background = true, $
59
59
return $ this ;
60
60
}
61
61
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 )
63
63
{
64
64
if (is_null ($ input_file ) || empty ($ input_file ))
65
- throw new \Exception (" No input file " , 1 );
65
+ throw new \Exception (' No input file ' , 1 );
66
66
67
67
if ( is_array ($ format ) )
68
68
{
69
69
foreach ($ format as $ key )
70
70
{
71
71
if ( !in_array ($ key , $ this ->formats ))
72
- throw new \Exception (" Invalid format! " , 1 );
72
+ throw new \Exception (' Invalid format! ' , 1 );
73
73
}
74
74
} else {
75
75
if ( !in_array ($ format , $ this ->formats ))
76
- throw new \Exception (" Invalid format! " , 1 );
76
+ throw new \Exception (' Invalid format! ' , 1 );
77
77
}
78
78
79
79
$ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
80
80
81
- $ command .= " process " ;
81
+ $ command .= ' process ' ;
82
82
83
83
$ command .= "\"$ input_file \"" ;
84
84
85
85
if ( $ output_file !== false )
86
- $ command .= " -o " . "\"$ output_file \"" ;
86
+ $ command .= ' -o ' . "\"$ output_file \"" ;
87
87
88
88
if ( is_array ($ format ) )
89
- $ command .= " -f " . join (" " , $ format );
89
+ $ command .= ' -f ' . join (' ' , $ format );
90
90
else
91
- $ command .= " -f " . $ format ;
91
+ $ command .= ' -f ' . $ format ;
92
92
/*
93
93
// Resources dir
94
94
$command .= " -r " . $this->resource_directory;
95
95
*/
96
96
if ( count ($ parameters ) > 0 )
97
97
{
98
- $ command .= " -P " ;
98
+ $ command .= ' -P ' ;
99
99
foreach ($ parameters as $ key => $ value )
100
100
{
101
- $ command .= " " . $ key . "= " . $ value ;
101
+ $ param = $ key . '= ' . $ value . ' ' ;
102
+ $ command .= "\"$ param \"" ;
102
103
}
103
104
}
104
105
105
106
if ( count ($ db_connection ) > 0 )
106
107
{
107
- $ command .= " -t " . $ db_connection ['driver ' ];
108
+ $ command .= ' -t ' . $ db_connection ['driver ' ];
108
109
109
110
if (isset ($ db_connection ['username ' ]))
110
111
$ command .= " -u " . $ db_connection ['username ' ];
111
112
112
113
if ( isset ($ db_connection ['password ' ]) && !empty ($ db_connection ['password ' ]) )
113
- $ command .= " -p " . $ db_connection ['password ' ];
114
+ $ command .= ' -p ' . $ db_connection ['password ' ];
114
115
115
116
if ( isset ($ db_connection ['host ' ]) && !empty ($ db_connection ['host ' ]) )
116
- $ command .= " -H " . $ db_connection ['host ' ];
117
+ $ command .= ' -H ' . $ db_connection ['host ' ];
117
118
118
119
if ( isset ($ db_connection ['database ' ]) && !empty ($ db_connection ['database ' ]) )
119
- $ command .= " -n " . $ db_connection ['database ' ];
120
+ $ command .= ' -n ' . $ db_connection ['database ' ];
120
121
121
122
if ( isset ($ db_connection ['port ' ]) && !empty ($ db_connection ['port ' ]) )
122
- $ command .= " --db-port " . $ db_connection ['port ' ];
123
+ $ command .= ' --db-port ' . $ db_connection ['port ' ];
123
124
124
125
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 ' ];
126
127
127
128
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 ' ];
129
130
130
131
if ( isset ($ db_connection ['jdbc_dir ' ]) && !empty ($ db_connection ['jdbc_dir ' ]) )
131
132
$ command .= ' --jdbc-dir ' . $ db_connection ['jdbc_dir ' ];
132
133
133
134
if ( isset ($ db_connection ['db_sid ' ]) && !empty ($ db_connection ['db_sid ' ]) )
134
135
$ command .= ' --db-sid ' . $ db_connection ['db_sid ' ];
135
136
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 ' ];
141
139
142
140
}
143
141
@@ -151,11 +149,11 @@ public function process($input_file, $output_file = false, $format = array("pdf"
151
149
public function list_parameters ($ input_file )
152
150
{
153
151
if (is_null ($ input_file ) || empty ($ input_file ))
154
- throw new \Exception (" No input file " , 1 );
152
+ throw new \Exception (' No input file ' , 1 );
155
153
156
154
$ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
157
155
158
- $ command .= " list_parameters " ;
156
+ $ command .= ' list_parameters ' ;
159
157
160
158
$ command .= "\"$ input_file \"" ;
161
159
@@ -173,7 +171,7 @@ public function execute($run_as_user = false)
173
171
{
174
172
175
173
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 . "\"" ;
177
175
178
176
$ output = array ();
179
177
$ return_var = 0 ;
@@ -182,11 +180,11 @@ public function execute($run_as_user = false)
182
180
chdir ($ this ->path_executable );
183
181
exec ($ this ->the_command , $ output , $ return_var );
184
182
} else {
185
- throw new \Exception (" Invalid resource directory. " , 1 );
183
+ throw new \Exception (' Invalid resource directory. ' , 1 );
186
184
}
187
185
188
186
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 );
190
188
191
189
return $ output ;
192
190
}
0 commit comments