/**
  * Parses out all the command line to find the requested controller plus
  * any arguments which are available to both Synergy framework
  * classes and to the Controller class
  *
  * @param string $arguments line of args to be parsed (if null then taken from command line)
  *
  * @return ArgumentParser
  */
 public static function parseArguments($arguments = null)
 {
     $obj = new ArgumentParser();
     if (is_null($arguments) && isset($_SERVER['argv'])) {
         $aArgs = $_SERVER['argv'];
     } elseif (is_array($arguments)) {
         $aArgs = $arguments;
     } else {
         return $obj;
     }
     $request = null;
     $requestArgs = array();
     $phase = 1;
     $script_filename = strtolower($_SERVER['SCRIPT_FILENAME']);
     foreach ($aArgs as $val) {
         switch ($phase) {
             case 1:
                 // look for our app/console script first
                 if (strtolower($val) == $script_filename) {
                     $phase = 2;
                     continue;
                 }
                 break;
             case 2:
                 // look for any args for Synergy
                 if (substr($val, 0, 1) == '-') {
                     $requestArgs[] = $val;
                 } else {
                     $phase = 3;
                     $obj->setRequest($val);
                 }
                 break;
             case 3:
                 // look for any args for the request
                 $requestArgs[] = $val;
         }
     }
     if (is_array($requestArgs)) {
         $obj->setElements($requestArgs);
     }
     return $obj;
 }