/** * Creates the methodTable for a passed class. * * @param $className {String} The name of the service class. (may also simply be __FILE__) * @param $servicePath {String} The location of the classes (optional) */ public static function create($className, $servicePath = NULL, &$classComment){ $methodTable = array(); if(file_exists($className)){ $sourcePath = $className; $className = str_replace("\\", '/', $className); $className = substr($className, strrpos($className, '/') + 1); $className = str_replace('.php', '', $className); }else{ $className = str_replace('.php', '', $className); $fullPath = str_replace('.', '/', $className); $className = $fullPath; if(strpos($fullPath, '/') !== FALSE){ $className = substr(strrchr($fullPath, '/'), 1); } // FIX: what does the code bellow? if($servicePath == NULL){ if(isset($GLOBALS['amfphp']['classPath'])){ $servicePath = $GLOBALS['amfphp']['classPath']; }else{ $servicePath = "../services/"; } } $sourcePath = $servicePath . $fullPath . ".php"; } if(!file_exists($sourcePath)){ trigger_error("The MethodTable class could not find {" . $sourcePath . "}", E_USER_ERROR); } if(!class_exists('ReflectionClass')){ return null; } $classMethods = MethodTable::getClassMethodsReflection($sourcePath, $className, $classComment); foreach ($classMethods as $key => $value){ if($value["name"][0] == "_" || $value["name"] == "beforeFilter"){ continue; } $params = $value['args']; $methodName = $value['name']; $methodComment = $value['comment']; $methodLength = $value['lenght']; $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::getMethodCommentAttributeFirstLine($methodComment, "return"); $paramsComment = MethodTable::getMethodCommentArguments($methodComment); $methodTable[$methodName] = array(); $methodTable[$methodName]["description"] = ($description == "") ? "No description given." : $description; $details = MethodTable::getArgumentsDetails($params,$paramsComment); $default = $value["defaults"]; $arguments = array(); foreach ($params as $index => $paramName){ $argument = array(); $argument["name"] = $paramName; $argument["details"] = $details[$index]; if(array_key_exists($index, $default)){ $argument["default"] = $default[$index]; } $arguments[$index] = $argument; } $methodTable[$methodName]["arguments"] = $arguments; //$methodTable[$methodName]["access"] = ($access == "") ? "private" : $access; // <- why is this needed? $methodTable[$methodName]["lenght"] = $methodLength; if($roles != "") $methodTable[$methodName]["roles"] = $roles; if($instance != "") $methodTable[$methodName]["instance"] = $instance; if($returns != "") $methodTable[$methodName]["return"] = $returns; } //$classComment = trim(str_replace("\r\n", "\n", MethodTable::getMethodDescription($classComment))); return $methodTable; }