From deedad7e2c34a39a6edc25ba9726925fd4f9ba83 Mon Sep 17 00:00:00 2001 From: Leandro Cintra Date: Fri, 11 Mar 2016 10:00:42 -0300 Subject: [PATCH] Implements filter dinamic --- src/JasperPHP/JasperPHP.php | 64 ++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/src/JasperPHP/JasperPHP.php b/src/JasperPHP/JasperPHP.php index 073c90f..6e338d3 100644 --- a/src/JasperPHP/JasperPHP.php +++ b/src/JasperPHP/JasperPHP.php @@ -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; @@ -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; } @@ -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; @@ -59,73 +59,74 @@ 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']; @@ -133,11 +134,8 @@ public function process($input_file, $output_file = false, $format = array("pdf" 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']; } @@ -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\""; @@ -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; @@ -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; }