Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/*
4
	This file is part of ActiveLink PHP DOC Package (www.active-link.com).
5
	Copyright (c) 2002-2004 by Zurab Davitiani
6
 
7
	You can contact the author of this software via E-mail at
8
	hattrick@mailcan.com
9
 
10
	ActiveLink PHP DOC Package is free software; you can redistribute it and/or modify
11
	it under the terms of the GNU Lesser General Public License as published by
12
	the Free Software Foundation; either version 2.1 of the License, or
13
	(at your option) any later version.
14
 
15
	ActiveLink PHP DOC Package is distributed in the hope that it will be useful,
16
	but WITHOUT ANY WARRANTY; without even the implied warranty of
17
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
	GNU Lesser General Public License for more details.
19
 
20
	You should have received a copy of the GNU Lesser General Public License
21
	along with ActiveLink PHP DOC Package; if not, write to the Free Software
22
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
*/
24
 
25
import("org.active-link.doc.Method");
26
 
27
/**
28
  *	PHPClass class provides a structural definition for a class
29
  *	@class		PHPClass
30
  *	@package	org.active-link.doc
31
  *	@author		Zurab Davitiani
32
  *	@version	0.3.4
33
  *	@requires	Method
34
  *	@see		PHPClass
35
  */
36
 
37
class PHPClass {
38
 
39
	var $methods;
40
	var $properties;
41
	var $info;
42
 
43
	/**
44
	  *	Constructor, if filename is supplied parses the file into the object
45
	  *	@method		PHPClass
46
	  *	@param		optional string filename
47
	  *	@returns	none
48
	  */
49
	function PHPClass($filename = "") {
50
		$this->methods = array();
51
		$this->properties = array();
52
		$this->info = array();
53
		if($filename != "")
54
			$this->parseFromFile($filename);
55
	}
56
 
57
	/**
58
	  *	Deletes a property by name
59
	  *	@method		deleteInfo
60
	  *	@param		string name
61
	  *	@returns	true if successful, false otherwise
62
	  */
63
    function deleteInfo($name) {
64
		$success = false;
65
		if(array_key_exists($name, $this->info)) {
66
			unset($this->info[$name]);
67
			$success = true;
68
		}
69
		return $success;
70
	}
71
 
72
	/**
73
	  *	Returns a property value by name
74
	  *	@method		getInfo
75
	  *	@param		string name
76
	  *	@returns	string value if successful, false otherwise
77
	  */
78
    function getInfo($name) {
79
		if(array_key_exists($name, $this->info))
80
			return $this->info[$name];
81
		else
82
			return false;
83
	}
84
 
85
	/**
86
	  *	Parses a class from supplied filename
87
	  *	@method		parseFromFile
88
	  *	@param		string filename
89
	  *	@returns	true if successful, false otherwise
90
	  */
91
	function parseFromFile($filename) {
92
		$success = false;
93
		if(file_exists($filename) && is_readable($filename)) {
94
			$arrContents = file($filename);
95
			$parsing = false;
96
			$parsingBlocks = array();
97
			$tempBlock = array();
98
			foreach($arrContents as $line) {
99
				if(trim($line) == "/**") {
100
					$parsing = true;
101
					$blockstart = true;
102
				}
103
				elseif($parsing && trim($line) == "*/") {
104
					$parsing = false;
105
					$parsingBlocks[] = $tempBlock;
106
					$tempBlock = array();
107
				}
108
				else {
109
					if($parsing) {
110
						if($blockstart) {
111
							$tempBlock[] = $line;
112
							$blockstart = false;
113
						}
114
						else {
115
							$tempBlock[] = $line;
116
						}
117
					}
118
				}
119
			}
120
			foreach($parsingBlocks as $blockLines) {
121
				$block = array();
122
				foreach($blockLines as $line) {
123
					$str = strstr($line, "@");
124
					$str = substr($str, 1);
125
					if($str !== false) {
126
						$separatorPos = (strpos($str, " ") && strpos($str, "\t")) ? min(strpos($str, " "), strpos($str, "\t")) : (strpos($str, " ") ? strpos($str, " ") : (strpos($str, "\t") ? strpos($str, "\t") : strlen($str)));
127
						$name = trim(substr($str, 0, $separatorPos));
128
						$value = trim(substr($str, $separatorPos));
129
					}
130
					else {
131
						$name = "description";
132
						$value = trim($line);
133
					}
134
					if($name == "param" || $name == "description")
135
						$block[$name][] = $value;
136
					else
137
						$block[$name] = $value;
138
				}
139
				//print("<pre>");
140
				//print_r($block);
141
				//print("</pre>");
142
				if(array_key_exists("method", $block)) {
143
					$tempMethod = new Method($block["method"]);
144
					unset($block["method"]);
145
					if(isset($block["param"]) && is_array($block["param"])) {
146
						foreach($block["param"] as $param) {
147
							$tempMethod->setParam($param, "");
148
						}
149
					}
150
					unset($block["param"]);
151
					foreach($block as $name => $value) {
152
						$tempMethod->setInfo($name, $value);
153
					}
154
					$this->setMethod($tempMethod);
155
				}
156
				elseif(array_key_exists("class", $block)) {
157
					$this->setInfo("name", $block["class"]);
158
					unset($block["class"]);
159
					foreach($block as $name => $value) {
160
						$this->setInfo($name, $value);
161
					}
162
				}
163
			}
164
			$success = true;
165
		}
166
		return $success;
167
	}
168
 
169
	/**
170
	  *	Sets a property by name
171
	  *	@method		setInfo
172
	  *	@param		string name, string value
173
	  *	@returns	none
174
	  */
175
	function setInfo($name, $value) {
176
		$this->info[$name] = $value;
177
	}
178
 
179
	/**
180
	  *	Adds a method to the class definition
181
	  *	@method		setMethod
182
	  *	@param		object method
183
	  *	@returns	true if successful, false otherwise
184
	  */
185
	function setMethod($method) {
186
		$success = false;
187
		if(is_object($method) && get_class($method) == "method") {
188
			$this->methods[$method->getInfo("name")] = $method;
189
			$success = true;
190
		}
191
		return $success;
192
	}
193
 
194
}
195
 
196
?>