Skip to content

refactoring to improvements #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Release Notes - PHPJasper - Version 2.1
========================================================
** Refactoring
* strict types activate
* add type declarations
________________________________________________________
Release Notes - PHPJasper - Version 2.0
========================================================
** Improvement
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![License](https://poser.pugx.org/geekcom/phpjasper/license)](https://packagist.org/packages/geekcom/phpjasper)

### Docs
[![Language-pt_BR](https://img.shields.io/badge/pt__BR-100%25-green.svg)](https://github.com/PHPJasper/phpjasper/blob/master/docs/pt_BR/LEIA-ME_pt_BR.md)
[![Language-pt_BR](https://img.shields.io/badge/pt__BR-100%25-green.svg)](https://github.com/PHPJasper/phpjasper/blob/2.0/docs/pt_BR/LEIA-ME_pt_BR.md)

### About
This package is the solution to compile and process JasperReports (.jrxml & .jasper files) just using PHP.
Expand Down
56 changes: 28 additions & 28 deletions src/PHPJasper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PHPJasper;

/**
Expand All @@ -22,7 +24,7 @@ class PHPJasper
/**
* @var string
*/
protected $path_executable;
protected $pathExecutable;

/**
* @var bool
Expand All @@ -40,46 +42,46 @@ class PHPJasper
public function __construct()
{
$this->executable = 'jasperstarter';
$this->path_executable = __DIR__ . '/../bin/jasperstarter/bin';
$this->pathExecutable = __DIR__ . '/../bin/jasperstarter/bin';
$this->windows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? true : false;
}

/**
* @param $input_file
* @param bool $output_file
* @param string $input
* @param string $output optional
* @return $this
* @throws Exception\InvalidInputFile
*/
public function compile($input_file, $output_file = false)
public function compile(string $input, string $output = '')
{
if (!$input_file) {
if (!$input) {
throw new \PHPJasper\Exception\InvalidInputFile();
}

$this->command = $this->windows ? $this->executable : './' . $this->executable;
$this->command .= ' compile ';
$this->command .= "\"$input_file\"";
$this->command .= "\"$input\"";

if ($output_file !== false) {
$this->command .= ' -o ' . "\"$output_file\"";
if (!empty($output)) {
$this->command .= ' -o ' . "\"$output\"";
}

return $this;
}


/**
* @param $input_file
* @param bool $output_file
* @param string $input
* @param string $output
* @param array $options
* @return $this
* @throws Exception\InvalidInputFile
* @throws Exception\InvalidFormat
*/
public function process($input_file, $output_file = false, $options = [])
public function process(string $input, string $output, array $options = [])
{
$options = $this->parseProcessOptions($options);
if (!$input_file) {
if (!$input) {
throw new \PHPJasper\Exception\InvalidInputFile();
}
$this->validateFormat($options['format']);
Expand All @@ -90,10 +92,8 @@ public function process($input_file, $output_file = false, $options = [])
}

$this->command .= ' process ';
$this->command .= "\"$input_file\"";
if ($output_file !== false) {
$this->command .= ' -o ' . "\"$output_file\"";
}
$this->command .= "\"$input\"";
$this->command .= ' -o ' . "\"$output\"";

$this->command .= ' -f ' . join(' ', $options['format']);
if ($options['params']) {
Expand Down Expand Up @@ -130,10 +130,10 @@ public function process($input_file, $output_file = false, $options = [])

/**
*
* @param $options
* @param array $options
* @return array
*/
protected function parseProcessOptions($options)
protected function parseProcessOptions(array $options)
{
$defaultOptions = [
'format' => ['pdf'],
Expand Down Expand Up @@ -162,19 +162,19 @@ protected function validateFormat($format)
}

/**
* @param $input_file
* @param string $input
* @return $this
* @throws \Exception
*/
public function listParameters($input_file)
public function listParameters(string $input)
{
if (!$input_file) {
if (!$input) {
throw new \PHPJasper\Exception\InvalidInputFile();
}

$this->command = $this->windows ? $this->executable : './' . $this->executable;
$this->command .= ' list_parameters ';
$this->command .= "\"$input_file\"";
$this->command .= "\"$input\"";

return $this;
}
Expand All @@ -192,11 +192,11 @@ public function execute($user = false)
$this->addUserToCommand($user);

$output = [];
$return_var = 0;
$returnVar = 0;

chdir($this->path_executable);
exec($this->command, $output, $return_var);
if ($return_var !== 0) {
chdir($this->pathExecutable);
exec($this->command, $output, $returnVar);
if ($returnVar !== 0) {
throw new \PHPJasper\Exception\ErrorCommandExecutable();
}

Expand Down Expand Up @@ -230,7 +230,7 @@ protected function validateExecute()
if (!$this->command) {
throw new \PHPJasper\Exception\InvalidCommandExecutable();
}
if (!is_dir($this->path_executable)) {
if (!is_dir($this->pathExecutable)) {
throw new \PHPJasper\Exception\InvalidResourceDirectory();
}

Expand Down