Skip to content

Commit c487fce

Browse files
committed
Cleaned up code base
1 parent 3f1f6d6 commit c487fce

32 files changed

+729
-573
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ You can find many examples of how to use the dom parser and any of its parts (wh
2828
```php
2929
// Assuming you installed from Composer:
3030
require "vendor/autoload.php";
31-
use PHPHtmlParser\Dom;
31+
use PHPHtmlParser\Dom\Node;
3232

3333
$dom = new Dom;
3434
$dom->loadStr('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div>');
@@ -46,7 +46,7 @@ You may also seamlessly load a file into the dom instead of a string, which is m
4646
```php
4747
// Assuming you installed from Composer:
4848
require "vendor/autoload.php";
49-
use PHPHtmlParser\Dom;
49+
use PHPHtmlParser\Dom\Node;
5050

5151
$dom = new Dom;
5252
$dom->loadFromFile('tests/data/big.html');
@@ -79,7 +79,7 @@ Loading a url is very similar to the way you would load the html from a file.
7979
```php
8080
// Assuming you installed from Composer:
8181
require "vendor/autoload.php";
82-
use PHPHtmlParser\Dom;
82+
use PHPHtmlParser\Dom\Node;
8383

8484
$dom = new Dom;
8585
$dom->loadFromUrl('http://google.com');
@@ -95,7 +95,7 @@ What makes the loadFromUrl method note worthy is the `PHPHtmlParser\CurlInterfac
9595
```php
9696
// Assuming you installed from Composer:
9797
require "vendor/autoload.php";
98-
use PHPHtmlParser\Dom;
98+
use PHPHtmlParser\Dom\Node;
9999
use App\Services\Connector;
100100

101101
$dom = new Dom;
@@ -113,7 +113,7 @@ Loading a string directly, with out the checks in `load()` is also easily done.
113113
```php
114114
// Assuming you installed from Composer:
115115
require "vendor/autoload.php";
116-
use PHPHtmlParser\Dom;
116+
use PHPHtmlParser\Dom\Node;
117117

118118
$dom = new Dom;
119119
$dom->loadStr('<html>String</html>', []);
@@ -130,7 +130,7 @@ You can also set parsing option that will effect the behavior of the parsing eng
130130
```php
131131
// Assuming you installed from Composer:
132132
require "vendor/autoload.php";
133-
use PHPHtmlParser\Dom;
133+
use PHPHtmlParser\Dom\Node;
134134

135135
$dom = new Dom;
136136
$dom->setOptions([
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace PHPHtmlParser\Contracts\Dom;
4+
5+
use PHPHtmlParser\Exceptions\LogicalException;
6+
use PHPHtmlParser\Options;
7+
8+
interface CleanerInterface
9+
{
10+
/**
11+
* Cleans the html of any none-html information.
12+
*
13+
* @throws LogicalException
14+
*/
15+
public function clean(string $str, Options $options): string;
16+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace PHPHtmlParser\Contracts\Dom;
4+
5+
use PHPHtmlParser\Content;
6+
use PHPHtmlParser\Dom\Node\AbstractNode;
7+
use PHPHtmlParser\Exceptions\ChildNotFoundException;
8+
use PHPHtmlParser\Exceptions\CircularException;
9+
use PHPHtmlParser\Exceptions\ContentLengthException;
10+
use PHPHtmlParser\Exceptions\LogicalException;
11+
use PHPHtmlParser\Exceptions\StrictException;
12+
use PHPHtmlParser\Options;
13+
14+
interface ParserInterface
15+
{
16+
/**
17+
* Attempts to parse the html in content.
18+
*
19+
* @throws ChildNotFoundException
20+
* @throws CircularException
21+
* @throws ContentLengthException
22+
* @throws LogicalException
23+
* @throws StrictException
24+
*/
25+
public function parse(Options $options, Content $content, int $size): AbstractNode;
26+
27+
/**
28+
* Attempts to detect the charset that the html was sent in.
29+
*
30+
* @throws ChildNotFoundException
31+
*/
32+
public function detectCharset(Options $options, string $defaultCharset, AbstractNode $root): bool;
33+
}

src/PHPHtmlParser/Contracts/Selector/SelectorInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace PHPHtmlParser\Contracts\Selector;
66

7-
use PHPHtmlParser\Dom\AbstractNode;
8-
use PHPHtmlParser\Dom\Collection;
7+
use PHPHtmlParser\Dom\Node\AbstractNode;
8+
use PHPHtmlParser\Dom\Node\Collection;
99
use PHPHtmlParser\DTO\Selector\ParsedSelectorCollectionDTO;
1010
use PHPHtmlParser\Exceptions\ChildNotFoundException;
1111

src/PHPHtmlParser/DTO/TagDTO.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PHPHtmlParser\DTO;
66

7-
use PHPHtmlParser\Dom\HtmlNode;
7+
use PHPHtmlParser\Dom\Node\HtmlNode;
88

99
final class TagDTO
1010
{
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PHPHtmlParser\Discovery;
6+
7+
use PHPHtmlParser\Contracts\Dom\CleanerInterface;
8+
use PHPHtmlParser\Dom\Cleaner;
9+
10+
class CleanerDiscovery
11+
{
12+
/**
13+
* @var Cleaner|null
14+
*/
15+
private static $parser = null;
16+
17+
public static function find(): CleanerInterface
18+
{
19+
if (self::$parser == null) {
20+
self::$parser = new Cleaner();
21+
}
22+
23+
return self::$parser;
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PHPHtmlParser\Discovery;
6+
7+
use PHPHtmlParser\Contracts\Dom\ParserInterface;
8+
use PHPHtmlParser\Dom\Parser;
9+
10+
class DomParserDiscovery
11+
{
12+
/**
13+
* @var ParserInterface|null
14+
*/
15+
private static $parser = null;
16+
17+
public static function find(): ParserInterface
18+
{
19+
if (self::$parser == null) {
20+
self::$parser = new Parser();
21+
}
22+
23+
return self::$parser;
24+
}
25+
}

src/PHPHtmlParser/Discovery/ParserDiscovery.php renamed to src/PHPHtmlParser/Discovery/SelectorParserDiscovery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PHPHtmlParser\Contracts\Selector\ParserInterface;
88
use PHPHtmlParser\Selector\Parser;
99

10-
class ParserDiscovery
10+
class SelectorParserDiscovery
1111
{
1212
/**
1313
* @var ParserInterface|null

0 commit comments

Comments
 (0)