diff --git a/README.md b/README.md index 0692bde..2115dbc 100755 --- a/README.md +++ b/README.md @@ -153,9 +153,12 @@ $output = __DIR__ . '/vendor/geekcom/phpjasper/examples'; $jasper = new JasperPHP; $jasper->process( - $input, - $output, - array("pdf", "rtf") + $input, //input + $output, //output + ['pdf', 'rtf'], //formats + [], //parameters + [], //data_source + 'en' //locale )->execute(); ``` @@ -187,7 +190,6 @@ foreach($output as $parameter_description) We can also specify parameters for connecting to database: ```php - require __DIR__ . '/vendor/autoload.php'; use JasperPHP\JasperPHP; @@ -203,7 +205,7 @@ $jasper->process( $input, $output, $format, - [], + [], //parameters [ 'driver' => 'postgres', 'username' => 'DB_USERNAME', @@ -212,7 +214,7 @@ $jasper->process( 'database' => 'DB_DATABASE', 'schema' => 'DB_SCHEMA', 'port' => '5432' - ], + ], $locale )->execute(); ``` @@ -242,7 +244,7 @@ $jasper->process( $input, $output, $format, - [], + [], //parameters [ 'driver' => 'generic', 'host' => '127.0.0.1', @@ -295,14 +297,15 @@ use JasperPHP\JasperPHP; Route::get('/reports', function () { - $output = public_path() . '/report/'.time().'_hello_world'; $report = new JasperPHP; + $report->process( - public_path() . '/report/hello_world.jrxml', - $output, - array('pdf', 'rtf', 'xml'), - array(), - array() + public_path() . '/report/hello_world.jrxml', //input + public_path() . '/report/'.time().'_hello_world', //output + ['pdf', 'rtf', 'xml'], //formats + [], //parameters + [], //data_source + '', //locale )->execute(); }); ``` @@ -336,12 +339,12 @@ public function xmlToPdf() $php_jasper = new JasperPHP; $php_jasper->process( - public_path() . '/report/CancelAck.jrxml', - $output, - array($ext), - array(), - array('data_file' => $data_file, 'driver' => $driver, 'xml_xpath' => $xml_xpath), - $locale + public_path() . '/report/CancelAck.jrxml', //input + $output, //output + [$ext], //formats + [], //parameters + ['data_file' => $data_file, 'driver' => $driver, 'xml_xpath' => $xml_xpath], //data_source + $locale //locale )->execute(); header('Content-Description: File Transfer'); @@ -398,11 +401,11 @@ public function jsonToPdf() $php_jasper = new JasperPHP; $php_jasper->process( - public_path() . '/report/json.jrxml', - $output, - array($ext), - array(), - array('data_file' => $data_file, 'driver' => $driver, 'json_query' => $json_query), + public_path() . '/report/json.jrxml', //input + $output, //output + [$ext], //formats + [], //parameters + ['data_file' => $data_file, 'driver' => $driver, 'json_query' => $json_query], $locale )->execute(); diff --git a/src/JasperPHP/JasperPHP.php b/src/JasperPHP/JasperPHP.php index 9ccb32a..fc43772 100755 --- a/src/JasperPHP/JasperPHP.php +++ b/src/JasperPHP/JasperPHP.php @@ -7,11 +7,9 @@ class JasperPHP protected $executable = 'jasperstarter'; //executable jasperstarter protected $path_executable; protected $the_command; - protected $redirect_output; - protected $background; protected $windows = false; - protected $formats = array('pdf', 'rtf', 'xls', 'xlsx', 'docx', 'odt', 'ods', 'pptx', 'csv', 'html', 'xhtml', 'xml', 'jrprint'); + protected $formats = ['pdf', 'rtf', 'xls', 'xlsx', 'docx', 'odt', 'ods', 'pptx', 'csv', 'html', 'xhtml', 'xml', 'jrprint']; protected $resource_directory; //Path to report resource dir or jar file function __construct($resource_dir = false) @@ -41,7 +39,7 @@ public static function __callStatic($method, $parameters) return call_user_func_array(array(new $model, $method), $parameters); } - public function compile($input_file, $output_file = false, $background = true, $redirect_output = true) + public function compile($input_file, $output_file = false) { if (is_null($input_file) || empty($input_file)) { throw new \Exception('No input file', 1); @@ -57,14 +55,12 @@ public function compile($input_file, $output_file = false, $background = true, $ $command .= ' -o ' . "\"$output_file\""; } - $this->redirect_output = $redirect_output; - $this->background = $background; $this->the_command = $command; return $this; } - public function process($input_file, $output_file = false, $format = array('pdf'), $parameters = array(), $db_connection = array(), $locale = false, $background = true, $redirect_output = true) + public function process($input_file, $output_file = false, $format = ['pdf'], $parameters = [], $db_connection = [], $locale = false) { if (is_null($input_file) || empty($input_file)) { throw new \Exception('No input file', 1); @@ -100,7 +96,6 @@ public function process($input_file, $output_file = false, $format = array('pdf' $command .= ' -f ' . $format; } - if (count($parameters) > 0) { $command .= ' -P '; @@ -163,8 +158,6 @@ public function process($input_file, $output_file = false, $format = array('pdf' } } - $this->redirect_output = $redirect_output; - $this->background = $background; $this->the_command = $command; return $this; @@ -194,12 +187,11 @@ public function output() public function execute($run_as_user = false) { - if ($run_as_user !== false && strlen($run_as_user > 0) && !$this->windows) { $this->the_command = 'su -u ' . $run_as_user . " -c \"" . $this->the_command . "\""; } - $output = array(); + $output = []; $return_var = 0; if (is_dir($this->path_executable)) {