PluginProbe
Independent Analytics – WordPress Analytics Plugin / 1.24.0
Independent Analytics – WordPress Analytics Plugin v1.24.0
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 All 120 releases
independent-analytics / IAWP / Utils / URL.php
URL.php
43 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IAWP_SCOPED\IAWP\Utils;
4
5 use IAWP_SCOPED\League\Uri\Contracts\UriException;
6 use IAWP_SCOPED\League\Uri\Uri;
7 class URL
8 {
9 private $url;
10 public function __construct(string $url)
11 {
12 $this->url = $url;
13 }
14 public function is_valid_url() : bool
15 {
16 $valid_url = \filter_var($this->url, \FILTER_VALIDATE_URL);
17 if (!$valid_url) {
18 return \false;
19 }
20 try {
21 // Recommend approach for uri validation: https://uri.thephpleague.com/uri/6.0/rfc3986/#uri-validation
22 $components = Uri::createFromString($this->url);
23 if (\is_null($components->getHost())) {
24 return \false;
25 }
26 return \true;
27 } catch (UriException $e) {
28 return \false;
29 }
30 }
31 public function get_domain() : ?string
32 {
33 if ($this->is_valid_url()) {
34 $components = Uri::createFromString($this->url);
35 $host = $components->getHost();
36 if (!\is_null($host)) {
37 return $host;
38 }
39 }
40 return null;
41 }
42 }
43