Skip to content

Commit e15c0b2

Browse files
committed
New names for some methods
1 parent cd7e809 commit e15c0b2

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

src/HTMLServerComponentsCompiler.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class HTMLServerComponentsCompiler
1616
/**
1717
*
1818
*/
19-
const VERSION = '0.1.1';
19+
const VERSION = '0.2.0';
2020

2121
/**
2222
*
@@ -130,7 +130,7 @@ public function process($html)
130130

131131
$domDocument2 = new DOMDocument;
132132
$domDocument2->formatOutput = false;
133-
set_error_handler([$this, "handleInvalidTagWarning"]);
133+
set_error_handler([$this, "handleInvalidHTMLErrors"]);
134134
$domDocument2->loadHTML($domDocument->saveHTML());
135135
restore_error_handler();
136136
return $domDocument2->saveHTML();
@@ -158,24 +158,9 @@ public function processData($data)
158158
* @return string
159159
*/
160160
public function processFile($file, $attributes = [], $innerHTML = '')
161-
{
162-
return $this->process($this->getComponentContent($file, $attributes, $innerHTML));
163-
}
164-
165-
/**
166-
*
167-
* @param string $file
168-
* @param array $attributes
169-
* @param string $innerHTML
170-
* @return string
171-
*/
172-
private function getComponentContent($file, $attributes = [], $innerHTML = '')
173161
{
174162
$component = $this->constructComponent($attributes, $innerHTML);
175-
ob_start();
176-
$this->includeComponentFile($file, $component);
177-
$content = ob_get_clean();
178-
return $content;
163+
return $this->process($this->getComponentFileContent($file, $component));
179164
}
180165

181166
/**
@@ -196,10 +181,19 @@ protected function constructComponent($attributes = [], $innerHTML = '')
196181
*
197182
* @param string $file
198183
* @param HTMLServerComponent $component
184+
* @throws \Exception
185+
* @return string
199186
*/
200-
protected function includeComponentFile($file, $component)
187+
protected function getComponentFileContent($file, $component)
201188
{
202-
include $file;
189+
if (is_file($file)) {
190+
ob_start();
191+
include $file;
192+
$content = ob_get_clean();
193+
return $content;
194+
} else {
195+
throw new \Exception('Component file cannot be found');
196+
}
203197
}
204198

205199
/**
@@ -234,7 +228,7 @@ private function getDOMDocument($html)
234228
$html = '<!DOCTYPE html>' . $html;
235229
}
236230
$domDocument = new DOMDocument();
237-
set_error_handler([$this, "handleInvalidTagWarning"]);
231+
set_error_handler([$this, "handleInvalidHTMLErrors"]);
238232
$result = $domDocument->loadHTML('<?xml encoding="utf-8" ?>' . $html);
239233
restore_error_handler();
240234
if ($result === false) {
@@ -296,10 +290,9 @@ private function trimDOMElement(&$domElement)
296290
* @param string $errorMessage
297291
* @return boolean
298292
*/
299-
public function handleInvalidTagWarning($errorNumber, $errorMessage)
293+
public function handleInvalidHTMLErrors($errorNumber, $errorMessage)
300294
{
301295
return true;
302-
//return $errorNumber === 2 && strpos($errorMessage, 'invalid in Entity') !== false;
303296
}
304297

305298
}

0 commit comments

Comments
 (0)