-
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.
Add UserModeParser from irc-project to fix NamReply bug with userhost…
…-in-names Signed-off-by: NanoSector <rick@nanosector.nl>
- Loading branch information
1 parent
c10dcd1
commit a626acf
Showing
2 changed files
with
51 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* Copyright 2019 The WildPHP Team | ||
* | ||
* You should have received a copy of the MIT license with the project. | ||
* See the LICENSE file for more information. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WildPHP\Messages\Utility; | ||
|
||
class UserModeParser | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected static $prefixMap = [ | ||
'@' => 'o', | ||
'%' => 'h', | ||
'+' => 'v' | ||
]; | ||
|
||
/** | ||
* @param string $nickname | ||
* @param string $remainders | ||
* | ||
* @return array | ||
*/ | ||
public static function extractFromNickname(string $nickname, string &$remainders): array | ||
{ | ||
$parts = str_split($nickname); | ||
$modes = []; | ||
|
||
foreach ($parts as $key => $part) { | ||
if (!array_key_exists($part, self::$prefixMap)) { | ||
$remainders = implode('', $parts); | ||
break; | ||
} | ||
|
||
unset($parts[$key]); | ||
$modes[] = self::$prefixMap[$part]; | ||
} | ||
|
||
return $modes; | ||
} | ||
} |