/**
  * Creates the methodTable for a passed class.
  *
  * @static
  * @access public
  * @param $className(String) The name of the service class.
  *        May also simply be __FILE__
  * @param $servicePath(String) The location of the classes (optional)
  */
 function create($className, $servicePath = NULL, &$classComment)
 {
     $methodTable = array();
     if (file_exists(Inflector::underscore($className))) {
         //The new __FILE__ way of doing things was used
         // Files are underscored in cakePHP
         $sourcePath = Inflector::underscore($className);
         $className = str_replace("\\", '/', $className);
         $className = substr($className, strrpos($className, '/') + 1);
         // Class names are CamelCased in cakePHP
         $className = Inflector::camelize(str_replace('.php', '', $className));
     } else {
         $className = str_replace('.php', '', $className);
         $fullPath = Inflector::underscore(str_replace('.', '/', $className));
         $className = Inflector::camelize($fullPath);
         if (strpos($fullPath, '/') !== FALSE) {
             // Class names are CamelCased in cakePHP
             $className = Inflector::camelize(substr(strrchr($fullPath, '/'), 1));
         }
         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')) {
         //PHP5
         $classMethods = MethodTable::getClassMethodsReflection($sourcePath, $className, $classComment);
     } else {
         //PHP4
         $classMethods = MethodTable::getClassMethodsTokenizer($sourcePath, $className, $classComment);
     }
     foreach ($classMethods as $key => $value) {
         if ($value['name'][0] == '_' || $value['name'] == 'beforeFilter') {
             continue;
         }
         if (defined("METHOD_PREFIX")) {
             if (METHOD_PREFIX != substr($value['name'], 0, strlen(METHOD_PREFIX))) {
                 continue;
             }
         }
         $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::getMethodCommentAttributeFirstLine($methodComment, "returns");
         $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;
         }
     }
     $classComment = trim(str_replace("\r\n", "\n", MethodTable::getMethodDescription($classComment)));
     return $methodTable;
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
	/**
	 * 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;
	}
Esempio n. 4
0
 /**
  * Creates the methodTable for a passed class.
  *
  * @static
  * @access public
  * @param $className(String) The name of the service class.
  *        May also simply be __FILE__
  * @param $servicePath(String) The location of the classes (optional)
  */
 function create($className, $servicePath = NULL, &$classComment)
 {
     $methodTable = array();
     if (file_exists($className)) {
         //The new __FILE__ way of doing things was used
         $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);
         }
         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);
     }
     //convert classname to cake classname
     $className = Inflector::camelize($className);
     if (class_exists('ReflectionClass')) {
         //PHP5
         $classMethods = MethodTable::getClassMethodsReflection($sourcePath, $className, $classComment);
     } else {
         //PHP4
         $classMethods = MethodTable::getClassMethodsTokenizer($sourcePath, $className, $classComment);
     }
     foreach ($classMethods as $key => $value) {
         if ($value['name'][0] == '_' || in_array($value['name'], array('beforeFilter', 'afterFilter', 'beforeRender', 'afterRender', 'Object', 'cakeError', 'cleanUpFields', 'constructClasses', 'flash', 'flashOut', 'generateFieldNames', 'log', 'postConditions', 'redirect', 'referer', 'render', 'requestAction', 'set', 'setAction', 'toString', 'validate', 'validateErrors', 'view'))) {
             continue;
         }
         $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::getMethodCommentAttributeFirstLine($methodComment, "returns");
         $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;
         }
     }
     $classComment = trim(str_replace("\r\n", "\n", MethodTable::getMethodDescription($classComment)));
     return $methodTable;
 }
Esempio n. 5
0
 /**
  * Creates the methodTable for a passed class.
  *
  * @static
  * @access public
  * @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)) {
         //The new __FILE__ way of doing things was used
         $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);
         }
         if ($servicePath == NULL) {
             $servicePath = "../services/";
         }
         $sourcePath = $servicePath . $fullPath . ".php";
     }
     if (!file_exists($sourcePath)) {
         trigger_error("The MethodTable class could not find {" . $sourcePath . "}", E_USER_ERROR);
     }
     //PHP5
     $classMethods = MethodTable::getClassMethodsReflection($sourcePath, $className, $classComment);
     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::getMethodCommentAttributeFirstLine($methodComment, "returns");
         $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;
         }
     }
     $classComment = trim(str_replace("\r\n", "\n", MethodTable::getMethodDescription($classComment)));
     return $methodTable;
 }
Esempio n. 6
0
 /**
  * Creates the methodTable for a passed class.
  *
  * @static
  * @access public
  * @param $className(String) The name of the service class.
  *        May also simply be __FILE__
  * @param $servicePath(String) The location of the classes (optional)
  */
 function create($className, $servicePath = NULL)
 {
     $methodTable = array();
     if (file_exists($className)) {
         //The new __FILE__ way of doing things was used
         $sourcePath = $className;
     } else {
         $className = str_replace('.php', '', $className);
         $fullPath = str_replace('.', '/', $className);
         $className = $fullPath;
         if (strpos($fullPath, '/') !== FALSE) {
             $className = substr(strrchr($fullPath, '/'), 1);
         }
         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);
     }
     $source = file_get_contents($sourcePath);
     $tokens = token_get_all($source);
     $waitingForOpenParenthesis = false;
     $waitingForFunction = false;
     $waitingForClassName = false;
     $bufferingArgs = false;
     $argBuffer = "";
     $lastFunction = "";
     $lastFunctionComment = "";
     $lastComment = "";
     $classMethods = array();
     $realClassName = "";
     $openBraces = -10000;
     $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::getMethodCommentAttributeFirstLine($methodComment, "returns");
         $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;
 }