I think first that all you have to separate the "parsing" of the text
and the execution of the command itself via components, namely:

1) Create a "CommandParser" component that has function to "parse" a
command.
2) Create a "CommandExecutive" component that has a method for
implement each of the commands.

I suggest you to handle the user input in a unique action in the
controlle. For example, create a send action where all the user text
is sent:

class ChatController extends AppController {
            var $components =
Array('CommandParser','CommandExecutive');

            /*handles all text send by user*/
            function send($text) {
                  /*analize wherter the input is a command or is plain
text*/
                  if (CommandParser::isCommand($text)) {
                        //is a command redirect for command execution
                       //use the parser component to get the command
and the parameter of the command
                       $command = CommandParser::getCommand($text);
                       $parameter = CommandParser::getParameter($te
                       $this->redirect("/chat/command/$command/
$parameter");

                  }
                  else {
                       //is normal text, show
                       $this->redirect("/chat/add/$text")
                  }
             }

             //here is the rest of actions
            function add ($text) {
                 //perform logic of add text
            }

            function command ($command, $parameter) {
                 //perform logic of command
             }
}


For executing the command you can avoid the big switching statement by
using an array of callbacks indexed with the command names. All
callbacks are methods defined in the ActionExecutive component itself.
For example:

//this function may be in the controller
function proccessCommand($text,$parameter) {
       $command_list = Array (
                    'help' => "displayHelp",
                   'quit' => "quitUser",
                   /* ... */
                );

       /*verify if  it is a valid command*/
       if (empty($command_list[$text])) {
            return INVALID_COMMAND; /*this maybe a constant*/
      }

      $callback = $command_list[$text];
      /*execute the command that is a method in a command executive
component*/
      $result = CommandExecutive::$callback($parameter);
      return $result;
}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to