PHPDaemon\Utils\IRC::getCodeByCommand PHP Method

getCodeByCommand() public static method

public static getCodeByCommand ( string $cmd ) : integer
$cmd string Command
return integer
    public static function getCodeByCommand($cmd)
    {
        if (self::$codesFlip === null) {
            self::$codesFlip = array_flip(self::$codes);
        }
        if (isset(self::$codesFlip[$cmd])) {
            return sprintf('%03u', self::$codesFlip[$cmd]);
        }
        return $cmd;
    }

Usage Example

Beispiel #1
0
 /**
  * @TODO
  * @param  string $from From
  * @param  string $cmd  Command
  * @param  array  $args Arguments
  */
 public function commandArr($from, $cmd, $args)
 {
     if ($from === null) {
         $from = $this->pool->config->servername->value;
     }
     if (is_string($args)) {
         Daemon::log(get_class($this) . '->commandArr: args is string');
         return;
     }
     $cmd = IRC::getCodeByCommand($cmd);
     $line = ':' . $from . ' ' . $cmd;
     for ($i = 0, $s = sizeof($args); $i < $s; ++$i) {
         if ($i + 1 === $s && strpos($args[$i], " ") !== false) {
             $line .= ' :';
         } else {
             $line .= ' ';
         }
         $line .= $args[$i];
     }
     $this->writeln($line);
     if ($this->pool->protologging && $cmd !== 'PONG') {
         Daemon::log('=>=>=>=> ' . json_encode($line));
     }
 }