1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace PHPJasper ;
4
6
5
7
/**
@@ -22,7 +24,7 @@ class PHPJasper
22
24
/**
23
25
* @var string
24
26
*/
25
- protected $ path_executable ;
27
+ protected $ pathExecutable ;
26
28
27
29
/**
28
30
* @var bool
@@ -40,46 +42,46 @@ class PHPJasper
40
42
public function __construct ()
41
43
{
42
44
$ this ->executable = 'jasperstarter ' ;
43
- $ this ->path_executable = __DIR__ . '/../bin/jasperstarter/bin ' ;
45
+ $ this ->pathExecutable = __DIR__ . '/../bin/jasperstarter/bin ' ;
44
46
$ this ->windows = strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ? true : false ;
45
47
}
46
48
47
49
/**
48
- * @param $input_file
49
- * @param bool $output_file
50
+ * @param string $input
51
+ * @param string $output optional
50
52
* @return $this
51
53
* @throws Exception\InvalidInputFile
52
54
*/
53
- public function compile ($ input_file , $ output_file = false )
55
+ public function compile (string $ input , string $ output = '' )
54
56
{
55
- if (!$ input_file ) {
57
+ if (!$ input ) {
56
58
throw new \PHPJasper \Exception \InvalidInputFile ();
57
59
}
58
60
59
61
$ this ->command = $ this ->windows ? $ this ->executable : './ ' . $ this ->executable ;
60
62
$ this ->command .= ' compile ' ;
61
- $ this ->command .= "\"$ input_file \"" ;
63
+ $ this ->command .= "\"$ input \"" ;
62
64
63
- if ($ output_file !== false ) {
64
- $ this ->command .= ' -o ' . "\"$ output_file \"" ;
65
+ if (! empty ( $ output ) ) {
66
+ $ this ->command .= ' -o ' . "\"$ output \"" ;
65
67
}
66
68
67
69
return $ this ;
68
70
}
69
71
70
72
71
73
/**
72
- * @param $input_file
73
- * @param bool $output_file
74
+ * @param string $input
75
+ * @param string $output
74
76
* @param array $options
75
77
* @return $this
76
78
* @throws Exception\InvalidInputFile
77
79
* @throws Exception\InvalidFormat
78
80
*/
79
- public function process ($ input_file , $ output_file = false , $ options = [])
81
+ public function process (string $ input , string $ output , array $ options = [])
80
82
{
81
83
$ options = $ this ->parseProcessOptions ($ options );
82
- if (!$ input_file ) {
84
+ if (!$ input ) {
83
85
throw new \PHPJasper \Exception \InvalidInputFile ();
84
86
}
85
87
$ this ->validateFormat ($ options ['format ' ]);
@@ -90,10 +92,8 @@ public function process($input_file, $output_file = false, $options = [])
90
92
}
91
93
92
94
$ this ->command .= ' process ' ;
93
- $ this ->command .= "\"$ input_file \"" ;
94
- if ($ output_file !== false ) {
95
- $ this ->command .= ' -o ' . "\"$ output_file \"" ;
96
- }
95
+ $ this ->command .= "\"$ input \"" ;
96
+ $ this ->command .= ' -o ' . "\"$ output \"" ;
97
97
98
98
$ this ->command .= ' -f ' . join (' ' , $ options ['format ' ]);
99
99
if ($ options ['params ' ]) {
@@ -130,10 +130,10 @@ public function process($input_file, $output_file = false, $options = [])
130
130
131
131
/**
132
132
*
133
- * @param $options
133
+ * @param array $options
134
134
* @return array
135
135
*/
136
- protected function parseProcessOptions ($ options )
136
+ protected function parseProcessOptions (array $ options )
137
137
{
138
138
$ defaultOptions = [
139
139
'format ' => ['pdf ' ],
@@ -162,19 +162,19 @@ protected function validateFormat($format)
162
162
}
163
163
164
164
/**
165
- * @param $input_file
165
+ * @param string $input
166
166
* @return $this
167
167
* @throws \Exception
168
168
*/
169
- public function listParameters ($ input_file )
169
+ public function listParameters (string $ input )
170
170
{
171
- if (!$ input_file ) {
171
+ if (!$ input ) {
172
172
throw new \PHPJasper \Exception \InvalidInputFile ();
173
173
}
174
174
175
175
$ this ->command = $ this ->windows ? $ this ->executable : './ ' . $ this ->executable ;
176
176
$ this ->command .= ' list_parameters ' ;
177
- $ this ->command .= "\"$ input_file \"" ;
177
+ $ this ->command .= "\"$ input \"" ;
178
178
179
179
return $ this ;
180
180
}
@@ -192,11 +192,11 @@ public function execute($user = false)
192
192
$ this ->addUserToCommand ($ user );
193
193
194
194
$ output = [];
195
- $ return_var = 0 ;
195
+ $ returnVar = 0 ;
196
196
197
- chdir ($ this ->path_executable );
198
- exec ($ this ->command , $ output , $ return_var );
199
- if ($ return_var !== 0 ) {
197
+ chdir ($ this ->pathExecutable );
198
+ exec ($ this ->command , $ output , $ returnVar );
199
+ if ($ returnVar !== 0 ) {
200
200
throw new \PHPJasper \Exception \ErrorCommandExecutable ();
201
201
}
202
202
@@ -230,7 +230,7 @@ protected function validateExecute()
230
230
if (!$ this ->command ) {
231
231
throw new \PHPJasper \Exception \InvalidCommandExecutable ();
232
232
}
233
- if (!is_dir ($ this ->path_executable )) {
233
+ if (!is_dir ($ this ->pathExecutable )) {
234
234
throw new \PHPJasper \Exception \InvalidResourceDirectory ();
235
235
}
236
236
0 commit comments