3 * Common information needed by all portions of the application
\r
5 * phpDocumentor :: automatic documentation generator
\r
7 * PHP versions 4 and 5
\r
9 * Copyright (c) 2001-2007 Gregory Beaver
\r
13 * This library is free software; you can redistribute it
\r
14 * and/or modify it under the terms of the GNU Lesser General
\r
15 * Public License as published by the Free Software Foundation;
\r
16 * either version 2.1 of the License, or (at your option) any
\r
19 * This library is distributed in the hope that it will be useful,
\r
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
22 * Lesser General Public License for more details.
\r
24 * You should have received a copy of the GNU Lesser General Public
\r
25 * License along with this library; if not, write to the Free Software
\r
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
28 * @category ToolsAndUtilities
\r
29 * @package phpDocumentor
\r
30 * @author Greg Beaver <cellog@php.net>
\r
31 * @copyright 2001-2007 Gregory Beaver
\r
32 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
\r
33 * @version CVS: $Id: common.inc.php,v 1.13 2007/10/06 22:57:15 ashnazg Exp $
\r
35 * @link http://www.phpdoc.org
\r
36 * @link http://pear.php.net/PhpDocumentor
\r
37 * @see parserDocBlock, parserInclude, parserPage, parserClass
\r
38 * @see parserDefine, parserFunction, parserMethod, parserVar
\r
40 * @todo CS cleanup - change package to PhpDocumentor
\r
41 * @todo CS cleanup - rename constant to TOKENIZER_EXT
\r
44 /* phpDocumentor version */
\r
45 if ('@PEAR-DIR@' != '@'.'PEAR-DIR@') {
\r
47 define("PHPDOCUMENTOR_VER", "@VER@");
\r
49 define("PHPDOCUMENTOR_VER", "1.4.0");
\r
52 /* phpDocumentor URL */
\r
53 define("PHPDOCUMENTOR_WEBSITE", "http://www.phpdoc.org");
\r
55 // set the correct path delimiter
\r
56 define('SMART_PATH_DELIMITER', DIRECTORY_SEPARATOR);
\r
58 define('tokenizer_ext', extension_loaded('tokenizer')
\r
59 && version_compare(phpversion(), "4.3.0", ">="));
\r
61 // we just replace all the \ with / so that we can just operate on /
\r
62 define('PATH_DELIMITER', '/'); // set the correct path delimiter
\r
64 define('PHPDOCUMENTOR_WINDOWS', substr(PHP_OS, 0, 3) == 'WIN');
\r
67 phpversion() == '5.0.0RC1-dev' || phpversion() == '5.0.0RC2-dev'
\r
68 || version_compare(phpversion(), '5.0.0', 'ge'));
\r
70 // determine which "clone" class to set, based on PHP major version
\r
71 $cloneClassDir = 'PhpDocumentor' . DIRECTORY_SEPARATOR . 'phpDocumentor';
\r
72 $cloneClassFile = 'clone.inc.php';
\r
73 if ('@VER@' == '@'.'VER@') {
\r
74 // we're _not_ in a PEAR installation
\r
75 $cloneClassDir = dirname(__FILE__);
\r
79 $cloneClassFile = 'clone5.inc.php';
\r
81 require_once $cloneClassDir . DIRECTORY_SEPARATOR . $cloneClassFile;
\r
83 // make arg arrays available
\r
84 if (isset($_SERVER['argv'])) {
\r
85 $argv = $_SERVER['argv'];
\r
86 $argc = $_SERVER['argc'];
\r
90 * used in phpdoc.php and new_phpdoc.php
\r
92 * @param string $directory a directory string
\r
94 * @return array an array of directory contents
\r
95 * @todo CS cleanup - rename function to PhpDocumentor_ConfigFileList
\r
97 function phpDocumentor_ConfigFileList($directory)
\r
100 if (@is_dir($directory)) {
\r
103 // thanks to Jason E Sweat (jsweat@users.sourceforge.net) for fix
\r
104 $d = @dir($directory);
\r
106 while ($d && $entry=$d->read()) {
\r
108 if (strcmp($entry, ".") != 0 && strcmp($entry, "..") != 0) {
\r
109 if (substr($entry, 0, 1) != ".") $getentry = true;
\r
111 if ($getentry == true) {
\r
112 if (strpos($entry, '.ini'))
\r
113 if (is_file($directory . PATH_DELIMITER . $entry)) {
\r
114 $ret[] = str_replace('.ini', '', $entry);
\r
118 if ($d) $d->close();
\r
126 * Parse an .ini file
\r
128 * Works like {@link parse_ini_file}, except it will take a section like:
\r
137 * and return an associative array(MYVAR => array(value1, value2, value3))
\r
139 * @param string $filename full path to the ini file
\r
140 * @param bool $process_sections add an associative index
\r
141 * for each section [in brackets]
\r
144 * @todo CS cleanup - rename function to PhpDocumentor_parse_ini_file
\r
146 function phpDocumentor_parse_ini_file($filename, $process_sections = false)
\r
148 $ini_array = array();
\r
150 $lines = @file($filename);
\r
151 if (!$lines) return $lines;
\r
152 foreach ($lines as $line) {
\r
153 // code by Greg Beaver, ignore comments
\r
154 if ($line[0] == ';') continue;
\r
155 $line = trim($line);
\r
160 if ($line[0] == "[" && $line[strlen($line) - 1] == "]") {
\r
161 $sec_name = substr($line, 1, strlen($line) - 2);
\r
163 if (strpos($line, "=")) {
\r
164 $pos = strpos($line, "=");
\r
165 $property = trim(substr($line, 0, $pos));
\r
166 // code by Greg Beaver
\r
167 if (substr($property, 0, 1) == '"' && substr($property, -1) == '"') {
\r
169 stripcslashes(substr($property, 1, count($property) - 2));
\r
171 $value = trim(substr($line, $pos + 1));
\r
172 if ($value == 'false') $value = false;
\r
173 if ($value == 'true') $value = true;
\r
174 if (substr($value, 0, 1) == '"' && substr($value, -1) == '"') {
\r
175 $value = stripcslashes(substr($value, 1, count($value) - 2));
\r
179 if ($process_sections) {
\r
180 if ($sec_name != '')
\r
181 $ini_array[$sec_name][$property] = $value;
\r
183 $ini_array[$property] = $value;
\r
185 $ini_array[$property] = $value;
\r
188 // code by Greg Beaver
\r
189 if (trim($line[0]) == ';') continue;
\r
190 if ($process_sections) {
\r
191 $ini_array[$sec_name][] = trim($line);
\r
202 * construct an "array_key_exists()" method
\r
203 * if the runtime PHP version doesn't have one
\r
205 * @todo CS Cleanup - can't avoid "prefixed by package" error
\r
206 * @todo depend on PHP_Compat for this?
\r
208 if (!function_exists('array_key_exists')) {
\r
210 * Determines if a given key exists in a given array
\r
212 * @param mixed $key key to search for
\r
213 * @param array $search the array of keys to search
\r
215 * @return bool whether or not the key was found
\r
218 function array_key_exists($key, $search)
\r
220 foreach ($search as $keys => $nul) {
\r
221 if ($key == $keys) return true;
\r
228 * construct an "is_a()" method
\r
229 * if the runtime PHP version doesn't have one
\r
231 * @todo CS Cleanup - can't avoid "prefixed by package" error
\r
232 * @todo depend on PHP_Compat for this?
\r
234 if (!function_exists('is_a')) {
\r
236 * Determines if one item "is" an object of the other item
\r
238 * @param string $classname the class in question
\r
239 * @param string $classquery the "is it a" class
\r
241 * @return bool whether or not the class "is" one
\r
244 function is_a($classname, $classquery)
\r
246 $father = get_parent_class($classname);
\r
247 if (strtolower($father) == strtolower($classquery)) {
\r
249 } elseif (!empty($father)) {
\r
250 return is_a($father, $classquery);
\r
261 * @param string $s the "debug message" string to echo out
\r
264 * @todo CS Cleanup - can't avoid "prefixed by package" error
\r
267 * Taken out since ATutor has a function called debug as well.
\r
268 * Redeclaring function error otherwise.
\r
276 * Returns a formatted var_dump for debugging purposes.
\r
278 * @param string $s string to display
\r
279 * @param mixed $v unlimited number of variables to display with var_dump()
\r
283 function fancy_debug($s,$v)
\r
285 if (isset($GLOBALS['dont_debug']) && $GLOBALS['dont_debug']) return;
\r
286 debug($s."\n\n</pre><blockquote><pre>");
\r
288 if (func_num_args()>2) {
\r
289 for ($i=2;$i<func_num_args();$i++) {
\r
290 $a = func_get_arg($i);
\r
295 debug("</pre></blockquote><pre>\n\n");
\r
299 * Returns a lower-cased version of get_class for PHP 5
\r
301 * get_class() returns case as declared in the file in PHP 5
\r
303 * @param object $object the object to get the classname for
\r
305 * @return string the class name of the given object
\r
306 * @todo CS cleanup - rename function to PhpDocumentor_get_class
\r
308 function phpDocumentor_get_class($object)
\r
310 return strtolower(get_class($object));
\r