added Line parser and recv_pass, recv_error; added send command with a P10Formatter
[PHP-P10.git] / Uplink / P10Formatter.class.php
diff --git a/Uplink/P10Formatter.class.php b/Uplink/P10Formatter.class.php
new file mode 100644 (file)
index 0000000..d280bf2
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+/********************************* PHP-P10 ******************************
+ *    P10 uplink class by pk910   (c)2011 pk910                         *
+ ************************************************************************
+ *                          Version 2 (OOP)                             *
+ *                                                                      *
+ * PHP-P10 is free software; you can redistribute it and/or modify      *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or    *
+ * (at your option) any later version.                                  *
+ *                                                                      *
+ * This program is distributed in the hope that it will be useful,      *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
+ * GNU General Public License for more details.                         *
+ *                                                                      *
+ * You should have received a copy of the GNU General Public License    *
+ * along with PHP-P10; if not, write to the Free Software Foundation,   *
+ * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.       *
+ *                                                                      *
+ ************************************************************************
+ * 
+ *  Uplink/P10Formatter.class.php
+ *
+ * This file contains the command formatter.
+ *
+ ************************************************************************
+ * accessable methods:
+ *
+ * static String formatCMD(String $numeric, String $command, String[] $args) 
+ *     builds the command with the given arguments
+ *
+ */
+
+class P10Formatter {
+       
+       private static $commands = array(
+               "PASS"   => "PASS :%s",
+               "SERVER" => "SERVER %s 1 %s %s J10 %s]]] +s :%s",
+               "ERROR"  => "ERROR :%s"
+       );
+       
+       public static function formatCMD($numeric, $command, $args) {
+               if(array_key_exists($command, self::$commands)) {
+                       $command = self::$commands[$command];
+                       $command = vsprintf($command, $args);
+               } else {
+                       $command = vsprintf($command, $args);
+               }
+               return str_replace("{num}", $numeric, $command);
+       }
+}
+
+?>
\ No newline at end of file