|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Graze\CiffRenderer; |
|
4
|
|
|
|
|
5
|
|
|
use Graze\CiffRenderer\Renderer\RendererDocument; |
|
6
|
|
|
|
|
7
|
|
|
class CiffRenderer |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var RendererDocument |
|
11
|
|
|
*/ |
|
12
|
|
|
private $rendererDocument; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var callable |
|
16
|
|
|
*/ |
|
17
|
|
|
private $fontResolver; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var callable |
|
21
|
|
|
*/ |
|
22
|
|
|
private $graphicResolver; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param RendererDocument $rendererDocument |
|
26
|
|
|
*/ |
|
27
|
2 |
|
public function __construct(RendererDocument $rendererDocument) |
|
28
|
|
|
{ |
|
29
|
2 |
|
$this->rendererDocument = $rendererDocument; |
|
30
|
2 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Render an image from a ciff file located on the filesystem. |
|
34
|
|
|
* |
|
35
|
|
|
* @param string $filePath |
|
36
|
|
|
* @return Intervention\Image\Image |
|
|
|
|
|
|
37
|
|
|
*/ |
|
38
|
1 |
|
public function renderFile($filePath) |
|
39
|
|
|
{ |
|
40
|
1 |
|
$xml = simplexml_load_file($filePath); |
|
41
|
1 |
|
return $this->render($xml); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Render an image from ciff data contained within a string. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $string |
|
48
|
|
|
* @return Intervention\Image\Image |
|
|
|
|
|
|
49
|
|
|
*/ |
|
50
|
1 |
|
public function renderString($string) |
|
51
|
|
|
{ |
|
52
|
1 |
|
$xml = simplexml_load_string($string); |
|
53
|
1 |
|
return $this->render($xml); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param \SimpleXMLElement $xml |
|
58
|
|
|
* @return Intervention\Image\Image |
|
|
|
|
|
|
59
|
|
|
*/ |
|
60
|
2 |
|
private function render(\SimpleXMLElement $xml) |
|
61
|
|
|
{ |
|
62
|
2 |
|
return $this->rendererDocument->render( |
|
63
|
|
|
$xml, |
|
64
|
2 |
|
$this->fontResolver, |
|
65
|
2 |
|
$this->graphicResolver |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param callable $fontResolver |
|
71
|
|
|
*/ |
|
72
|
2 |
|
public function setFontResolver(callable $fontResolver) |
|
73
|
|
|
{ |
|
74
|
2 |
|
$this->fontResolver = $fontResolver; |
|
75
|
2 |
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param callable $graphicResolver |
|
79
|
|
|
*/ |
|
80
|
2 |
|
public function setGraphicResolver(callable $graphicResolver) |
|
81
|
|
|
{ |
|
82
|
2 |
|
$this->graphicResolver = $graphicResolver; |
|
83
|
2 |
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return CiffRenderer |
|
87
|
|
|
*/ |
|
88
|
|
|
public static function factory() |
|
89
|
|
|
{ |
|
90
|
|
|
return new static( |
|
91
|
|
|
RendererDocument::factory() |
|
92
|
|
|
); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.