Skip to content

Commit d4110ac

Browse files
authored
Merge pull request #241 from jeremykendall/feature/add-labels-method
adding ::labels method see #238
2 parents 2e68002 + a350967 commit d4110ac

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

src/Domain.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,14 @@ public function keys(string $label): array
327327
return array_keys($this->labels, $label, true);
328328
}
329329

330+
/**
331+
* Returns the object labels.
332+
*/
333+
public function labels(): array
334+
{
335+
return $this->labels;
336+
}
337+
330338
/**
331339
* Set IDNA_* options for functions idn_to_ascii.
332340
*

src/PublicSuffix.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@ public function keys(string $label): array
255255
return array_keys($this->labels, $label, true);
256256
}
257257

258+
/**
259+
* Returns the object labels.
260+
*/
261+
public function labels(): array
262+
{
263+
return $this->labels;
264+
}
265+
258266
/**
259267
* Set IDNA_* options for functions idn_to_ascii.
260268
*

tests/DomainTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,23 @@ public function testOffsets()
192192
self::assertSame([], $domain->keys('toto'));
193193
}
194194

195+
/**
196+
* @covers ::labels
197+
*/
198+
public function testLabels()
199+
{
200+
$domain = new Domain('master.com.example.com');
201+
self::assertSame([
202+
'com',
203+
'example',
204+
'com',
205+
'master',
206+
], $domain->labels());
207+
208+
$domain = new Domain();
209+
self::assertSame([], $domain->labels());
210+
}
211+
195212
/**
196213
* @covers ::setLabels
197214
* @covers ::setPublicSuffix

tests/PublicSuffixTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,22 @@ public function testOffsets()
227227
self::assertSame([2], $domain->keys('master'));
228228
}
229229

230+
/**
231+
* @covers ::labels
232+
*/
233+
public function testLabels()
234+
{
235+
$publicSuffix = new PublicSuffix('master.example.com');
236+
self::assertSame([
237+
'com',
238+
'example',
239+
'master',
240+
], $publicSuffix->labels());
241+
242+
$publicSuffix = new PublicSuffix();
243+
self::assertSame([], $publicSuffix->labels());
244+
}
245+
230246
/**
231247
* @covers ::createFromDomain
232248
* @dataProvider createFromDomainProvider

0 commit comments

Comments
 (0)