@@ -11,9 +11,10 @@ public function __construct(
1111 public ?string $ host = null ,
1212 public ?string $ domain = null ,
1313 public ?string $ tld = null ,
14+ private ?bool $ isValid = null ,
1415 public ?bool $ isPrivate = null ,
1516 ) {
16- $ parsed = HostParser::parse ($ this ->original );
17+ $ parsed = HostParser::parse (strtolower ( $ this ->original ) );
1718
1819 $ this ->host = strval ($ parsed ['host ' ]);
1920 }
@@ -38,6 +39,11 @@ public function tld(?string $tld = null): string|self
3839 $ this ->tld = $ tld ;
3940
4041 $ root = str_replace (strval ($ this ->tld ), '' , strval ($ this ->host ));
42+
43+ if (!validate_domain_root (trim ($ root , '. ' ))) {
44+ $ this ->isValid = false ;
45+ }
46+
4147 $ root = explode ('. ' , trim (strval ($ root ), '. ' ));
4248
4349 $ this ->domain (end ($ root ) . '. ' . $ this ->tld );
@@ -58,7 +64,7 @@ public function domain(?string $domain = null): string|self
5864
5965 public function isValid (): bool
6066 {
61- return !empty ($ this ->tld ());
67+ return $ this -> isValid ?? !empty ($ this ->tld ());
6268 }
6369
6470 public function isPrivate (?bool $ isPrivate = null ): bool |self
0 commit comments