Skip to content

Commit

Permalink
general updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Rodrigues Lima committed Sep 27, 2016
1 parent 6f83e74 commit 087e63b
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 84 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
The MIT License (MIT)

Copyright (c) 2013 Hélder Duarte
Copyright (c) 2015 Daniel Rodrigues Lima
Copyright (c) 2015 Leandro Bitencourt
Copyright (c) 2015 Daniel Rodrigues
Copyright (c) 2015 Jefferson Barreto

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
8 changes: 2 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lavela/phpjasper",
"description": "Create Reports in PHP with JasperReports",
"description": "Create Reports in PHP/Laravel with JasperReports",
"license": "MIT",
"keywords": [
"reports",
Expand All @@ -23,12 +23,8 @@
"name": "Daniel Rodrigues",
"email": "[email protected]",
"role": "Developer"
},
{
"name": "Jefferson Barreto",
"email": "[email protected]",
"role": "Developer"
}

],
"minimum-stability": "dev",
"require": {
Expand Down
39 changes: 19 additions & 20 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">

<filter>
<whitelist>
<directory>src/JasperPHP</directory>
<directory>src/JasperStarter</directory>
</whitelist>
</filter>
<filter>
<whitelist>
<directory>src/JasperPHP</directory>
<directory>src/JasperStarter</directory>
</whitelist>
</filter>

<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
12 changes: 8 additions & 4 deletions src/JasperPHP/Facades/JasperPHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

use Illuminate\Support\Facades\Facade;

class JasperPHP extends Facade {

protected static function getFacadeAccessor() { return 'jasperphp'; }
}
class JasperPHP extends Facade
{

protected static function getFacadeAccessor()
{
return 'jasperphp';
}
}
86 changes: 41 additions & 45 deletions src/JasperPHP/JasperPHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class JasperPHP
{
protected $executable = 'jasperstarter'; //executable jasperstarter
protected $path_executable = __DIR__ . '/../JasperStarter/bin/'; //Path to executable
protected $path_executable;
protected $the_command;
protected $redirect_output;
protected $background;
Expand All @@ -16,11 +16,12 @@ class JasperPHP

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/lavela/phpjasper/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);
Expand All @@ -40,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 @@ -49,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(), $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 @@ -82,78 +81,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;
/*
// Resources dir
$command .= " -r " . $this->resource_directory;
*/
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'];

}

$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 @@ -175,22 +171,22 @@ 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;
}
}
}
14 changes: 7 additions & 7 deletions src/JasperPHP/JasperPHPServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

use Illuminate\Support\ServiceProvider;

class JasperPHPServiceProvider extends ServiceProvider {
class JasperPHPServiceProvider extends ServiceProvider
{

const SESSION_HASH = '_JasperPHP';

Expand All @@ -13,23 +14,22 @@ class JasperPHPServiceProvider extends ServiceProvider {
*
* @return void
*/
public function register() {
public function register()
{

$this->app['jasperphp'] = $this->app->share(function()
{
$this->app['jasperphp'] = $this->app->share(function () {
return new JasperPHP;
});


/**
* Register the alias.
*/
$this->app->booting(function()
{
$this->app->booting(function () {
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('JasperPHP', 'JasperPHP\Facades\JasperPHP');
});

}

}
}

0 comments on commit 087e63b

Please sign in to comment.