Skip to content

Commit 49dfd15

Browse files
author
Edd-G
committed
Fix: get initial prefix from config
1 parent 8ea0c32 commit 49dfd15

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/HtmlParser.php

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public function __construct(string $html)
4444
require_once( __DIR__ . '/Config.php');
4545
$this->config = new Config();
4646

47+
$this->prefix = $this->config->getPrefix();
48+
4749
libxml_use_internal_errors(true);
4850

4951
$this->html = $html;
@@ -126,6 +128,7 @@ private function init()
126128
if (!$this->hasHtml()) throw new Exception('No HTML to parse !');
127129

128130
$finder = new DomXPath($this->dom);
131+
129132
$nodes = $finder->query("//*[contains(@class, '$this->prefix')]");
130133

131134
foreach ($nodes as $node) {

src/Parser.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ class Parser
2828
/**
2929
* @var string
3030
*/
31-
private $prefix = "prs";
31+
private $prefix;
3232

3333
public function __construct(string $data)
3434
{
35+
require_once( __DIR__ . '/Config.php');
36+
$this->config = new Config();
37+
38+
$this->prefix = $this->config->getPrefix();
39+
3540
$this->data = json_decode($data);
3641

3742
$this->dom = new DOMDocument(1.0, 'UTF-8');
@@ -52,7 +57,7 @@ static function parse($data)
5257
*/
5358
public function getPrefix(): string
5459
{
55-
return $this->prefix;
60+
return !empty($this->prefix) ? $this->prefix : $this->config->getPrefix();
5661
}
5762

5863
/**

0 commit comments

Comments
 (0)