Skip to content

Commit

Permalink
Improvements 👾
Browse files Browse the repository at this point in the history
- Fixed Helper::parseVersion()
- Fixed Request::is()
- Fixed deprecated strcasecmp()
- Fixed Inphinit\Experimental\Routing\Group::checkDomain() (ports)
- DOMDocument::save supports PHP8.1 (ReturnTypeWillChange)
  • Loading branch information
brcontainer committed Jan 28, 2022
1 parent 851cb88 commit 81a28d7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Experimental/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function isBinary($path)
$encode = finfo_buffer($finfo, file_get_contents($path, false, null, 0, 5012));
finfo_close($finfo);

self::$bin[$path] = strcasecmp($encode, 'binary') === 0;
self::$bin[$path] = $encode ? strcasecmp($encode, 'binary') === 0 : false;
}

return self::$bin[$path];
Expand Down
2 changes: 1 addition & 1 deletion src/Experimental/Routing/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected function checkDomain()
} else {
$host = Request::header('Host');

self::$cacheHost = $host ? strtok($host, ':') : '';
$host = self::$cacheHost = $host ? strtok($host, ':') : '';
}

if ($host === $this->domain) {
Expand Down
1 change: 1 addition & 0 deletions src/Inphinit/Dom/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public function __toString()
* @throws \Inphinit\Dom\DomException
* @return void
*/
#[\ReturnTypeWillChange]
public function save($path, $format = Document::XML)
{
switch ($format) {
Expand Down
10 changes: 6 additions & 4 deletions src/Inphinit/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ class Helper
*/
public static function parseVersion($version)
{
if (preg_match('#^(\d+)\.(\d+)\.(\d+)(-([\da-z]+(\.[\da-z]+)*)(\+([\da-z]+(\.[\da-z]+)*))?)?$#', $version, $match)) {
//if (preg_match('#^(\d+)\.(\d+)\.(\d+)(-([\da-z]+(\.[\da-z]+)*)(\+([\da-z]+(\.[\da-z]+)*))?)?$#', $version, $matches)) {

if (preg_match('#^(\d|[1-9]\d+)\.(\d|[1-9]\d+)\.(\d|[1-9]\d+)((?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$#', $version, $matches)) {
$matches = array(
'major' => $matches[1],
'minor' => $matches[2],
'patch' => $matches[3],
'extra' => $matches[4],
'release' => explode('.', $matches[5]),
'build' => explode('.', $matches[8])
'extra' => isset($matches[4]) ? $matches[4] : null,
'release' => isset($matches[5]) && $matches[5] !== '' ? explode('.', $matches[5]) : null,
'build' => isset($matches[6]) && $matches[6] !== '' ? explode('.', $matches[6]) : null
);

return (object) $matches;
Expand Down
16 changes: 13 additions & 3 deletions src/Inphinit/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,23 @@ public static function is($check)
return empty($_SERVER['HTTPS']) === false && strcasecmp($_SERVER['HTTPS'], 'on') === 0;

case 'xhr':
return strcasecmp(self::header('X-Requested-With'), 'xmlhttprequest') === 0;
return strcasecmp((string) self::header('X-Requested-With'), 'xmlhttprequest') === 0;

case 'pjax':
return strcasecmp(self::header('X-Pjax'), 'true') === 0;
return strcasecmp((string) self::header('X-Pjax') || '', 'true') === 0;

case 'prefetch':
return strcasecmp(self::header('Purpose') || self::header('X-Moz') || self::header('X-Purpose'), 'prefetch') === 0;
if ($data = self::header('Purpose')) {
$prop = $data;
} elseif ($data = self::header('X-Moz')) {
$prop = $data;
} elseif ($data = self::header('X-Purpose')) {
$prop = $data;
} else {
return false;
}

return strcasecmp($prop, 'prefetch') === 0;
}

return strcasecmp($_SERVER['REQUEST_METHOD'], $check) === 0;
Expand Down

0 comments on commit 81a28d7

Please sign in to comment.