Skip to content

Commit 2e68002

Browse files
committed
Add more control over IDNA options
1 parent 3a99c53 commit 2e68002

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

src/Rules.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,30 @@ public static function __set_state(array $properties): self
143143
);
144144
}
145145

146+
/**
147+
* Set IDNA_* options for functions idn_to_ascii.
148+
*
149+
* @see https://www.php.net/manual/en/intl.constants.php
150+
*
151+
* @return int
152+
*/
153+
public function getAsciiIDNAOption(): int
154+
{
155+
return $this->asciiIDNAOption;
156+
}
157+
158+
/**
159+
* Set IDNA_* options for functions idn_to_utf8.
160+
*
161+
* @see https://www.php.net/manual/en/intl.constants.php
162+
*
163+
* @return int
164+
*/
165+
public function getUnicodeIDNAOption(): int
166+
{
167+
return $this->unicodeIDNAOption;
168+
}
169+
146170
/**
147171
* Determines the public suffix for a given domain.
148172
*

src/TopLevelDomains.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,30 @@ public function getModifiedDate(): DateTimeImmutable
176176
return $this->modifiedDate;
177177
}
178178

179+
/**
180+
* Set IDNA_* options for functions idn_to_ascii.
181+
*
182+
* @see https://www.php.net/manual/en/intl.constants.php
183+
*
184+
* @return int
185+
*/
186+
public function getAsciiIDNAOption(): int
187+
{
188+
return $this->asciiIDNAOption;
189+
}
190+
191+
/**
192+
* Set IDNA_* options for functions idn_to_utf8.
193+
*
194+
* @see https://www.php.net/manual/en/intl.constants.php
195+
*
196+
* @return int
197+
*/
198+
public function getUnicodeIDNAOption(): int
199+
{
200+
return $this->unicodeIDNAOption;
201+
}
202+
179203
/**
180204
* {@inheritdoc}
181205
*/

tests/RulesTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,10 @@ public function testPublicSuffixSpec()
644644
$this->checkPublicSuffix('xn--fiqs8s', null);
645645
}
646646

647+
/**
648+
* @covers ::getAsciiIDNAOption
649+
* @covers ::getUnicodeIDNAOption
650+
*/
647651
public function testResolveWithIDNAOptions()
648652
{
649653
$resolvedByDefault = $this->rules->resolve('foo.de', Rules::ICANN_DOMAINS);
@@ -655,7 +659,7 @@ public function testResolveWithIDNAOptions()
655659
$rules = $manager->getRules(Manager::PSL_URL, null, 16, 32);
656660
$resolved = $rules->resolve('foo.de', Rules::ICANN_DOMAINS);
657661
self::assertSame(
658-
[16, 32],
662+
[$rules->getAsciiIDNAOption(), $rules->getUnicodeIDNAOption()],
659663
[$resolved->getAsciiIDNAOption(), $resolved->getUnicodeIDNAOption()]
660664
);
661665
}

tests/TopLevelDomainsTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,21 @@ public function testGetterProperties()
9595
}
9696

9797
/**
98+
* @covers ::getAsciiIDNAOption
99+
* @covers ::getUnicodeIDNAOption
98100
* @covers ::withIDNAOptions
99101
*/
100102
public function testwithIDNAOptions()
101103
{
102-
self::assertSame($this->collection, $this->collection->withIDNAOptions(IDNA_DEFAULT, IDNA_DEFAULT));
103-
self::assertNotEquals($this->collection, $this->collection->withIDNAOptions(IDNA_DEFAULT, 128));
104+
self::assertSame($this->collection, $this->collection->withIDNAOptions(
105+
$this->collection->getAsciiIDNAOption(),
106+
$this->collection->getUnicodeIDNAOption()
107+
));
108+
109+
self::assertNotEquals($this->collection, $this->collection->withIDNAOptions(
110+
$this->collection->getAsciiIDNAOption(),
111+
128
112+
));
104113
}
105114

106115
/**

0 commit comments

Comments
 (0)