Skip to content

Commit e596b68

Browse files
committed
Merge branch 'jared-conexed-master'
2 parents d25b2bf + f23b6da commit e596b68

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
],
1616
"require": {
1717
"php": ">=5.3",
18-
"ext-curl": "*",
19-
"ext-mbstring": "*"
18+
"ext-curl": "*"
2019
},
2120
"require-dev": {
2221
"ext-gd": "*",
2322
"phpunit/phpunit": "*",
2423
"squizlabs/php_codesniffer": "*"
2524
},
25+
"suggest": {
26+
"ext-mbstring": "*"
27+
},
2628
"autoload": {
2729
"psr-4": {
2830
"Curl\\": "src/Curl/"

src/Curl/StringUtil.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,42 @@
44

55
class StringUtil
66
{
7+
public static function characterReversePosition($haystack, $needle, $part = false)
8+
{
9+
if (function_exists('\mb_strrchr')) {
10+
return \mb_strrchr($haystack, $needle, $part);
11+
} else {
12+
return \strrchr($haystack, $needle);
13+
}
14+
}
15+
16+
public static function length($string)
17+
{
18+
if (function_exists('\mb_strlen')) {
19+
return \mb_strlen($string);
20+
} else {
21+
return \strlen($string);
22+
}
23+
}
24+
25+
public static function position($haystack, $needle, $offset = 0)
26+
{
27+
if (function_exists('\mb_strpos')) {
28+
return \mb_strpos($haystack, $needle, $offset);
29+
} else {
30+
return \strpos($haystack, $needle, $offset);
31+
}
32+
}
33+
34+
public static function reversePosition($haystack, $needle, $offset = 0)
35+
{
36+
if (function_exists('\mb_strrpos')) {
37+
return \mb_strrpos($haystack, $needle, $offset);
38+
} else {
39+
return \strrpos($haystack, $needle, $offset);
40+
}
41+
}
42+
743
/**
844
* Return true when $haystack starts with $needle.
945
*
@@ -15,6 +51,15 @@ class StringUtil
1551
*/
1652
public static function startsWith($haystack, $needle)
1753
{
18-
return \mb_substr($haystack, 0, \mb_strlen($needle)) === $needle;
54+
return self::substring($haystack, 0, self::length($needle)) === $needle;
55+
}
56+
57+
public static function substring($string, $start, $length)
58+
{
59+
if (function_exists('\mb_substr')) {
60+
return \mb_substr($string, $start, $length);
61+
} else {
62+
return \substr($string, $start, $length);
63+
}
1964
}
2065
}

src/Curl/Url.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public static function removeDotSegments($input)
5656
// buffer; otherwise,
5757
} elseif (StringUtil::startsWith($input, '/../')) {
5858
$input = substr($input, 3);
59-
$output = substr_replace($output, '', \mb_strrpos($output, '/'));
59+
$output = substr_replace($output, '', StringUtil::reversePosition($output, '/'));
6060
} elseif ($input === '/..') {
6161
$input = '/';
62-
$output = substr_replace($output, '', \mb_strrpos($output, '/'));
62+
$output = substr_replace($output, '', StringUtil::reversePosition($output, '/'));
6363

6464
// D. if the input buffer consists only of "." or "..", then remove
6565
// that from the input buffer; otherwise,
@@ -70,7 +70,7 @@ public static function removeDotSegments($input)
7070
// the output buffer, including the initial "/" character (if
7171
// any) and any subsequent characters up to, but not including,
7272
// the next "/" character or the end of the input buffer.
73-
} elseif (!(($pos = \mb_strpos($input, '/', 1)) === false)) {
73+
} elseif (!(($pos = StringUtil::position($input, '/', 1)) === false)) {
7474
$output .= substr($input, 0, $pos);
7575
$input = substr_replace($input, '', 0, $pos);
7676
} else {
@@ -131,7 +131,7 @@ private function absolutizeUrl()
131131
if (StringUtil::startsWith($r['path'], '/')) {
132132
$target['path'] = self::removeDotSegments($r['path']);
133133
} else {
134-
$base = \mb_strrchr($b['path'], '/', true);
134+
$base = StringUtil::characterReversePosition($b['path'], '/', true);
135135
if ($base === false) {
136136
$base = '';
137137
}

0 commit comments

Comments
 (0)