-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChromeHeadlessIoService.php
123 lines (114 loc) · 3.05 KB
/
ChromeHeadlessIoService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/**
* ChromeHeadlessIoService class
*
* @category Core
* @package KoolReport
* @author KoolPHP Inc <support@koolphp.net>
* @copyright 2017-2028 KoolPHP Inc
* @license MIT License https://www.koolreport.com/license#mit-license
* @link https://www.koolphp.net
*/
namespace koolreport\cloudexport;
/**
* ChromeHeadlessIoService class
*
* @category Core
* @package KoolReport
* @author KoolPHP Inc <support@koolphp.net>
* @copyright 2017-2028 KoolPHP Inc
* @license MIT License https://www.koolreport.com/license#mit-license
* @link https://www.koolphp.net
*/
class ChromeHeadlessIoService
{
/**
* Parameters for ChomeHeadless.io service
*
* @param array $params The parameters
*/
protected $settings;
protected $authentication;
/**
* Parameters for ChomeHeadless.io service
*
* @param string $html The html that will be sent to export
* @param array $params The parameters
*/
public function __construct($html, $authentication)
{
$this->authentication = $authentication;
$this->settings = [
'html' => $html,
'resourcePatterns' => [
[
"regex" => '~((KoolReport.load.resources|KoolReport.widget.init)\([^\)]*)["\']([^"\']+css|[^"\']+js|css[^"\']+|js[^"\']+|(?![^"\',\)\[\]\:]*(css|js))[^"\',\)\[\]\:]*)["\']~',
"replace" => "{group1}'{group3}'",
"urlGroup" => "{group3}"
]
]
];
}
/**
* Set export setting
*
* @param array $settings The setting for export
*
* @return $this
*/
public function settings($settings)
{
$this->settings = array_merge($this->settings, $settings);
return $this;
}
/**
* Export to pdf
*
* @param array $options The option for pdf
*
* @return OutputHandler The output content
*/
public function pdf($options = [])
{
return $this->exportTo('pdf', $options);
}
/**
* Export to jpg
*
* @param array $options The option for jpg
*
* @return OutputHandler The output content
*/
public function jpg($options = [])
{
return $this->exportTo('jpg', $options);
}
/**
* Export to png
*
* @param array $options The option for png
*
* @return OutputHandler The output content
*/
public function png($options = [])
{
return $this->exportTo('png', $options);
}
/**
* Export to pdf
*
* @param string $format Format you want to export to "pdf","jpg"
* @param array $options The option for pdf
*
* @return OutputHandler The output content
*/
public function exportTo($format, $options = [])
{
$service = new \chromeheadlessio\Service($this->authentication);
$exportContent = $service
->export($this->settings)
->{$format}($options)
->toString();
return new OutputHandler($exportContent);
}
}