Skip to content

Commit 504129b

Browse files
committed
Url::match() optimization
1 parent 5e62faf commit 504129b

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Embed/Url.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,21 @@ public function getUrl()
5151
*/
5252
public function match($pattern)
5353
{
54-
if (is_array($pattern)) {
55-
foreach ($pattern as $p) {
56-
if ($this->match($p) === true) {
57-
return true;
58-
}
59-
}
54+
$url = $this->getUrl();
6055

61-
return false;
56+
if (!is_array($pattern)) {
57+
$pattern = array($pattern);
6258
}
6359

64-
$pattern = str_replace(array('\\*', '\\?'), array('.+', '?'), preg_quote($pattern, '|'));
60+
foreach ($pattern as $pattern) {
61+
$pattern = str_replace(array('\\*', '\\?'), array('.+', '?'), preg_quote($pattern, '|'));
62+
63+
if (preg_match('|^'.$pattern.'$|i', $url)) {
64+
return true;
65+
}
66+
}
6567

66-
return (preg_match('|^'.$pattern.'$|i', $this->getUrl()) === 1) ? true : false;
68+
return false;
6769
}
6870

6971

0 commit comments

Comments
 (0)