1
|
|
|
<?php namespace Luminaire\Premailer; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Created by Sublime Text 3 |
5
|
|
|
* |
6
|
|
|
* @user Kevin Tanjung |
7
|
|
|
* @website http://kevintanjung.github.io |
8
|
|
|
* @email [email protected] |
9
|
|
|
* @date 02/08/2016 |
10
|
|
|
* @time 11:05 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
use InvalidArgumentException; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The "HTML File based Premailer" class |
17
|
|
|
* |
18
|
|
|
* @package \Luminaire\Premailer |
19
|
|
|
*/ |
20
|
|
|
class HtmlFile extends BasePremailer |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* File path of the HTML source file |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $filename; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Create a new instance of "HTML File Premailer" |
32
|
|
|
* |
33
|
|
|
* @param string $filename |
34
|
|
|
*/ |
35
|
|
|
public function __construct($filename) |
36
|
|
|
{ |
37
|
|
|
$this->setFilename($filename); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Sets the file path of the HTML source file. |
42
|
|
|
* |
43
|
|
|
* @param string $filename |
44
|
|
|
* @return $this |
45
|
|
|
*/ |
46
|
|
|
protected function setFilename($filename) |
47
|
|
|
{ |
48
|
|
|
if ( ! is_string($filename)) |
49
|
|
|
{ |
50
|
|
|
throw new InvalidArgumentException("The argument 0 of the [setFilename] method expects to be a string but [" . gettype($filename). "] given."); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if (is_readable($filename)) |
54
|
|
|
{ |
55
|
|
|
$this->filename = $filename; |
56
|
|
|
} |
57
|
|
|
elseif (file_exists($filename)) |
58
|
|
|
{ |
59
|
|
|
throw new InvalidArgumentException("File [{$filename}] isn't readable."); |
60
|
|
|
} |
61
|
|
|
else |
62
|
|
|
{ |
63
|
|
|
throw new InvalidArgumentException("File [{$filename}] doesn't exist."); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Gets the file path of the HTML source file. |
71
|
|
|
* |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
protected function getFilename() |
75
|
|
|
{ |
76
|
|
|
return $this->filename; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Gets the HTML content from the preferred source. |
81
|
|
|
* |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
protected function getHtmlContent() |
85
|
|
|
{ |
86
|
|
|
return file_get_contents($this->getFilename()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|