Skip to content

Commit

Permalink
general and README.md update
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Rodrigues Lima committed Dec 26, 2016
1 parent d8bafe8 commit e335dd1
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 87 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Keep your code clean and organized, happy code.
**Keep your code clean and organized, happy code.**
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Reports for PHP and Laravel 5.*, with JasperReports.
# PHP reports with Jasper Reports, [optional] Laravel 5.*

[![StyleCI](https://styleci.io/repos/46984485/shield?branch=master)](https://styleci.io/repos/46984485)
[![CircleCI](https://circleci.com/gh/geekcom/phpjasper/tree/master.svg?style=shield)](https://circleci.com/gh/geekcom/phpjasper/tree/master)
Expand Down Expand Up @@ -47,6 +47,7 @@ Package to generate reports with [JasperReports 6.3.1](http://community.jasperso
* PHP [exec()](http://php.net/manual/function.exec.php) function
* [optional] [Mysql Connector](http://dev.mysql.com/downloads/connector/j/) (if you want to use database)
* [optional] [PostgreSQL Connector](https://jdbc.postgresql.org/download.html) (if you want to use database)
* [optional] [Microsoft JDBC Drivers](https://www.microsoft.com/en-US/download/details.aspx?id=11774) (if you want to use database)
* [optional] [Jaspersoft Studio](http://community.jaspersoft.com/project/jaspersoft-studio) (to draw and compile your reports)

###Java(JDK)
Expand Down Expand Up @@ -449,16 +450,20 @@ I have a report that generates a *Invoice* with a DB connection, images and mult

##Thanks

Thanks to [Cenote GmbH](http://www.cenote.de/) for the [JasperStarter](http://jasperstarter.sourceforge.net/) tool.
[Cenote GmbH](http://www.cenote.de/) for the [JasperStarter](http://jasperstarter.sourceforge.net/) tool.

##Questions?
[JetBrains](https://www.jetbrains.com/) for the [PhpStorm](PhpStorm) and all great tools.

Open a [Issue](https://github.com/geekcom/phpjasper/issues)

##License
##[Questions?](https://github.com/geekcom/phpjasper/issues)

Open a new [Issue](https://github.com/geekcom/phpjasper/issues) or look for a closed issue


##[License](https://github.com/geekcom/phpjasper/blob/master/LICENSE)

MIT

##Contribute
##[Contribute](https://github.com/geekcom/phpjasper/blob/master/CONTRIBUTING.md)

Contribute to the community PHP and Laravel, feel free to contribute, make a fork!!
71 changes: 35 additions & 36 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
{
"name": "geekcom/phpjasper",
"description": "Create Reports in PHP/Laravel with JasperReports",
"license": "MIT",
"keywords": [
"reports",
"jasper",
"jasperreports",
"pdf",
"xml",
"PHP",
"java",
"json"
],
"homepage": "https://github.com/geekcom/phpjasper",
"authors": [
{
"name": "Daniel Rodrigues",
"email": "[email protected]",
"homepage": "https://olamundophp.wordpress.com/",
"role": "Developer"
},
{
"name": "Leandro Bitencourt",
"email": "[email protected]",
"homepage": "http://www.leandrobitencourt.zz.mu",
"role": "Developer"
}

],
"minimum-stability": "dev",
"require": {
"php": ">=5.4.0"
"name": "geekcom/phpjasper",
"description": "Create Reports in PHP/Laravel with JasperReports",
"license": "MIT",
"keywords": [
"reports",
"jasper",
"jasperreports",
"pdf",
"xml",
"PHP",
"java",
"json"
],
"homepage": "http://geekcom.github.io/phpjasper/",
"authors": [
{
"name": "Daniel Rodrigues Lima",
"email": "[email protected]",
"homepage": "https://olamundophp.wordpress.com/",
"role": "Owner/Developer"
},
"autoload": {
"psr-0": {
"JasperPHP": "src/"
}
{
"name": "Leandro Bitencourt",
"email": "[email protected]",
"homepage": "http://www.leandrobitencourt.zz.mu",
"role": "Developer"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=5.4.0"
},
"autoload": {
"psr-0": {
"JasperPHP": "src/"
}
}
}
83 changes: 39 additions & 44 deletions src/JasperPHP/JasperPHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function __construct($resource_dir = false)
{
$this->path_executable = __DIR__ . '/../JasperStarter/bin'; //Path to executable
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
$this->windows = true;
$this->windows = true;

if (!$resource_dir) {
$this->resource_directory = __DIR__ . '/../../../vendor/geekcom/jasperphp/src/JasperStarter/bin';
Expand All @@ -41,7 +41,7 @@ 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))
if (is_null($input_file) || empty($input_file))
throw new \Exception('No input file', 1);

$command = ($this->windows) ? $this->executable : './' . $this->executable;
Expand All @@ -50,31 +50,29 @@ public function compile($input_file, $output_file = false, $background = true, $

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

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

$this->redirect_output = $redirect_output;
$this->background = $background;
$this->the_command = $command;
$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)
{
if(is_null($input_file) || empty($input_file))
if (is_null($input_file) || empty($input_file))
throw new \Exception('No input file', 1);

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

$command = ($this->windows) ? $this->executable : './' . $this->executable;
Expand All @@ -85,78 +83,75 @@ public function process($input_file, $output_file = false, $format = array('pdf'

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

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

if( is_array($format) )
if (is_array($format))
$command .= ' -f ' . join(' ', $format);
else
$command .= ' -f ' . $format;


if( count($parameters) > 0 )
{


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

foreach ($parameters as $key => $value)
{
foreach ($parameters as $key => $value) {
$param = $key . '="' . $value . '" ';
$command .= " " .$param. " ";
$command .= " " . $param . " ";
}

}

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

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

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

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

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

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

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

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

if ( isset($db_connection['jdbc_dir']) && !empty($db_connection['jdbc_dir']) )
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']) )
if (isset($db_connection['db_sid']) && !empty($db_connection['db_sid']))
$command .= ' --db-sid ' . $db_connection['db_sid'];

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

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

if ( isset($db_connection['json_query']) )
if (isset($db_connection['json_query']))
$command .= ' --json-query ' . $db_connection['json_query'];
}

$this->redirect_output = $redirect_output;
$this->background = $background;
$this->the_command = $command;
$this->redirect_output = $redirect_output;
$this->background = $background;
$this->the_command = $command;

return $this;
}

public function list_parameters($input_file)
{
if(is_null($input_file) || empty($input_file))
if (is_null($input_file) || empty($input_file))
throw new \Exception('No input file', 1);

$command = ($this->windows) ? $this->executable : './' . $this->executable;
Expand All @@ -178,20 +173,20 @@ public function output()
public function execute($run_as_user = false)
{

if( $run_as_user !== false && strlen($run_as_user > 0) && !$this->windows )
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();
$return_var = 0;

if (is_dir($this->path_executable)){
if (is_dir($this->path_executable)) {
chdir($this->path_executable);
exec($this->the_command, $output, $return_var);
} else {
throw new \Exception('Invalid resource directory.', 1);
}

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

return $output;
Expand Down

0 comments on commit e335dd1

Please sign in to comment.