11<?php
22
3+ declare (strict_types=1 );
4+
35namespace PHPJasper ;
46
57/**
@@ -22,7 +24,7 @@ class PHPJasper
2224 /**
2325 * @var string
2426 */
25- protected $ path_executable ;
27+ protected $ pathExecutable ;
2628
2729 /**
2830 * @var bool
@@ -40,46 +42,46 @@ class PHPJasper
4042 public function __construct ()
4143 {
4244 $ this ->executable = 'jasperstarter ' ;
43- $ this ->path_executable = __DIR__ . '/../bin/jasperstarter/bin ' ;
45+ $ this ->pathExecutable = __DIR__ . '/../bin/jasperstarter/bin ' ;
4446 $ this ->windows = strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ? true : false ;
4547 }
4648
4749 /**
48- * @param $input_file
49- * @param bool $output_file
50+ * @param string $input
51+ * @param string $output optional
5052 * @return $this
5153 * @throws Exception\InvalidInputFile
5254 */
53- public function compile ($ input_file , $ output_file = false )
55+ public function compile (string $ input , string $ output = '' )
5456 {
55- if (!$ input_file ) {
57+ if (!$ input ) {
5658 throw new \PHPJasper \Exception \InvalidInputFile ();
5759 }
5860
5961 $ this ->command = $ this ->windows ? $ this ->executable : './ ' . $ this ->executable ;
6062 $ this ->command .= ' compile ' ;
61- $ this ->command .= "\"$ input_file \"" ;
63+ $ this ->command .= "\"$ input \"" ;
6264
63- if ($ output_file !== false ) {
64- $ this ->command .= ' -o ' . "\"$ output_file \"" ;
65+ if (! empty ( $ output ) ) {
66+ $ this ->command .= ' -o ' . "\"$ output \"" ;
6567 }
6668
6769 return $ this ;
6870 }
6971
7072
7173 /**
72- * @param $input_file
73- * @param bool $output_file
74+ * @param string $input
75+ * @param string $output
7476 * @param array $options
7577 * @return $this
7678 * @throws Exception\InvalidInputFile
7779 * @throws Exception\InvalidFormat
7880 */
79- public function process ($ input_file , $ output_file = false , $ options = [])
81+ public function process (string $ input , string $ output , array $ options = [])
8082 {
8183 $ options = $ this ->parseProcessOptions ($ options );
82- if (!$ input_file ) {
84+ if (!$ input ) {
8385 throw new \PHPJasper \Exception \InvalidInputFile ();
8486 }
8587 $ this ->validateFormat ($ options ['format ' ]);
@@ -90,10 +92,8 @@ public function process($input_file, $output_file = false, $options = [])
9092 }
9193
9294 $ 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 \"" ;
9797
9898 $ this ->command .= ' -f ' . join (' ' , $ options ['format ' ]);
9999 if ($ options ['params ' ]) {
@@ -130,10 +130,10 @@ public function process($input_file, $output_file = false, $options = [])
130130
131131 /**
132132 *
133- * @param $options
133+ * @param array $options
134134 * @return array
135135 */
136- protected function parseProcessOptions ($ options )
136+ protected function parseProcessOptions (array $ options )
137137 {
138138 $ defaultOptions = [
139139 'format ' => ['pdf ' ],
@@ -162,19 +162,19 @@ protected function validateFormat($format)
162162 }
163163
164164 /**
165- * @param $input_file
165+ * @param string $input
166166 * @return $this
167167 * @throws \Exception
168168 */
169- public function listParameters ($ input_file )
169+ public function listParameters (string $ input )
170170 {
171- if (!$ input_file ) {
171+ if (!$ input ) {
172172 throw new \PHPJasper \Exception \InvalidInputFile ();
173173 }
174174
175175 $ this ->command = $ this ->windows ? $ this ->executable : './ ' . $ this ->executable ;
176176 $ this ->command .= ' list_parameters ' ;
177- $ this ->command .= "\"$ input_file \"" ;
177+ $ this ->command .= "\"$ input \"" ;
178178
179179 return $ this ;
180180 }
@@ -192,11 +192,11 @@ public function execute($user = false)
192192 $ this ->addUserToCommand ($ user );
193193
194194 $ output = [];
195- $ return_var = 0 ;
195+ $ returnVar = 0 ;
196196
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 ) {
200200 throw new \PHPJasper \Exception \ErrorCommandExecutable ();
201201 }
202202
@@ -230,7 +230,7 @@ protected function validateExecute()
230230 if (!$ this ->command ) {
231231 throw new \PHPJasper \Exception \InvalidCommandExecutable ();
232232 }
233- if (!is_dir ($ this ->path_executable )) {
233+ if (!is_dir ($ this ->pathExecutable )) {
234234 throw new \PHPJasper \Exception \InvalidResourceDirectory ();
235235 }
236236
0 commit comments