Skip to content

Commit

Permalink
Merge remote-tracking branch 'lavela/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
geekcom committed Mar 11, 2016
2 parents c4e55e8 + 9db7b1a commit 0a9f80c
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions src/JasperPHP/JasperPHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class JasperPHP
{
protected $executable = "jasperstarter"; //executable jasperstarter
protected $executable = 'jasperstarter'; //executable jasperstarter
protected $path_executable = __DIR__ . '/../JasperStarter/bin/'; //Path to executable
protected $the_command;
protected $redirect_output;
Expand All @@ -20,10 +20,10 @@ function __construct($resource_dir = false)
$this->windows = true;

if (!$resource_dir) {
$this->resource_directory = __DIR__ . "/../../../vendor/cossou/jasperphp/src/JasperStarter/bin";
$this->resource_directory = __DIR__ . '/../../../vendor/cossou/jasperphp/src/JasperStarter/bin';
} else {
if (!file_exists($resource_dir))
throw new \Exception("Invalid resource directory.", 1);
throw new \Exception('Invalid resource directory.', 1);

$this->resource_directory = $resource_dir;
}
Expand All @@ -41,16 +41,16 @@ public static function __callStatic($method, $parameters)
public function compile($input_file, $output_file = false, $background = true, $redirect_output = true)
{
if(is_null($input_file) || empty($input_file))
throw new \Exception("No input file", 1);
throw new \Exception('No input file', 1);

$command = ($this->windows) ? $this->executable : './' . $this->executable;

$command .= " compile ";
$command .= ' compile ';

$command .= "\"$input_file\"";

if( $output_file !== false )
$command .= " -o " . "\"$output_file\"";
$command .= ' -o ' . "\"$output_file\"";

$this->redirect_output = $redirect_output;
$this->background = $background;
Expand All @@ -59,85 +59,83 @@ public function compile($input_file, $output_file = false, $background = true, $
return $this;
}

public function process($input_file, $output_file = false, $format = array("pdf"), $parameters = array(), $db_connection = array(), $background = true, $redirect_output = true)
public function process($input_file, $output_file = false, $format = array('pdf'), $parameters = array(), $db_connection = array(), $background = true, $redirect_output = true)
{
if(is_null($input_file) || empty($input_file))
throw new \Exception("No input file", 1);
throw new \Exception('No input file', 1);

if( is_array($format) )
{
foreach ($format as $key)
{
if( !in_array($key, $this->formats))
throw new \Exception("Invalid format!", 1);
throw new \Exception('Invalid format!', 1);
}
} else {
if( !in_array($format, $this->formats))
throw new \Exception("Invalid format!", 1);
throw new \Exception('Invalid format!', 1);
}

$command = ($this->windows) ? $this->executable : './' . $this->executable;

$command .= " process ";
$command .= ' process ';

$command .= "\"$input_file\"";

if( $output_file !== false )
$command .= " -o " . "\"$output_file\"";
$command .= ' -o ' . "\"$output_file\"";

if( is_array($format) )
$command .= " -f " . join(" ", $format);
$command .= ' -f ' . join(' ', $format);
else
$command .= " -f " . $format;
$command .= ' -f ' . $format;
/*
// Resources dir
$command .= " -r " . $this->resource_directory;
*/
if( count($parameters) > 0 )
{
$command .= " -P";
$command .= ' -P ';
foreach ($parameters as $key => $value)
{
$command .= " " . $key . "=" . $value;
$param = $key . '=' . $value . ' ';
$command .= "\"$param\"";
}
}

if( count($db_connection) > 0 )
{
$command .= " -t " . $db_connection['driver'];
$command .= ' -t ' . $db_connection['driver'];

if(isset($db_connection['username']))
$command .= " -u " . $db_connection['username'];

if( isset($db_connection['password']) && !empty($db_connection['password']) )
$command .= " -p " . $db_connection['password'];
$command .= ' -p ' . $db_connection['password'];

if( isset($db_connection['host']) && !empty($db_connection['host']) )
$command .= " -H " . $db_connection['host'];
$command .= ' -H ' . $db_connection['host'];

if( isset($db_connection['database']) && !empty($db_connection['database']) )
$command .= " -n " . $db_connection['database'];
$command .= ' -n ' . $db_connection['database'];

if( isset($db_connection['port']) && !empty($db_connection['port']) )
$command .= " --db-port " . $db_connection['port'];
$command .= ' --db-port ' . $db_connection['port'];

if( isset($db_connection['jdbc_driver']) && !empty($db_connection['jdbc_driver']) )
$command .= " --db-driver " . $db_connection['jdbc_driver'];
$command .= ' --db-driver ' . $db_connection['jdbc_driver'];

if( isset($db_connection['jdbc_url']) && !empty($db_connection['jdbc_url']) )
$command .= " --db-url " . $db_connection['jdbc_url'];
$command .= ' --db-url ' . $db_connection['jdbc_url'];

if ( isset($db_connection['jdbc_dir']) && !empty($db_connection['jdbc_dir']) )
$command .= ' --jdbc-dir ' . $db_connection['jdbc_dir'];

if ( isset($db_connection['db_sid']) && !empty($db_connection['db_sid']) )
$command .= ' --db-sid ' . $db_connection['db_sid'];

if ( isset($db_connection['xml_xpath']) )
$command .= ' --xml-xpath ' . $db_connection['xml_xpath'];

if ( isset($db_connection['data_file']) )
$command .= ' --data-file ' . "\"".$db_connection['data_file']."\"";
if ( isset($db_connection['data_file']) )
$command .= ' --data-file ' . $db_connection['data_file'];

}

Expand All @@ -151,11 +149,11 @@ public function process($input_file, $output_file = false, $format = array("pdf"
public function list_parameters($input_file)
{
if(is_null($input_file) || empty($input_file))
throw new \Exception("No input file", 1);
throw new \Exception('No input file', 1);

$command = ($this->windows) ? $this->executable : './' . $this->executable;

$command .= " list_parameters ";
$command .= ' list_parameters ';

$command .= "\"$input_file\"";

Expand All @@ -173,7 +171,7 @@ 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 . "\"";
$this->the_command = 'su -u ' . $run_as_user . " -c \"" . $this->the_command . "\"";

$output = array();
$return_var = 0;
Expand All @@ -182,11 +180,11 @@ public function execute($run_as_user = false)
chdir($this->path_executable);
exec($this->the_command, $output, $return_var);
} else {
throw new \Exception("Invalid resource directory.", 1);
throw new \Exception('Invalid resource directory.', 1);
}

if($return_var != 0)
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);
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);

return $output;
}
Expand Down

0 comments on commit 0a9f80c

Please sign in to comment.