diff --git a/CHANGELOG.md b/CHANGELOG.md
index bd2dffc..9862bea 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,7 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed
- Curl interface and curl implementation has been removed.
- Removed support for the depth first search option.
-- findById() method removed from Dom object.
+- `findById()` method removed from Dom object.
+- Removed `load()` method in Dom object.
## 2.2.0
diff --git a/README.md b/README.md
index 54c28d0..cbd6480 100755
--- a/README.md
+++ b/README.md
@@ -31,7 +31,7 @@ require "vendor/autoload.php";
use PHPHtmlParser\Dom;
$dom = new Dom;
-$dom->load('
');
+$dom->loadStr('');
$a = $dom->find('a')[0];
echo $a->text; // "click here"
```
@@ -86,7 +86,7 @@ $dom->loadFromUrl('http://google.com');
$html = $dom->outerHtml;
// or
-$dom->load('http://google.com');
+$dom->loadFromUrl('http://google.com');
$html = $dom->outerHtml; // same result as the first example
```
@@ -137,11 +137,11 @@ $dom->setOptions([
'strict' => true, // Set a global option to enable strict html parsing.
]);
-$dom->load('http://google.com', [
+$dom->loadFromUrl('http://google.com', [
'whitespaceTextNode' => false, // Only applies to this load.
]);
-$dom->load('http://gmail.com'); // will not have whitespaceTextNode set to false.
+$dom->loadFromUrl('http://gmail.com'); // will not have whitespaceTextNode set to false.
```
At the moment we support 8 options.
diff --git a/src/PHPHtmlParser/Dom.php b/src/PHPHtmlParser/Dom.php
index ba9ea4a..1cba505 100755
--- a/src/PHPHtmlParser/Dom.php
+++ b/src/PHPHtmlParser/Dom.php
@@ -15,7 +15,6 @@
use PHPHtmlParser\Exceptions\CurlException;
use PHPHtmlParser\Exceptions\LogicalException;
use PHPHtmlParser\Exceptions\NotLoadedException;
-use PHPHtmlParser\Exceptions\ParentNotFoundException;
use PHPHtmlParser\Exceptions\StrictException;
use PHPHtmlParser\Exceptions\UnknownChildTypeException;
use Psr\Http\Client\ClientInterface;
@@ -139,29 +138,6 @@ public function __get($name)
return $this->root->$name;
}
- /**
- * Attempts to load the dom from any resource, string, file, or URL.
- *
- * @throws ChildNotFoundException
- * @throws CircularException
- * @throws CurlException
- * @throws StrictException
- * @throws LogicalException
- */
- public function load(string $str, array $options = []): Dom
- {
- // check if it's a file
- if (\strpos($str, "\n") === false && \is_file($str)) {
- return $this->loadFromFile($str, $options);
- }
- // check if it's a url
- if (\preg_match("/^https?:\/\//i", $str)) {
- return $this->loadFromUrl($str, $options);
- }
-
- return $this->loadStr($str, $options);
- }
-
/**
* Loads the dom from a document file/url.
*
diff --git a/src/PHPHtmlParser/StaticDom.php b/src/PHPHtmlParser/StaticDom.php
index b4c3ef2..411ca3d 100755
--- a/src/PHPHtmlParser/StaticDom.php
+++ b/src/PHPHtmlParser/StaticDom.php
@@ -56,23 +56,6 @@ public static function mount(string $className = 'Dom', ?Dom $dom = null): bool
return true;
}
- /**
- * Creates a new dom object and calls load() on the
- * new object.
- *
- * @throws ChildNotFoundException
- * @throws CircularException
- * @throws CurlException
- * @throws StrictException
- */
- public static function load(string $str): Dom
- {
- $dom = new Dom();
- self::$dom = $dom;
-
- return $dom->load($str);
- }
-
/**
* Creates a new dom object and calls loadFromFile() on the
* new object.
@@ -114,6 +97,14 @@ public static function loadFromUrl(string $url, array $options = [], ClientInter
return $dom->loadFromUrl($url, $options, $client, $request);
}
+ public static function loadStr(string $str, array $options = []): Dom
+ {
+ $dom = new Dom();
+ self::$dom = $dom;
+
+ return $dom->loadStr($str, $options);
+ }
+
/**
* Sets the $dom variable to null.
*/
diff --git a/tests/DomTest.php b/tests/DomTest.php
index d68b0fc..2a904cc 100755
--- a/tests/DomTest.php
+++ b/tests/DomTest.php
@@ -20,14 +20,14 @@ public function testParsingCData()
$html = "";
$dom = new Dom();
$dom->setOptions(['cleanupInput' => false]);
- $dom->load($html);
+ $dom->loadStr($html);
$this->assertSame($html, $dom->root->outerHtml());
}
- public function testLoad()
+ public function testloadStr()
{
$dom = new Dom();
- $dom->load('');
+ $dom->loadStr('');
$div = $dom->find('div', 0);
$this->assertEquals('', $div->outerHtml);
}
@@ -44,7 +44,7 @@ public function testNotLoaded()
public function testIncorrectAccess()
{
$dom = new Dom();
- $dom->load('');
+ $dom->loadStr('');
$div = $dom->find('div', 0);
$this->assertEquals(null, $div->foo);
}
@@ -52,7 +52,7 @@ public function testIncorrectAccess()
public function testLoadSelfclosingAttr()
{
$dom = new Dom();
- $dom->load("
baz
");
+ $dom->loadStr("
baz
");
$br = $dom->find('br', 0);
$this->assertEquals('
', $br->outerHtml);
}
@@ -60,7 +60,7 @@ public function testLoadSelfclosingAttr()
public function testLoadSelfclosingAttrToString()
{
$dom = new Dom();
- $dom->load("
baz
");
+ $dom->loadStr("
baz
");
$br = $dom->find('br', 0);
$this->assertEquals('
', (string) $br);
}
@@ -68,7 +68,7 @@ public function testLoadSelfclosingAttrToString()
public function testLoadEscapeQuotes()
{
$dom = new Dom();
- $dom->load('');
+ $dom->loadStr('');
$div = $dom->find('div', 0);
$this->assertEquals('', $div->outerHtml);
}
@@ -76,14 +76,14 @@ public function testLoadEscapeQuotes()
public function testLoadNoOpeningTag()
{
$dom = new Dom();
- $dom->load('');
+ $dom->loadStr('');
$this->assertEquals('content', $dom->find('.content', 0)->text);
}
public function testLoadNoClosingTag()
{
$dom = new Dom();
- $dom->load('
');
+ $dom->loadStr('
');
$root = $dom->find('div', 0)->getParent();
$this->assertEquals('
', $root->outerHtml);
}
@@ -91,7 +91,7 @@ public function testLoadNoClosingTag()
public function testLoadAttributeOnSelfClosing()
{
$dom = new Dom();
- $dom->load('
');
+ $dom->loadStr('
');
$br = $dom->find('br', 0);
$this->assertEquals('both', $br->getAttribute('class'));
}
@@ -99,7 +99,7 @@ public function testLoadAttributeOnSelfClosing()
public function testLoadClosingTagOnSelfClosing()
{
$dom = new Dom();
- $dom->load('');
+ $dom->loadStr('');
$this->assertEquals('
Hey bro, click here
', $dom->find('div', 0)->innerHtml);
}
@@ -108,7 +108,7 @@ public function testLoadClosingTagOnSelfClosingNoSlash()
$dom = new Dom();
$dom->addNoSlashTag('br');
- $dom->load('');
+ $dom->loadStr('');
$this->assertEquals('
Hey bro, click here
', $dom->find('div', 0)->innerHtml);
}
@@ -116,7 +116,7 @@ public function testLoadClosingTagAddSelfClosingTag()
{
$dom = new Dom();
$dom->addSelfClosingTag('mytag');
- $dom->load('');
+ $dom->loadStr('');
$this->assertEquals('Hey bro, click here
', $dom->find('div', 0)->innerHtml);
}
@@ -127,7 +127,7 @@ public function testLoadClosingTagAddSelfClosingTagArray()
'mytag',
'othertag',
]);
- $dom->load('');
+ $dom->loadStr('');
$this->assertEquals('Hey bro, click here
', $dom->find('div', 0)->innerHtml);
}
@@ -135,7 +135,7 @@ public function testLoadClosingTagRemoveSelfClosingTag()
{
$dom = new Dom();
$dom->removeSelfClosingTag('br');
- $dom->load('');
+ $dom->loadStr('');
$this->assertEquals('
Hey bro, click here
', $dom->find('div', 0)->innerHtml);
}
@@ -143,35 +143,35 @@ public function testLoadClosingTagClearSelfClosingTag()
{
$dom = new Dom();
$dom->clearSelfClosingTags();
- $dom->load('');
+ $dom->loadStr('');
$this->assertEquals('
Hey bro, click here
', $dom->find('div', 0)->innerHtml);
}
public function testLoadNoValueAttribute()
{
$dom = new Dom();
- $dom->load('');
+ $dom->loadStr('');
$this->assertEquals('', $dom->innerHtml);
}
public function testLoadBackslashAttributeValue()
{
$dom = new Dom();
- $dom->load('');
+ $dom->loadStr('');
$this->assertEquals('', $dom->innerHtml);
}
public function testLoadNoValueAttributeBefore()
{
$dom = new Dom();
- $dom->load('');
+ $dom->loadStr('');
$this->assertEquals('', $dom->innerHtml);
}
public function testLoadUpperCase()
{
$dom = new Dom();
- $dom->load('');
+ $dom->loadStr('');
$this->assertEquals('
hEY BRO, CLICK HERE
', $dom->find('div', 0)->innerHtml);
}
@@ -206,7 +206,7 @@ public function testLoadFromFileNotFound()
public function testLoadUtf8()
{
$dom = new Dom();
- $dom->load('Dzień
');
+ $dom->loadStr('Dzień
');
$this->assertEquals('Dzień', $dom->find('p', 0)->text);
}
@@ -268,56 +268,56 @@ public function testLoadFromUrl()
public function testToStringMagic()
{
$dom = new Dom();
- $dom->load('');
+ $dom->loadStr('');
$this->assertEquals('', (string) $dom);
}
public function testGetMagic()
{
$dom = new Dom();
- $dom->load('');
+ $dom->loadStr('');
$this->assertEquals('', $dom->innerHtml);
}
public function testFirstChild()
{
$dom = new Dom();
- $dom->load('
');
+ $dom->loadStr('
');
$this->assertEquals('', $dom->firstChild()->outerHtml);
}
public function testLastChild()
{
$dom = new Dom();
- $dom->load('
');
+ $dom->loadStr('
');
$this->assertEquals('
', $dom->lastChild()->outerHtml);
}
public function testGetElementById()
{
$dom = new Dom();
- $dom->load('
');
+ $dom->loadStr('
');
$this->assertEquals('click here', $dom->getElementById('78')->outerHtml);
}
public function testGetElementsByTag()
{
$dom = new Dom();
- $dom->load('
');
+ $dom->loadStr('
');
$this->assertEquals('Hey bro, click here
', $dom->getElementsByTag('p')[0]->outerHtml);
}
public function testGetElementsByClass()
{
$dom = new Dom();
- $dom->load('
');
+ $dom->loadStr('
');
$this->assertEquals('Hey bro, click here
', $dom->getElementsByClass('all')[0]->innerHtml);
}
public function testScriptCleanerScriptTag()
{
$dom = new Dom();
- $dom->load('
+ $dom->loadStr('
.....