scratch – Blame information for rev 140

Subversion Repositories:
Rev:
Rev Author Line No. Line
126 office 1 <?php
2 /**
3 *
4 * This file is part of the Aura project for PHP.
5 *
6 * @package Aura.Uri
7 *
8 * @license http://opensource.org/licenses/bsd-license.php BSD
9 *
10 */
11 namespace Aura\Uri;
12  
13 /**
14 *
15 * Processing the host
16 *
17 * @package Aura.Uri
18 *
19 */
20 class Host
21 {
22 /**
23 *
24 * The public suffix list.
25 *
26 * @var array
27 *
28 */
29 protected $psl;
30  
31 /**
32 *
33 * The full Host this object represents.
34 *
35 * @var string
36 *
37 */
38 protected $host;
39  
40 /**
41 *
42 * Subdomain portion of host.
43 *
44 * @var string
45 *
46 */
47 protected $subdomain;
48  
49 /**
50 *
51 * Registerable domain portion of host.
52 *
53 * @var string
54 *
55 */
56 protected $registerable_domain;
57  
58 /**
59 *
60 * Public suffix portion of host.
61 *
62 * @var string
63 *
64 */
65 protected $public_suffix;
66  
67 /**
68 *
69 * Constructor.
70 *
71 * @param PublicSuffixList $psl Public suffix list.
72 *
73 * @param array $spec Host elements.
74 *
75 */
76 public function __construct(PublicSuffixList $psl, array $spec = [])
77 {
78 $this->psl = $psl;
79 foreach ($spec as $key => $val) {
80 $this->$key = $val;
81 }
82 }
83  
84 /**
85 *
86 * Returns this Host object as a string.
87 *
88 * @return string The full Host this object represents.
89 *
90 */
91 public function __toString()
92 {
93 return $this->get();
94 }
95  
96 /**
97 *
98 * Returns this Host object as a string.
99 *
100 * @return string The full Host this object represents.
101 *
102 */
103 public function get()
104 {
105 if ($this->host !== null) {
106 return $this->host;
107 }
108  
109 // retain only the elements that are not empty
110 $str = array_filter(
111 [$this->subdomain, $this->registerable_domain],
112 'strlen'
113 );
114  
115 return implode('.', $str);
116 }
117  
118 /**
119 *
120 * Sets values from a host string; overwrites any previous values.
121 *
122 * @param string $spec The host string to use; e.g., 'example.com'.
123 *
124 * @return void
125 *
126 */
127 public function setFromString($spec)
128 {
129 $this->host = $spec;
130 $this->public_suffix = $this->psl->getPublicSuffix($spec);
131 $this->registerable_domain = $this->psl->getRegisterableDomain($spec);
132 $this->subdomain = $this->psl->getSubdomain($spec);
133 }
134  
135 /**
136 *
137 * Returns the public suffix portion of the host.
138 *
139 * @return string
140 *
141 */
142 public function getPublicSuffix()
143 {
144 return $this->public_suffix;
145 }
146  
147 /**
148 *
149 * Returns the subdomain portion of the host.
150 *
151 * @return string
152 *
153 */
154 public function getSubdomain()
155 {
156 return $this->subdomain;
157 }
158  
159 /**
160 *
161 * Returns the registerable domain portion of the host.
162 *
163 * @return string
164 *
165 */
166 public function getRegisterableDomain()
167 {
168 return $this->registerable_domain;
169 }
170 }