Skip to content

Commit 087e63b

Browse files
author
Daniel Rodrigues Lima
committed
general updates
1 parent 6f83e74 commit 087e63b

File tree

7 files changed

+79
-84
lines changed

7 files changed

+79
-84
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea/

LICENSE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
The MIT License (MIT)
22

33
Copyright (c) 2013 Hélder Duarte
4+
Copyright (c) 2015 Daniel Rodrigues Lima
45
Copyright (c) 2015 Leandro Bitencourt
5-
Copyright (c) 2015 Daniel Rodrigues
6-
Copyright (c) 2015 Jefferson Barreto
76

87
Permission is hereby granted, free of charge, to any person obtaining a copy of
98
this software and associated documentation files (the "Software"), to deal in

composer.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lavela/phpjasper",
3-
"description": "Create Reports in PHP with JasperReports",
3+
"description": "Create Reports in PHP/Laravel with JasperReports",
44
"license": "MIT",
55
"keywords": [
66
"reports",
@@ -23,12 +23,8 @@
2323
"name": "Daniel Rodrigues",
2424
"email": "[email protected]",
2525
"role": "Developer"
26-
},
27-
{
28-
"name": "Jefferson Barreto",
29-
"email": "[email protected]",
30-
"role": "Developer"
3126
}
27+
3228
],
3329
"minimum-stability": "dev",
3430
"require": {

phpunit.xml.dist

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
processIsolation="false"
9-
stopOnFailure="false"
10-
syntaxCheck="false"
11-
>
3+
backupStaticAttributes="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
syntaxCheck="false">
1211

13-
<filter>
14-
<whitelist>
15-
<directory>src/JasperPHP</directory>
16-
<directory>src/JasperStarter</directory>
17-
</whitelist>
18-
</filter>
12+
<filter>
13+
<whitelist>
14+
<directory>src/JasperPHP</directory>
15+
<directory>src/JasperStarter</directory>
16+
</whitelist>
17+
</filter>
1918

20-
<testsuites>
21-
<testsuite name="Test Suite">
22-
<directory>tests</directory>
23-
</testsuite>
24-
</testsuites>
19+
<testsuites>
20+
<testsuite name="Test Suite">
21+
<directory>tests</directory>
22+
</testsuite>
23+
</testsuites>
2524
</phpunit>

src/JasperPHP/Facades/JasperPHP.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
use Illuminate\Support\Facades\Facade;
66

7-
class JasperPHP extends Facade {
8-
9-
protected static function getFacadeAccessor() { return 'jasperphp'; }
10-
}
7+
class JasperPHP extends Facade
8+
{
9+
10+
protected static function getFacadeAccessor()
11+
{
12+
return 'jasperphp';
13+
}
14+
}

src/JasperPHP/JasperPHP.php

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class JasperPHP
66
{
77
protected $executable = 'jasperstarter'; //executable jasperstarter
8-
protected $path_executable = __DIR__ . '/../JasperStarter/bin/'; //Path to executable
8+
protected $path_executable;
99
protected $the_command;
1010
protected $redirect_output;
1111
protected $background;
@@ -16,11 +16,12 @@ class JasperPHP
1616

1717
function __construct($resource_dir = false)
1818
{
19+
$this->path_executable = __DIR__ . '/../JasperStarter/bin'; //Path to executable
1920
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
20-
$this->windows = true;
21+
$this->windows = true;
2122

2223
if (!$resource_dir) {
23-
$this->resource_directory = __DIR__ . '/../../../vendor/lavela/phpjasper/src/JasperStarter/bin';
24+
$this->resource_directory = __DIR__ . '/../../../vendor/cossou/jasperphp/src/JasperStarter/bin';
2425
} else {
2526
if (!file_exists($resource_dir))
2627
throw new \Exception('Invalid resource directory.', 1);
@@ -40,7 +41,7 @@ public static function __callStatic($method, $parameters)
4041

4142
public function compile($input_file, $output_file = false, $background = true, $redirect_output = true)
4243
{
43-
if(is_null($input_file) || empty($input_file))
44+
if (is_null($input_file) || empty($input_file))
4445
throw new \Exception('No input file', 1);
4546

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

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

52-
if( $output_file !== false )
53+
if ($output_file !== false)
5354
$command .= ' -o ' . "\"$output_file\"";
5455

55-
$this->redirect_output = $redirect_output;
56-
$this->background = $background;
57-
$this->the_command = $command;
56+
$this->redirect_output = $redirect_output;
57+
$this->background = $background;
58+
$this->the_command = $command;
5859

5960
return $this;
6061
}
6162

6263
public function process($input_file, $output_file = false, $format = array('pdf'), $parameters = array(), $db_connection = array(), $background = true, $redirect_output = true)
6364
{
64-
if(is_null($input_file) || empty($input_file))
65+
if (is_null($input_file) || empty($input_file))
6566
throw new \Exception('No input file', 1);
6667

67-
if( is_array($format) )
68-
{
69-
foreach ($format as $key)
70-
{
71-
if( !in_array($key, $this->formats))
68+
if (is_array($format)) {
69+
foreach ($format as $key) {
70+
if (!in_array($key, $this->formats))
7271
throw new \Exception('Invalid format!', 1);
7372
}
7473
} else {
75-
if( !in_array($format, $this->formats))
76-
throw new \Exception('Invalid format!', 1);
74+
if (!in_array($format, $this->formats))
75+
throw new \Exception('Invalid format!', 1);
7776
}
7877

7978
$command = ($this->windows) ? $this->executable : './' . $this->executable;
@@ -82,78 +81,75 @@ public function process($input_file, $output_file = false, $format = array('pdf'
8281

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

85-
if( $output_file !== false )
84+
if ($output_file !== false)
8685
$command .= ' -o ' . "\"$output_file\"";
8786

88-
if( is_array($format) )
87+
if (is_array($format))
8988
$command .= ' -f ' . join(' ', $format);
9089
else
9190
$command .= ' -f ' . $format;
9291
/*
9392
// Resources dir
9493
$command .= " -r " . $this->resource_directory;
9594
*/
96-
if( count($parameters) > 0 )
97-
{
95+
if (count($parameters) > 0) {
9896
$command .= ' -P ';
9997

100-
foreach ($parameters as $key => $value)
101-
{
98+
foreach ($parameters as $key => $value) {
10299
$param = $key . '="' . $value . '" ';
103-
$command .= " " .$param. " ";
100+
$command .= " " . $param . " ";
104101
}
105102

106103
}
107104

108-
if( count($db_connection) > 0 )
109-
{
105+
if (count($db_connection) > 0) {
110106
$command .= ' -t ' . $db_connection['driver'];
111107

112-
if(isset($db_connection['username']))
108+
if (isset($db_connection['username']))
113109
$command .= " -u " . $db_connection['username'];
114110

115-
if( isset($db_connection['password']) && !empty($db_connection['password']) )
111+
if (isset($db_connection['password']) && !empty($db_connection['password']))
116112
$command .= ' -p ' . $db_connection['password'];
117113

118-
if( isset($db_connection['host']) && !empty($db_connection['host']) )
114+
if (isset($db_connection['host']) && !empty($db_connection['host']))
119115
$command .= ' -H ' . $db_connection['host'];
120116

121-
if( isset($db_connection['database']) && !empty($db_connection['database']) )
117+
if (isset($db_connection['database']) && !empty($db_connection['database']))
122118
$command .= ' -n ' . $db_connection['database'];
123119

124-
if( isset($db_connection['port']) && !empty($db_connection['port']) )
120+
if (isset($db_connection['port']) && !empty($db_connection['port']))
125121
$command .= ' --db-port ' . $db_connection['port'];
126122

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

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

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

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

139-
if ( isset($db_connection['xml_xpath']) )
135+
if (isset($db_connection['xml_xpath']))
140136
$command .= ' --xml-xpath ' . $db_connection['xml_xpath'];
141137

142-
if ( isset($db_connection['data_file']) )
138+
if (isset($db_connection['data_file']))
143139
$command .= ' --data-file ' . $db_connection['data_file'];
144140

145141
}
146142

147-
$this->redirect_output = $redirect_output;
148-
$this->background = $background;
149-
$this->the_command = $command;
143+
$this->redirect_output = $redirect_output;
144+
$this->background = $background;
145+
$this->the_command = $command;
150146

151147
return $this;
152148
}
153149

154150
public function list_parameters($input_file)
155151
{
156-
if(is_null($input_file) || empty($input_file))
152+
if (is_null($input_file) || empty($input_file))
157153
throw new \Exception('No input file', 1);
158154

159155
$command = ($this->windows) ? $this->executable : './' . $this->executable;
@@ -175,22 +171,22 @@ public function output()
175171
public function execute($run_as_user = false)
176172
{
177173

178-
if( $run_as_user !== false && strlen($run_as_user > 0) && !$this->windows )
174+
if ($run_as_user !== false && strlen($run_as_user > 0) && !$this->windows)
179175
$this->the_command = 'su -u ' . $run_as_user . " -c \"" . $this->the_command . "\"";
180176

181177
$output = array();
182178
$return_var = 0;
183179

184-
if (is_dir($this->path_executable)){
180+
if (is_dir($this->path_executable)) {
185181
chdir($this->path_executable);
186182
exec($this->the_command, $output, $return_var);
187183
} else {
188184
throw new \Exception('Invalid resource directory.', 1);
189185
}
190186

191-
if($return_var != 0)
187+
if ($return_var != 0)
192188
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);
193-
189+
194190
return $output;
195191
}
196-
}
192+
}

src/JasperPHP/JasperPHPServiceProvider.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
use Illuminate\Support\ServiceProvider;
66

7-
class JasperPHPServiceProvider extends ServiceProvider {
7+
class JasperPHPServiceProvider extends ServiceProvider
8+
{
89

910
const SESSION_HASH = '_JasperPHP';
1011

@@ -13,23 +14,22 @@ class JasperPHPServiceProvider extends ServiceProvider {
1314
*
1415
* @return void
1516
*/
16-
public function register() {
17+
public function register()
18+
{
1719

18-
$this->app['jasperphp'] = $this->app->share(function()
19-
{
20+
$this->app['jasperphp'] = $this->app->share(function () {
2021
return new JasperPHP;
2122
});
2223

2324

2425
/**
2526
* Register the alias.
2627
*/
27-
$this->app->booting(function()
28-
{
28+
$this->app->booting(function () {
2929
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
3030
$loader->alias('JasperPHP', 'JasperPHP\Facades\JasperPHP');
3131
});
3232

3333
}
3434

35-
}
35+
}

0 commit comments

Comments
 (0)