-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
545 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Octamp\Wamp\Matcher; | ||
|
||
class ExactMatch implements MatchInterface | ||
{ | ||
|
||
public function getName(): string | ||
{ | ||
return 'exact'; | ||
} | ||
|
||
public function isMatched($uri, $uri2): bool | ||
{ | ||
return $uri === $uri2; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Octamp\Wamp\Matcher; | ||
|
||
interface MatchInterface | ||
{ | ||
public function getName(): string; | ||
|
||
public function isMatched(string $uri, string $uri2): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Octamp\Wamp\Matcher; | ||
|
||
class Matcher | ||
{ | ||
/** | ||
* @var MatchInterface[] | ||
*/ | ||
protected array $matches = []; | ||
|
||
public function __construct() | ||
{ | ||
$this->addMatch(new ExactMatch()); | ||
} | ||
|
||
public function addMatch(MatchInterface $match): void | ||
{ | ||
$this->matches[$match->getName()] = $match; | ||
} | ||
|
||
public function isMatch(string $from, string $to, string $name): bool | ||
{ | ||
if (!isset($this->matches[$name])) { | ||
return false; | ||
} | ||
|
||
return $this->matches[$name]->isMatched($from, $to); | ||
} | ||
|
||
/** | ||
* @throws UnExistMatchException | ||
*/ | ||
public function getMatch($name): MatchInterface | ||
{ | ||
if (!isset($this->matches[$name])) { | ||
throw new UnExistMatchException('Matcher ' . $name . ' does not exists'); | ||
} | ||
|
||
return $this->matches[$name]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Octamp\Wamp\Matcher; | ||
|
||
class PrefixMatch implements MatchInterface | ||
{ | ||
|
||
public function getName(): string | ||
{ | ||
return 'prefix'; | ||
} | ||
|
||
public function isMatched(string $uri, string $uri2): bool | ||
{ | ||
if ($uri === $uri2) { | ||
return true; | ||
} | ||
|
||
$pattern = '/^(' . $uri . ')(\.|-).*$/'; | ||
|
||
return preg_match($pattern, $uri2) === 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Octamp\Wamp\Matcher; | ||
|
||
class UnExistMatchException extends \Exception | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Octamp\Wamp\Matcher; | ||
|
||
class WildcardMatch implements MatchInterface | ||
{ | ||
|
||
public function getName(): string | ||
{ | ||
return 'wildcard'; | ||
} | ||
|
||
public function isMatched(string $uri, string $uri2): bool | ||
{ | ||
if ($uri === $uri2) { | ||
return true; | ||
} | ||
|
||
$len = strlen($uri); | ||
if ($uri[$len - 1] === '.' || $uri[$len - 1] === '-') { | ||
$uri = substr_replace($uri, ')(.*)(\.|-)', $len - 1, 1); | ||
} else { | ||
$uri .= ')'; | ||
} | ||
|
||
if ($uri[0] === '.' || $uri[0] === '-') { | ||
$uri = substr_replace($uri, '(.*)(\.|-)(', 0, 1); | ||
} else { | ||
$uri = '(' . $uri; | ||
} | ||
|
||
|
||
$uri = str_replace('..', ')(\.|-)(.*)(\.|-)(', $uri); | ||
$uri = str_replace('.-', ')(\.|-)(.*)(\.|-)(', $uri); | ||
$uri = str_replace('-.', ')(\.|-)(.*)(\.|-)(', $uri); | ||
$uri = str_replace('--', ')(\.|-)(.*)(\.|-)(', $uri); | ||
|
||
$patterns = '/^' . $uri . '$/'; | ||
|
||
return preg_match($patterns, $uri2) === 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.