|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* Jasper report integration for PHP |
|
7
|
|
|
* |
|
8
|
|
|
* @link https://github.com/belgattitude/soluble-jasper |
|
9
|
|
|
* @author Vanvelthem Sébastien |
|
10
|
|
|
* @copyright Copyright (c) 2017 Vanvelthem Sébastien |
|
11
|
|
|
* @license MIT |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Soluble\Jasper\DataSource; |
|
15
|
|
|
|
|
16
|
|
|
use Soluble\Jasper\DataSource\Contract\JRDataSourceFromReportParamsInterface; |
|
17
|
|
|
use Soluble\Jasper\DataSource\Contract\JRDataSourceFromReportParamsTrait; |
|
18
|
|
|
use Soluble\Jasper\DataSource\Contract\ReportParametrableInterface; |
|
19
|
|
|
use Soluble\Jasper\ReportParams; |
|
20
|
|
|
|
|
21
|
|
|
class XmlDataSource implements JRDataSourceFromReportParamsInterface, ReportParametrableInterface |
|
22
|
|
|
{ |
|
23
|
|
|
use JRDataSourceFromReportParamsTrait; |
|
24
|
|
|
|
|
25
|
|
|
public const PARAM_XML_SOURCE = 'net.sf.jasperreports.xml.source'; |
|
26
|
|
|
public const PARAM_XML_DATE_PATTERN = 'net.sf.jasperreports.xml.date.pattern'; |
|
27
|
|
|
public const PARAM_XML_NUMBER_PATTERN = 'net.sf.jasperreports.xml.number.pattern'; |
|
28
|
|
|
public const PARAM_XML_LOCALE_CODE = 'net.sf.jasperreports.xml.locale.code'; |
|
29
|
|
|
public const PARAM_XML_TIMEZONE_ID = 'net.sf.jasperreports.xml.timezone.id'; |
|
30
|
|
|
|
|
31
|
|
|
public const DEFAULT_DATE_PATTERN = 'yyyy-MM-dd'; |
|
32
|
|
|
public const DEFAULT_NUMBER_PATTERN = '0.####'; |
|
33
|
|
|
public const DEFAULT_LOCALE_CODE = 'en_US'; |
|
34
|
|
|
public const DEFAULT_TIMEZONE_ID = 'UTC'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
private $xmlSource; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
private $options; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param string $xmlSource file or url for the json source |
|
48
|
|
|
* @param string $datePattern json date pattern in java style (i.e. 'yyyy-MM-dd') |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct( |
|
51
|
|
|
string $xmlSource, |
|
52
|
|
|
string $datePattern = self::DEFAULT_DATE_PATTERN, |
|
53
|
|
|
string $numberPattern = self::DEFAULT_NUMBER_PATTERN, |
|
54
|
|
|
string $timezoneId = self::DEFAULT_TIMEZONE_ID, |
|
55
|
|
|
string $localeCode = self::DEFAULT_LOCALE_CODE |
|
56
|
|
|
) { |
|
57
|
|
|
$this->xmlSource = $xmlSource; |
|
58
|
|
|
$this->setOptions([ |
|
59
|
|
|
self::PARAM_XML_SOURCE => $xmlSource, |
|
60
|
|
|
self::PARAM_XML_DATE_PATTERN => $datePattern, |
|
61
|
|
|
self::PARAM_XML_NUMBER_PATTERN => $numberPattern, |
|
62
|
|
|
self::PARAM_XML_TIMEZONE_ID => $timezoneId, |
|
63
|
|
|
self::PARAM_XML_LOCALE_CODE => $localeCode |
|
64
|
|
|
]); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function setOptions(array $options) |
|
68
|
|
|
{ |
|
69
|
|
|
$options[self::PARAM_XML_SOURCE] = $this->xmlSource; |
|
|
|
|
|
|
70
|
|
|
$this->options = $options; |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function getOptions(): array |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->options; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function getDataSourceReportParams(): ReportParams |
|
79
|
|
|
{ |
|
80
|
|
|
return new ReportParams($this->options); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.