-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'developer' into master
- Loading branch information
Showing
121 changed files
with
418 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ php: | |
- '5.6' | ||
- '7.0' | ||
- '7.1' | ||
- hhvm | ||
- hhvm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
namespace JasperPHP\Exception; | ||
/** | ||
* Class ErrorCommandExecutable | ||
* @package JasperPHP\Exception | ||
*/ | ||
class ErrorCommandExecutable extends \Exception | ||
{ | ||
public function __construct($message = "", $code = 0, Exception $previous = null) | ||
{ | ||
$message = '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.'; | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
namespace JasperPHP\Exception; | ||
/** | ||
* Class InvalidCommandExecutable | ||
* @package JasperPHP\Exception | ||
*/ | ||
class InvalidCommandExecutable extends \Exception | ||
{ | ||
|
||
/** | ||
* InvalidCommandExecutable constructor. | ||
* @param string $message | ||
* @param int $code | ||
* @param Exception|null $previous | ||
*/ | ||
public function __construct($message = "", $code = 0, Exception $previous = null) | ||
{ | ||
$message = 'Cannot execute a blank command'; | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
namespace JasperPHP\Exception; | ||
/** | ||
* Class InvalidFormat | ||
* @package JasperPHP\Exception | ||
*/ | ||
class InvalidFormat extends \Exception | ||
{ | ||
|
||
public function __construct($message = "", $code = 0, Exception $previous = null) | ||
{ | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
namespace JasperPHP\Exception; | ||
/** | ||
* Class InvalidInputFile | ||
* @package JasperPHP\Exception | ||
*/ | ||
class InvalidInputFile extends \Exception | ||
{ | ||
|
||
/** | ||
* InvalidInputFile constructor. | ||
* @param string $message | ||
* @param int $code | ||
* @param Exception|null $previous | ||
*/ | ||
public function __construct($message = "", $code = 0, Exception $previous = null) | ||
{ | ||
$message = 'No input file'; | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
namespace JasperPHP\Exception; | ||
/** | ||
* Class InvalidResourceDirectory | ||
* @package JasperPHP\Exception | ||
*/ | ||
class InvalidResourceDirectory extends \Exception | ||
{ | ||
|
||
/** | ||
* Invalid Resource Directory constructor. | ||
* | ||
* @param string $message | ||
* @param int $code | ||
* @param Exception|null $previous | ||
*/ | ||
public function __construct($message = "", $code = 0, Exception $previous = null) | ||
{ | ||
$message = 'Invalid resource directory'; | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
<?php | ||
namespace JasperPHP; | ||
/** | ||
* Class JasperPHP | ||
* @package JasperPHP | ||
*/ | ||
class JasperPHP | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $command; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $executable; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $path_executable; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
protected $windows; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $formats = ['pdf', 'rtf', 'xls', 'xlsx', 'docx', 'odt', 'ods', 'pptx', 'csv', 'html', 'xhtml', 'xml', 'jrprint']; | ||
|
||
/** | ||
* JasperPHP constructor | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->executable = 'jasperstarter'; | ||
$this->path_executable = __DIR__ . '/../bin/jasperstarter/bin'; | ||
$this->windows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? true : false; | ||
} | ||
|
||
/** | ||
* @param $input_file | ||
* @param bool $output_file | ||
* @return $this | ||
* @throws Exception\InvalidInputFile | ||
*/ | ||
public function compile($input_file, $output_file = false) | ||
{ | ||
if (!$input_file) { | ||
throw new \JasperPHP\Exception\InvalidInputFile(); | ||
} | ||
|
||
$this->command = $this->windows ? $this->executable : './' . $this->executable; | ||
$this->command .= ' compile '; | ||
$this->command .= "\"$input_file\""; | ||
|
||
if ($output_file !== false) { | ||
$this->command .= ' -o ' . "\"$output_file\""; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @param $input_file | ||
* @param bool $output_file | ||
* @param array $options | ||
* @return $this | ||
* @throws Exception\InvalidInputFile | ||
* @throws Exception\InvalidFormat | ||
*/ | ||
public function process($input_file, $output_file = false, $options = []) | ||
{ | ||
$options = $this->parseProcessOptions($options); | ||
if (!$input_file) { | ||
throw new \JasperPHP\Exception\InvalidInputFile(); | ||
} | ||
$this->validateFormat($options['format']); | ||
|
||
$this->command = $this->windows ? $this->executable : './' . $this->executable; | ||
if ($options['locale']) { | ||
$this->command .= " --locale {$options['locale']}"; | ||
} | ||
|
||
$this->command .= ' process '; | ||
$this->command .= "\"$input_file\""; | ||
if ($output_file !== false) { | ||
$this->command .= ' -o ' . "\"$output_file\""; | ||
} | ||
|
||
$this->command .= ' -f ' . join(' ', $options['format']); | ||
if ($options['params']) { | ||
$this->command .= ' -P '; | ||
foreach ($options['params'] as $key => $value) { | ||
$this->command .= " " . $key . '="' . $value . '" ' . " "; | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* | ||
* @param $options | ||
* @return array | ||
*/ | ||
protected function parseProcessOptions($options) | ||
{ | ||
$defaultOptions = [ | ||
'format' => ['pdf'], | ||
'params' => [], | ||
'locale' => false, | ||
'db_connection' => [] | ||
]; | ||
|
||
return array_merge($defaultOptions, $options); | ||
} | ||
|
||
/** | ||
* @param $format | ||
* @throws Exception\InvalidFormat | ||
*/ | ||
protected function validateFormat($format) | ||
{ | ||
if (!is_array($format)) { | ||
$format = [$format]; | ||
} | ||
foreach ($format as $value) { | ||
if (!in_array($value, $this->formats)) { | ||
throw new \JasperPHP\Exception\InvalidFormat(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param $input_file | ||
* @return $this | ||
* @throws \Exception | ||
*/ | ||
public function listParameters($input_file) | ||
{ | ||
if (!$input_file) { | ||
throw new \JasperPHP\Exception\InvalidInputFile(); | ||
} | ||
|
||
$this->command = $this->windows ? $this->executable : './' . $this->executable; | ||
$this->command .= ' list_parameters '; | ||
$this->command .= "\"$input_file\""; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param bool $user | ||
* @return mixed | ||
* @throws Exception\InvalidCommandExecutable | ||
* @throws Exception\InvalidResourceDirectory | ||
* @throws Exception\ErrorCommandExecutable | ||
*/ | ||
public function execute($user = false) | ||
{ | ||
$this->validateExecute(); | ||
$this->addUserToCommand($user); | ||
|
||
$output = []; | ||
$return_var = 0; | ||
|
||
chdir($this->path_executable); | ||
exec($this->command, $output, $return_var); | ||
if ($return_var !== 0) { | ||
throw new \JasperPHP\Exception\ErrorCommandExecutable(); | ||
} | ||
|
||
return $output; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function output() | ||
{ | ||
return $this->command; | ||
} | ||
|
||
/** | ||
* @param $user | ||
*/ | ||
protected function addUserToCommand($user) | ||
{ | ||
if ($user && !$this->windows) { | ||
$this->command = 'su -u ' . $user . " -c \"" . $this->command . "\""; | ||
} | ||
} | ||
|
||
/** | ||
* @throws Exception\InvalidCommandExecutable | ||
* @throws Exception\InvalidResourceDirectory | ||
*/ | ||
protected function validateExecute() | ||
{ | ||
if (!$this->command) { | ||
throw new \JasperPHP\Exception\InvalidCommandExecutable(); | ||
} | ||
if (!is_dir ($this->path_executable)) { | ||
throw new \JasperPHP\Exception\InvalidResourceDirectory(); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.