Skip to content

Commit

Permalink
Fixed #155, removed load method call
Browse files Browse the repository at this point in the history
  • Loading branch information
paquettg committed Jul 14, 2020
1 parent 8fccd89 commit 1a1c3eb
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 123 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require "vendor/autoload.php";
use PHPHtmlParser\Dom;

$dom = new Dom;
$dom->load('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div>');
$dom->loadStr('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div>');
$a = $dom->find('a')[0];
echo $a->text; // "click here"
```
Expand Down Expand Up @@ -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
```

Expand Down Expand Up @@ -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.
Expand Down
24 changes: 0 additions & 24 deletions src/PHPHtmlParser/Dom.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
25 changes: 8 additions & 17 deletions src/PHPHtmlParser/StaticDom.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*/
Expand Down
Loading

0 comments on commit 1a1c3eb

Please sign in to comment.