Skip to content

Commit

Permalink
README.md updated, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
geekcom committed Jan 10, 2017
1 parent 9db72d6 commit 6fd98fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 36 deletions.
51 changes: 27 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
```

Expand Down Expand Up @@ -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;
Expand All @@ -203,7 +205,7 @@ $jasper->process(
$input,
$output,
$format,
[],
[], //parameters
[
'driver' => 'postgres',
'username' => 'DB_USERNAME',
Expand All @@ -212,7 +214,7 @@ $jasper->process(
'database' => 'DB_DATABASE',
'schema' => 'DB_SCHEMA',
'port' => '5432'
],
],
$locale
)->execute();
```
Expand Down Expand Up @@ -242,7 +244,7 @@ $jasper->process(
$input,
$output,
$format,
[],
[], //parameters
[
'driver' => 'generic',
'host' => '127.0.0.1',
Expand Down Expand Up @@ -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();
});
```
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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();

Expand Down
16 changes: 4 additions & 12 deletions src/JasperPHP/JasperPHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -100,7 +96,6 @@ public function process($input_file, $output_file = false, $format = array('pdf'
$command .= ' -f ' . $format;
}


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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 6fd98fa

Please sign in to comment.