/**
  * Creates the methodTable for a passed class.
  *
  * @static
  * @access public
  * @param $sourcePath(String) The path to the file you want to parse
  * @param $containsClass(Bool) True if the file is a class definition (optional)
  */
 function create($sourcePath, $containsClass = false)
 {
     $methodTable = array();
     if (!file_exists($sourcePath)) {
         return false;
     }
     $source = file_get_contents($sourcePath);
     $tokens = (array) token_get_all($source);
     $waitingForOpenParenthesis = false;
     $waitingForFunction = false;
     $waitingForClassName = false;
     $bufferingArgs = false;
     $argBuffer = "";
     $lastFunction = "";
     $lastFunctionComment = "";
     $lastComment = "";
     $classMethods = array();
     $realClassName = "";
     if ($containsClass) {
         $openBraces = -10000;
     } else {
         $openBraces = 1;
     }
     $waitingForEndEncapsedString = false;
     foreach ($tokens as $token) {
         if (is_string($token)) {
             if ($token == '{') {
                 $openBraces++;
             }
             if ($token == '}') {
                 if ($waitingForEndEncapsedString) {
                     $waitingForEndEncapsedString = false;
                 } else {
                     $lastComment = '';
                     $openBraces--;
                     if ($openBraces == 0) {
                         break;
                     }
                 }
             } elseif ($waitingForOpenParenthesis && $token == '(') {
                 $bufferingArgs = true;
                 $argBuffer = "";
                 $waitingForOpenParenthesis = false;
             } elseif ($bufferingArgs) {
                 if ($token != ')') {
                     $argBuffer .= $token;
                 } else {
                     if ($lastFunction != $realClassName) {
                         $classMethods[] = array("name" => $lastFunction, "comment" => $lastFunctionComment, "args" => $argBuffer);
                         $bufferingArgs = false;
                         $argBuffer = "";
                         $lastFunction = "";
                         $lastFunctionComment = "";
                     }
                 }
             }
         } else {
             // token array
             list($id, $text) = $token;
             if ($bufferingArgs) {
                 $argBuffer .= $text;
             }
             switch ($id) {
                 case T_COMMENT:
                 case T_ML_COMMENT:
                     // we've defined this
                 // we've defined this
                 case T_DOC_COMMENT:
                     // and this
                     // no action on comments
                     $lastComment = $text;
                     break;
                 case T_FUNCTION:
                     if ($openBraces >= 1) {
                         $waitingForFunction = true;
                     }
                     break;
                 case T_STRING:
                     if ($waitingForFunction) {
                         $waitingForFunction = false;
                         $waitingForOpenParenthesis = true;
                         $lastFunction = $text;
                         $lastFunctionComment = $lastComment;
                         $lastComment = "";
                     }
                     if ($waitingForClassName) {
                         $waitingForClassName = false;
                         $realClassName = $text;
                     }
                     break;
                 case T_CLASS:
                     $openBraces = 0;
                     $waitingForClassName = true;
                     break;
                 case T_CURLY_OPEN:
                 case T_DOLLAR_OPEN_CURLY_BRACES:
                     $waitingForEndEncapsedString = true;
                     break;
             }
         }
     }
     foreach ($classMethods as $key => $value) {
         $methodSignature = $value['args'];
         $methodName = $value['name'];
         $methodComment = $value['comment'];
         $description = MethodTable::getMethodDescription($methodComment) . " " . MethodTable::getMethodCommentAttribute($methodComment, "desc");
         $description = trim($description);
         $access = MethodTable::getMethodCommentAttributeFirstWord($methodComment, "access");
         $roles = MethodTable::getMethodCommentAttributeFirstWord($methodComment, "roles");
         $instance = MethodTable::getMethodCommentAttributeFirstWord($methodComment, "instance");
         $returns = MethodTable::getMethodReturnValue($methodComment);
         $pagesize = MethodTable::getMethodCommentAttributeFirstWord($methodComment, "pagesize");
         $params = MethodTable::getMethodCommentArguments($methodComment);
         //description, arguments, access, [roles, [instance, [returns, [pagesize]]]]
         $methodTable[$methodName] = array();
         //$methodTable[$methodName]["signature"] = $methodSignature; //debug purposes
         $methodTable[$methodName]["description"] = $description == "" ? "No description given." : $description;
         $methodTable[$methodName]["arguments"] = MethodTable::getMethodArguments($methodSignature, $params);
         $methodTable[$methodName]["access"] = $access == "" ? "private" : $access;
         if ($roles != "") {
             $methodTable[$methodName]["roles"] = $roles;
         }
         if ($instance != "") {
             $methodTable[$methodName]["instance"] = $instance;
         }
         if ($returns != "") {
             $methodTable[$methodName]["returns"] = $returns;
         }
         if ($pagesize != "") {
             $methodTable[$methodName]["pagesize"] = $pagesize;
         }
     }
     return $methodTable;
 }