Skip to content

Commit

Permalink
Merge pull request #106 from pamil/4.x-idntoasciideprecated
Browse files Browse the repository at this point in the history
Workaround deprecated variant in `idn_to_*` functions & PHP 7.2 support
  • Loading branch information
nyamsprod authored Oct 17, 2017
2 parents f2c9d3e + 04457bf commit 81a6f8f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ matrix:
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=false
- php: 7.1
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=false
- php: 7.2
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=false
- php: hhvm
env: COLLECT_COVERAGE=false VALIDATE_CODING_STYLE=false
fast_finish: true
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ext-mbstring" : "*",
"ext-intl" : "*",
"ext-fileinfo": "*",
"jeremykendall/php-domain-parser": "^3.0",
"jeremykendall/php-domain-parser": "4.0.3-alpha",
"php" : ">=5.5.9",
"psr/http-message": "^1.0"
},
Expand Down
10 changes: 9 additions & 1 deletion src/Components/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,15 @@ public function getLabels()
public function getLabel($offset, $default = null)
{
if (isset($this->data[$offset])) {
return $this->isIdn ? rawurldecode($this->data[$offset]) : idn_to_ascii($this->data[$offset]);
if ($this->isIdn) {
return rawurldecode($this->data[$offset]);
}

if (PHP_VERSION_ID >= 70200) {
return @idn_to_ascii($this->data[$offset]);
}

return idn_to_ascii($this->data[$offset]);
}

return $default;
Expand Down
6 changes: 3 additions & 3 deletions src/Components/HostnameTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function convertToAscii(array $labels, $convert)

foreach ($labels as &$label) {
if ('' !== $label) {
$label = idn_to_ascii($label);
$label = PHP_VERSION_ID >= 70200 ? @idn_to_ascii($label) : idn_to_ascii($label);
}
}
unset($label);
Expand All @@ -65,14 +65,14 @@ protected function validateStringHost($str)
$host = $this->lower($this->setIsAbsolute($str));
$raw_labels = explode('.', $host);
$labels = array_map(function ($value) {
return idn_to_ascii($value);
return PHP_VERSION_ID >= 70200 ? @idn_to_ascii($value) : idn_to_ascii($value);
}, $raw_labels);

$this->assertValidHost($labels);
$this->isIdn = $raw_labels !== $labels;

return array_reverse(array_map(function ($label) {
return idn_to_utf8($label);
return PHP_VERSION_ID >= 70200 ? @idn_to_utf8($label) : idn_to_utf8($label);
}, $labels));
}

Expand Down
8 changes: 4 additions & 4 deletions test/Components/DataPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public function testWithPath()
public function testCreateFromPath($path, $expected)
{
$uri = Path::createFromPath(dirname(__DIR__).'/data/'.$path);
$this->assertSame($expected, $uri->getMimeType());
$this->assertContains($uri->getMimeType(), $expected);
}

public function validFilePath()
{
return [
'text file' => ['hello-world.txt', 'text/plain'],
'img file' => ['red-nose.gif', 'image/gif'],
'vcard file' => ['john-doe.vcf', 'text/x-vcard'],
'text file' => ['hello-world.txt', ['text/plain']],
'img file' => ['red-nose.gif', ['image/gif']],
'vcard file' => ['john-doe.vcf', ['text/x-vcard', 'text/vcard']],
];
}

Expand Down

0 comments on commit 81a6f8f

Please sign in to comment.