added channel Burst
[PHP-P10.git] / Uplink / P10Formatter.class.php
1 <?php
2 /********************************* PHP-P10 ******************************
3  *    P10 uplink class by pk910   (c)2011 pk910                         *
4  ************************************************************************
5  *                          Version 2 (OOP)                             *
6  *                                                                      *
7  * PHP-P10 is free software; you can redistribute it and/or modify      *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or    *
10  * (at your option) any later version.                                  *
11  *                                                                      *
12  * This program is distributed in the hope that it will be useful,      *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
15  * GNU General Public License for more details.                         *
16  *                                                                      *
17  * You should have received a copy of the GNU General Public License    *
18  * along with PHP-P10; if not, write to the Free Software Foundation,   *
19  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.       *
20  *                                                                      *
21  ************************************************************************
22  * 
23  *  Uplink/P10Formatter.class.php
24  *
25  * This file contains the command formatter.
26  *
27  ************************************************************************
28  * accessable methods:
29  *
30  * static String formatCMD(String $numeric, String $command, String[] $args) 
31  *     builds the command with the given arguments
32  *
33  */
34
35 class P10Formatter {
36         
37         private static $commands = array(
38                 "PASS"   => "PASS :%s",
39                 "SERVER" => "SERVER %s 1 %s %s J10 %s]]] +s6 :%s",
40                 "ERROR"  => "ERROR :%s",
41                 "Z"      => "{num} Z %s",
42                 "N"      => "{num} N %s 1 %s %s %s %s %s %s :%s",
43                 "EB"     => "{num} EB",
44                 "EA"     => "{num} EA",
45                 "B"      => "{num} B %s %s %s",
46                 null     => null
47         );
48         
49         public static function formatCMD($numeric, $command, $args) {
50                 if(array_key_exists($command, self::$commands)) {
51                         $command = self::$commands[$command];
52                         $command = vsprintf($command, $args);
53                 } else {
54                         $command = vsprintf($command, $args);
55                 }
56                 return str_replace("{num}", $numeric, $command);
57         }
58 }
59
60 ?>