Skip to content

Commit 6fd98fa

Browse files
committed
README.md updated, refactoring
1 parent 9db72d6 commit 6fd98fa

File tree

2 files changed

+31
-36
lines changed

2 files changed

+31
-36
lines changed

README.md

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,12 @@ $output = __DIR__ . '/vendor/geekcom/phpjasper/examples';
153153
$jasper = new JasperPHP;
154154

155155
$jasper->process(
156-
$input,
157-
$output,
158-
array("pdf", "rtf")
156+
$input, //input
157+
$output, //output
158+
['pdf', 'rtf'], //formats
159+
[], //parameters
160+
[], //data_source
161+
'en' //locale
159162
)->execute();
160163
```
161164

@@ -187,7 +190,6 @@ foreach($output as $parameter_description)
187190
We can also specify parameters for connecting to database:
188191

189192
```php
190-
191193
require __DIR__ . '/vendor/autoload.php';
192194

193195
use JasperPHP\JasperPHP;
@@ -203,7 +205,7 @@ $jasper->process(
203205
$input,
204206
$output,
205207
$format,
206-
[],
208+
[], //parameters
207209
[
208210
'driver' => 'postgres',
209211
'username' => 'DB_USERNAME',
@@ -212,7 +214,7 @@ $jasper->process(
212214
'database' => 'DB_DATABASE',
213215
'schema' => 'DB_SCHEMA',
214216
'port' => '5432'
215-
],
217+
],
216218
$locale
217219
)->execute();
218220
```
@@ -242,7 +244,7 @@ $jasper->process(
242244
$input,
243245
$output,
244246
$format,
245-
[],
247+
[], //parameters
246248
[
247249
'driver' => 'generic',
248250
'host' => '127.0.0.1',
@@ -295,14 +297,15 @@ use JasperPHP\JasperPHP;
295297

296298
Route::get('/reports', function () {
297299

298-
$output = public_path() . '/report/'.time().'_hello_world';
299300
$report = new JasperPHP;
301+
300302
$report->process(
301-
public_path() . '/report/hello_world.jrxml',
302-
$output,
303-
array('pdf', 'rtf', 'xml'),
304-
array(),
305-
array()
303+
public_path() . '/report/hello_world.jrxml', //input
304+
public_path() . '/report/'.time().'_hello_world', //output
305+
['pdf', 'rtf', 'xml'], //formats
306+
[], //parameters
307+
[], //data_source
308+
'', //locale
306309
)->execute();
307310
});
308311
```
@@ -336,12 +339,12 @@ public function xmlToPdf()
336339
$php_jasper = new JasperPHP;
337340

338341
$php_jasper->process(
339-
public_path() . '/report/CancelAck.jrxml',
340-
$output,
341-
array($ext),
342-
array(),
343-
array('data_file' => $data_file, 'driver' => $driver, 'xml_xpath' => $xml_xpath),
344-
$locale
342+
public_path() . '/report/CancelAck.jrxml', //input
343+
$output, //output
344+
[$ext], //formats
345+
[], //parameters
346+
['data_file' => $data_file, 'driver' => $driver, 'xml_xpath' => $xml_xpath], //data_source
347+
$locale //locale
345348
)->execute();
346349

347350
header('Content-Description: File Transfer');
@@ -398,11 +401,11 @@ public function jsonToPdf()
398401
$php_jasper = new JasperPHP;
399402

400403
$php_jasper->process(
401-
public_path() . '/report/json.jrxml',
402-
$output,
403-
array($ext),
404-
array(),
405-
array('data_file' => $data_file, 'driver' => $driver, 'json_query' => $json_query),
404+
public_path() . '/report/json.jrxml', //input
405+
$output, //output
406+
[$ext], //formats
407+
[], //parameters
408+
['data_file' => $data_file, 'driver' => $driver, 'json_query' => $json_query],
406409
$locale
407410
)->execute();
408411

src/JasperPHP/JasperPHP.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ class JasperPHP
77
protected $executable = 'jasperstarter'; //executable jasperstarter
88
protected $path_executable;
99
protected $the_command;
10-
protected $redirect_output;
11-
protected $background;
1210
protected $windows = false;
1311

14-
protected $formats = array('pdf', 'rtf', 'xls', 'xlsx', 'docx', 'odt', 'ods', 'pptx', 'csv', 'html', 'xhtml', 'xml', 'jrprint');
12+
protected $formats = ['pdf', 'rtf', 'xls', 'xlsx', 'docx', 'odt', 'ods', 'pptx', 'csv', 'html', 'xhtml', 'xml', 'jrprint'];
1513
protected $resource_directory; //Path to report resource dir or jar file
1614

1715
function __construct($resource_dir = false)
@@ -41,7 +39,7 @@ public static function __callStatic($method, $parameters)
4139
return call_user_func_array(array(new $model, $method), $parameters);
4240
}
4341

44-
public function compile($input_file, $output_file = false, $background = true, $redirect_output = true)
42+
public function compile($input_file, $output_file = false)
4543
{
4644
if (is_null($input_file) || empty($input_file)) {
4745
throw new \Exception('No input file', 1);
@@ -57,14 +55,12 @@ public function compile($input_file, $output_file = false, $background = true, $
5755
$command .= ' -o ' . "\"$output_file\"";
5856
}
5957

60-
$this->redirect_output = $redirect_output;
61-
$this->background = $background;
6258
$this->the_command = $command;
6359

6460
return $this;
6561
}
6662

67-
public function process($input_file, $output_file = false, $format = array('pdf'), $parameters = array(), $db_connection = array(), $locale = false, $background = true, $redirect_output = true)
63+
public function process($input_file, $output_file = false, $format = ['pdf'], $parameters = [], $db_connection = [], $locale = false)
6864
{
6965
if (is_null($input_file) || empty($input_file)) {
7066
throw new \Exception('No input file', 1);
@@ -100,7 +96,6 @@ public function process($input_file, $output_file = false, $format = array('pdf'
10096
$command .= ' -f ' . $format;
10197
}
10298

103-
10499
if (count($parameters) > 0) {
105100
$command .= ' -P ';
106101

@@ -163,8 +158,6 @@ public function process($input_file, $output_file = false, $format = array('pdf'
163158
}
164159
}
165160

166-
$this->redirect_output = $redirect_output;
167-
$this->background = $background;
168161
$this->the_command = $command;
169162

170163
return $this;
@@ -194,12 +187,11 @@ public function output()
194187

195188
public function execute($run_as_user = false)
196189
{
197-
198190
if ($run_as_user !== false && strlen($run_as_user > 0) && !$this->windows) {
199191
$this->the_command = 'su -u ' . $run_as_user . " -c \"" . $this->the_command . "\"";
200192
}
201193

202-
$output = array();
194+
$output = [];
203195
$return_var = 0;
204196

205197
if (is_dir($this->path_executable)) {

0 commit comments

Comments
 (0)