@@ -18,7 +18,7 @@ function __construct($resource_dir = false)
18
18
{
19
19
$ this ->path_executable = __DIR__ . '/../JasperStarter/bin ' ; //Path to executable
20
20
if (strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' )
21
- $ this ->windows = true ;
21
+ $ this ->windows = true ;
22
22
23
23
if (!$ resource_dir ) {
24
24
$ this ->resource_directory = __DIR__ . '/../../../vendor/geekcom/jasperphp/src/JasperStarter/bin ' ;
@@ -41,7 +41,7 @@ public static function __callStatic($method, $parameters)
41
41
42
42
public function compile ($ input_file , $ output_file = false , $ background = true , $ redirect_output = true )
43
43
{
44
- if (is_null ($ input_file ) || empty ($ input_file ))
44
+ if (is_null ($ input_file ) || empty ($ input_file ))
45
45
throw new \Exception ('No input file ' , 1 );
46
46
47
47
$ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
@@ -50,31 +50,29 @@ public function compile($input_file, $output_file = false, $background = true, $
50
50
51
51
$ command .= "\"$ input_file \"" ;
52
52
53
- if ( $ output_file !== false )
53
+ if ( $ output_file !== false )
54
54
$ command .= ' -o ' . "\"$ output_file \"" ;
55
55
56
- $ this ->redirect_output = $ redirect_output ;
57
- $ this ->background = $ background ;
58
- $ this ->the_command = $ command ;
56
+ $ this ->redirect_output = $ redirect_output ;
57
+ $ this ->background = $ background ;
58
+ $ this ->the_command = $ command ;
59
59
60
60
return $ this ;
61
61
}
62
62
63
63
public function process ($ input_file , $ output_file = false , $ format = array ('pdf ' ), $ parameters = array (), $ db_connection = array (), $ locale = false , $ background = true , $ redirect_output = true )
64
64
{
65
- if (is_null ($ input_file ) || empty ($ input_file ))
65
+ if (is_null ($ input_file ) || empty ($ input_file ))
66
66
throw new \Exception ('No input file ' , 1 );
67
67
68
- if ( is_array ($ format ) )
69
- {
70
- foreach ($ format as $ key )
71
- {
72
- if ( !in_array ($ key , $ this ->formats ))
68
+ if (is_array ($ format )) {
69
+ foreach ($ format as $ key ) {
70
+ if (!in_array ($ key , $ this ->formats ))
73
71
throw new \Exception ('Invalid format! ' , 1 );
74
72
}
75
73
} else {
76
- if ( !in_array ($ format , $ this ->formats ))
77
- throw new \Exception ('Invalid format! ' , 1 );
74
+ if ( !in_array ($ format , $ this ->formats ))
75
+ throw new \Exception ('Invalid format! ' , 1 );
78
76
}
79
77
80
78
$ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
@@ -85,78 +83,75 @@ public function process($input_file, $output_file = false, $format = array('pdf'
85
83
86
84
$ command .= "\"$ input_file \"" ;
87
85
88
- if ( $ output_file !== false )
86
+ if ( $ output_file !== false )
89
87
$ command .= ' -o ' . "\"$ output_file \"" ;
90
88
91
- if ( is_array ($ format ) )
89
+ if ( is_array ($ format ))
92
90
$ command .= ' -f ' . join (' ' , $ format );
93
91
else
94
92
$ command .= ' -f ' . $ format ;
95
-
96
-
97
- if ( count ($ parameters ) > 0 )
98
- {
93
+
94
+
95
+ if (count ($ parameters ) > 0 ) {
99
96
$ command .= ' -P ' ;
100
97
101
- foreach ($ parameters as $ key => $ value )
102
- {
98
+ foreach ($ parameters as $ key => $ value ) {
103
99
$ param = $ key . '=" ' . $ value . '" ' ;
104
- $ command .= " " .$ param . " " ;
100
+ $ command .= " " . $ param . " " ;
105
101
}
106
102
107
103
}
108
104
109
- if ( count ($ db_connection ) > 0 )
110
- {
105
+ if (count ($ db_connection ) > 0 ) {
111
106
$ command .= ' -t ' . $ db_connection ['driver ' ];
112
107
113
- if (isset ($ db_connection ['username ' ]))
108
+ if (isset ($ db_connection ['username ' ]))
114
109
$ command .= " -u " . $ db_connection ['username ' ];
115
110
116
- if ( isset ($ db_connection ['password ' ]) && !empty ($ db_connection ['password ' ]) )
111
+ if ( isset ($ db_connection ['password ' ]) && !empty ($ db_connection ['password ' ]))
117
112
$ command .= ' -p ' . $ db_connection ['password ' ];
118
113
119
- if ( isset ($ db_connection ['host ' ]) && !empty ($ db_connection ['host ' ]) )
114
+ if ( isset ($ db_connection ['host ' ]) && !empty ($ db_connection ['host ' ]))
120
115
$ command .= ' -H ' . $ db_connection ['host ' ];
121
116
122
- if ( isset ($ db_connection ['database ' ]) && !empty ($ db_connection ['database ' ]) )
117
+ if ( isset ($ db_connection ['database ' ]) && !empty ($ db_connection ['database ' ]))
123
118
$ command .= ' -n ' . $ db_connection ['database ' ];
124
119
125
- if ( isset ($ db_connection ['port ' ]) && !empty ($ db_connection ['port ' ]) )
120
+ if ( isset ($ db_connection ['port ' ]) && !empty ($ db_connection ['port ' ]))
126
121
$ command .= ' --db-port ' . $ db_connection ['port ' ];
127
122
128
- if ( isset ($ db_connection ['jdbc_driver ' ]) && !empty ($ db_connection ['jdbc_driver ' ]) )
123
+ if ( isset ($ db_connection ['jdbc_driver ' ]) && !empty ($ db_connection ['jdbc_driver ' ]))
129
124
$ command .= ' --db-driver ' . $ db_connection ['jdbc_driver ' ];
130
125
131
- if ( isset ($ db_connection ['jdbc_url ' ]) && !empty ($ db_connection ['jdbc_url ' ]) )
126
+ if ( isset ($ db_connection ['jdbc_url ' ]) && !empty ($ db_connection ['jdbc_url ' ]))
132
127
$ command .= ' --db-url ' . $ db_connection ['jdbc_url ' ];
133
128
134
- if ( isset ($ db_connection ['jdbc_dir ' ]) && !empty ($ db_connection ['jdbc_dir ' ]) )
129
+ if (isset ($ db_connection ['jdbc_dir ' ]) && !empty ($ db_connection ['jdbc_dir ' ]))
135
130
$ command .= ' --jdbc-dir ' . $ db_connection ['jdbc_dir ' ];
136
131
137
- if ( isset ($ db_connection ['db_sid ' ]) && !empty ($ db_connection ['db_sid ' ]) )
132
+ if (isset ($ db_connection ['db_sid ' ]) && !empty ($ db_connection ['db_sid ' ]))
138
133
$ command .= ' --db-sid ' . $ db_connection ['db_sid ' ];
139
134
140
- if ( isset ($ db_connection ['xml_xpath ' ]) )
135
+ if (isset ($ db_connection ['xml_xpath ' ]))
141
136
$ command .= ' --xml-xpath ' . $ db_connection ['xml_xpath ' ];
142
137
143
- if ( isset ($ db_connection ['data_file ' ]) )
138
+ if (isset ($ db_connection ['data_file ' ]))
144
139
$ command .= ' --data-file ' . $ db_connection ['data_file ' ];
145
140
146
- if ( isset ($ db_connection ['json_query ' ]) )
141
+ if (isset ($ db_connection ['json_query ' ]))
147
142
$ command .= ' --json-query ' . $ db_connection ['json_query ' ];
148
143
}
149
144
150
- $ this ->redirect_output = $ redirect_output ;
151
- $ this ->background = $ background ;
152
- $ this ->the_command = $ command ;
145
+ $ this ->redirect_output = $ redirect_output ;
146
+ $ this ->background = $ background ;
147
+ $ this ->the_command = $ command ;
153
148
154
149
return $ this ;
155
150
}
156
151
157
152
public function list_parameters ($ input_file )
158
153
{
159
- if (is_null ($ input_file ) || empty ($ input_file ))
154
+ if (is_null ($ input_file ) || empty ($ input_file ))
160
155
throw new \Exception ('No input file ' , 1 );
161
156
162
157
$ command = ($ this ->windows ) ? $ this ->executable : './ ' . $ this ->executable ;
@@ -178,20 +173,20 @@ public function output()
178
173
public function execute ($ run_as_user = false )
179
174
{
180
175
181
- if ( $ run_as_user !== false && strlen ($ run_as_user > 0 ) && !$ this ->windows )
176
+ if ( $ run_as_user !== false && strlen ($ run_as_user > 0 ) && !$ this ->windows )
182
177
$ this ->the_command = 'su -u ' . $ run_as_user . " -c \"" . $ this ->the_command . "\"" ;
183
178
184
179
$ output = array ();
185
180
$ return_var = 0 ;
186
181
187
- if (is_dir ($ this ->path_executable )){
182
+ if (is_dir ($ this ->path_executable )) {
188
183
chdir ($ this ->path_executable );
189
184
exec ($ this ->the_command , $ output , $ return_var );
190
185
} else {
191
186
throw new \Exception ('Invalid resource directory. ' , 1 );
192
187
}
193
188
194
- if ($ return_var != 0 )
189
+ if ($ return_var != 0 )
195
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 );
196
191
197
192
return $ output ;
0 commit comments