1 | <?php |
||
10 | class BladeOnDemandRenderer |
||
11 | { |
||
12 | /** |
||
13 | * @var \Illuminate\View\Factory |
||
14 | */ |
||
15 | private $viewFactory; |
||
16 | |||
17 | /** |
||
18 | * @var \Illuminate\Mail\Markdown |
||
19 | */ |
||
20 | private $markdown; |
||
21 | |||
22 | /** |
||
23 | * @var \TijsVerkoyen\CssToInlineStyles\CssToInlineStyles |
||
24 | */ |
||
25 | private $cssInliner; |
||
26 | |||
27 | /** |
||
28 | * Wether to fill the missing variables from the template. |
||
29 | * |
||
30 | * @var boolean|callable |
||
31 | */ |
||
32 | private $fillMissingVariables = false; |
||
33 | |||
34 | /** |
||
35 | * The current theme being used when generating emails. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | private $theme = 'default'; |
||
40 | |||
41 | public function __construct(ViewFactory $viewFactory, Markdown $markdown, CssToInlineStyles $cssInliner) |
||
49 | |||
50 | /** |
||
51 | * Fills the missing variables in the template |
||
52 | * |
||
53 | * @param callable $callback |
||
54 | * @return $this |
||
55 | */ |
||
56 | public function fillMissingVariables(callable $callback = null) |
||
62 | |||
63 | /** |
||
64 | * Set the default theme to be used. |
||
65 | * |
||
66 | * @param string $theme |
||
67 | * @return $this |
||
68 | */ |
||
69 | public function theme($theme) |
||
75 | |||
76 | /** |
||
77 | * Renders the content with the given data. |
||
78 | * |
||
79 | * @param string $contents |
||
80 | * @param array $data |
||
81 | * @return string |
||
82 | */ |
||
83 | public function render(string $contents, array $data = []): string |
||
103 | |||
104 | /** |
||
105 | * Finds all missing variables. |
||
106 | * Source: https://stackoverflow.com/a/19563063 |
||
107 | * |
||
108 | * @param string $contents |
||
109 | * @param array $data |
||
110 | * @return array |
||
111 | */ |
||
112 | public function getMissingVariables(string $contents, array $data = []): array |
||
124 | |||
125 | /** |
||
126 | * Makes sure each variable is present in the data array. |
||
127 | * |
||
128 | * @param string $contents |
||
129 | * @param array $data |
||
130 | * @return array |
||
131 | */ |
||
132 | private function addMissingVariables(string $contents, array $data = []): array |
||
142 | |||
143 | /** |
||
144 | * Renders the markdown content to a HTML mail. |
||
145 | * |
||
146 | * @param string $contents |
||
147 | * @param array $data |
||
148 | * @return string |
||
149 | */ |
||
150 | public function renderMarkdownMailToHtml(string $contents, array $data = []): string |
||
165 | |||
166 | /** |
||
167 | * Renders the markdown content to a Text mail. |
||
168 | * |
||
169 | * @param string $contents |
||
170 | * @param array $data |
||
171 | * @return string |
||
172 | */ |
||
173 | public function renderMarkdownMailToText(string $contents, array $data = []): string |
||
181 | |||
182 | /** |
||
183 | * Parses the markdown content. |
||
184 | * |
||
185 | * @param string $contents |
||
186 | * @param array $data |
||
187 | * @return string |
||
188 | */ |
||
189 | public function parseMarkdownMail(string $contents, array $data = []): string |
||
193 | } |
||
194 |