Repository navigation
Expand file tree
/
Copy pathFactory.php
More file actions
81 lines (68 loc) · 2.21 KB
/
Copy pathFactory.php
File metadata and controls
81 lines (68 loc) · 2.21 KB
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
<?php
namespace AsyncPHP\Paper;
use AsyncPHP\Paper\Driver;
use AsyncPHP\Paper\Driver\DomDriver;
use AsyncPHP\Paper\Driver\PrinceDriver;
use AsyncPHP\Paper\Driver\SyncDriver;
use AsyncPHP\Paper\Driver\WebkitDriver;
use AsyncPHP\Paper\Runner;
use AsyncPHP\Paper\Runner\AmpRunner;
use AsyncPHP\Paper\Runner\ReactRunner;
class Factory
{
/**
* Creates a driver instance, based on provided config options.
*
* @param array $options
*
* @return null|Driver
*/
public function createDriver(array $options = ["driver" => "dom"])
{
$driver = null;
if ($options["driver"] === "dom") {
$driver = new DomDriver(
!empty($options["dom"]["options"]) ? $options["dom"]["options"] : []
);
}
if ($options["driver"] === "prince") {
$driver = new PrinceDriver(
!empty($options["prince"]["binary"]) ? $options["prince"]["binary"] : "prince",
!empty($options["prince"]["tempPath"]) ? $options["prince"]["tempPath"] : __DIR__,
!empty($options["prince"]["options"]) ? $options["prince"]["options"] : []
);
}
if ($options["driver"] === "webkit") {
$driver = new WebkitDriver(
!empty($options["webkit"]["binary"]) ? $options["webkit"]["binary"] : "wkhtmltopdf",
!empty($options["webkit"]["tempPath"]) ? $options["webkit"]["tempPath"] : __DIR__,
!empty($options["webkit"]["options"]) ? $options["webkit"]["options"] : []
);
}
if (empty($options["sync"])) {
return $driver;
}
if ($driver !== null) {
return new SyncDriver($driver);
}
return null;
}
/**
* Creates a runner instance, based on provided config options.
*
* @param array $options
*
* @return null|Runner
*/
public function createRunner(array $options = ["runner" => "amp"])
{
$runner = null;
if ($options["runner"] === "amp") {
$runner = new AmpRunner();
}
if ($options["runner"] === "react") {
$runner = new ReactRunner();
}
return $runner;
}
}