Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Common information needed by all portions of the application
4
 *
5
 * phpDocumentor :: automatic documentation generator
6
 *
7
 * PHP versions 4 and 5
8
 *
9
 * Copyright (c) 2001-2008 Gregory Beaver
10
 *
11
 * LICENSE:
12
 *
13
 * This library is free software; you can redistribute it
14
 * and/or modify it under the terms of the GNU Lesser General
15
 * Public License as published by the Free Software Foundation;
16
 * either version 2.1 of the License, or (at your option) any
17
 * later version.
18
 *
19
 * This library is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22
 * Lesser General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Lesser General Public
25
 * License along with this library; if not, write to the Free Software
26
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
 *
28
 * @category  ToolsAndUtilities
29
 * @package   phpDocumentor
30
 * @author    Greg Beaver <cellog@php.net>
31
 * @copyright 2001-2008 Gregory Beaver
32
 * @license   http://www.opensource.org/licenses/lgpl-license.php LGPL
33
 * @version   CVS: $Id: common.inc.php 288074 2009-09-05 02:16:26Z ashnazg $
34
 * @filesource
35
 * @link      http://www.phpdoc.org
36
 * @link      http://pear.php.net/PhpDocumentor
37
 * @see       parserDocBlock, parserInclude, parserPage, parserClass
38
 * @see       parserDefine, parserFunction, parserMethod, parserVar
39
 * @since     1.0rc1
40
 * @todo      CS cleanup - change package to PhpDocumentor
41
 * @todo      CS cleanup - rename constant to TOKENIZER_EXT
42
 */
43
 
44
/* phpDocumentor version */
45
if ('/usr/share/php' != '@'.'PEAR-DIR@') {
46
    /** @ignore */
47
    define("PHPDOCUMENTOR_VER", "1.4.3");
48
} else {
49
    define("PHPDOCUMENTOR_VER", "1.4.3");
50
}
51
 
52
/* phpDocumentor URL */
53
define("PHPDOCUMENTOR_WEBSITE", "http://www.phpdoc.org");
54
 
55
// set the correct path delimiter
56
define('SMART_PATH_DELIMITER', DIRECTORY_SEPARATOR);
57
 
58
define('tokenizer_ext', extension_loaded('tokenizer')
59
    && version_compare(phpversion(), "4.3.0", ">="));
60
 
61
// we just replace all the \ with / so that we can just operate on /
62
define('PATH_DELIMITER', '/'); // set the correct path delimiter
63
 
64
define('PHPDOCUMENTOR_WINDOWS', substr(PHP_OS, 0, 3) == 'WIN');
65
 
66
define('_IN_PHP5',
67
    phpversion() == '5.0.0RC1-dev' || phpversion() == '5.0.0RC2-dev'
68
    || version_compare(phpversion(), '5.0.0', 'ge'));
69
 
70
// determine which "clone" class to set, based on PHP major version
71
$cloneClassDir  = 'PhpDocumentor' . DIRECTORY_SEPARATOR . 'phpDocumentor';
72
$cloneClassFile = 'clone.inc.php';
73
if ('1.4.3' == '@'.'VER@') {
74
    // we're _not_ in a PEAR installation
75
    $cloneClassDir = dirname(__FILE__);
76
}
77
if (_IN_PHP5) {
78
    // we _are_ in PHP5
79
    $cloneClassFile = 'clone5.inc.php';
80
}
81
require_once $cloneClassDir . DIRECTORY_SEPARATOR . $cloneClassFile;
82
 
83
// make arg arrays available
84
if (isset($_SERVER['argv'])) {
85
    $argv = $_SERVER['argv'];
86
    $argc = $_SERVER['argc'];
87
}
88
 
89
/**
90
 * used in phpdoc.php and new_phpdoc.php
91
 *
92
 * @param string $directory a directory string
93
 *
94
 * @return array an array of directory contents
95
 * @todo CS cleanup - rename function to PhpDocumentor_ConfigFileList
96
 */
97
function phpDocumentor_ConfigFileList($directory)
98
{
99
    $ret = array();
100
    if (@is_dir($directory)) {
101
        $ret = array();
102
 
103
        // thanks to Jason E Sweat (jsweat@users.sourceforge.net) for fix
104
        $d = @dir($directory);
105
 
106
        while ($d && $entry=$d->read()) {
107
            $getentry = false;
108
            if (strcmp($entry, ".") != 0 && strcmp($entry, "..") != 0) {
109
                if (substr($entry, 0, 1) != ".") $getentry = true;
110
            }
111
            if ($getentry == true) {
112
                if (strpos($entry, '.ini'))
113
                if (is_file($directory . PATH_DELIMITER . $entry)) {
114
                    $ret[] = str_replace('.ini', '', $entry);
115
                }
116
            }
117
        }
118
        if ($d) $d->close();
119
    } else {
120
    }
121
    return $ret;
122
}
123
 
124
 
125
/**
126
 * Parse an .ini file
127
 *
128
 * Works like {@link parse_ini_file}, except it will take a section like:
129
 *
130
 * <pre>
131
 * [MYVAR]
132
 * value1
133
 * value2
134
 * value3
135
 * </pre>
136
 *
137
 * and return an associative array(MYVAR => array(value1, value2, value3))
138
 *
139
 * @param string $filename         full path to the ini file
140
 * @param bool   $process_sections add an associative index
141
 *                                 for each section [in brackets]
142
 *
143
 * @return array
144
 * @todo CS cleanup - rename function to PhpDocumentor_parse_ini_file
145
 */
146
function phpDocumentor_parse_ini_file($filename, $process_sections = false)
147
{
148
    $ini_array = array();
149
    $sec_name  = "";
150
    $lines     = @file($filename);
151
    if (!$lines) return $lines;
152
    foreach ($lines as $line) {
153
        // code by Greg Beaver, ignore comments
154
        if ($line[0] == ';') continue;
155
        $line = trim($line);
156
 
157
        if ($line == "") {
158
            continue;
159
        }
160
        if ($line[0] == "[" && $line[strlen($line) - 1] == "]") {
161
            $sec_name = substr($line, 1, strlen($line) - 2);
162
        } else {
163
            if (strpos($line, "=")) {
164
                $pos      = strpos($line, "=");
165
                $property = trim(substr($line, 0, $pos));
166
                // code by Greg Beaver
167
                if (substr($property, 0, 1) == '"' && substr($property, -1) == '"') {
168
                    $property =
169
                        stripcslashes(substr($property, 1, count($property) - 2));
170
                }
171
                $value = trim(substr($line, $pos + 1));
172
                if ($value == 'false') $value = false;
173
                if ($value == 'true') $value = true;
174
                if (substr($value, 0, 1) == '"' && substr($value, -1) == '"') {
175
                    $value = stripcslashes(substr($value, 1, count($value) - 2));
176
                }
177
                // done additions
178
 
179
                if ($process_sections) {
180
                    if ($sec_name != '')
181
                    $ini_array[$sec_name][$property] = $value;
182
                    else
183
                    $ini_array[$property] = $value;
184
                } else {
185
                    $ini_array[$property] = $value;
186
                }
187
            } else {
188
                // code by Greg Beaver
189
                if (trim($line[0]) == ';') continue;
190
                if ($process_sections) {
191
                    $ini_array[$sec_name][] = trim($line);
192
                }
193
                // done additions
194
            }
195
        }
196
    }
197
    return $ini_array;
198
}
199
 
200
 
201
/**
202
 * construct an "array_key_exists()" method
203
 * if the runtime PHP version doesn't have one
204
 *
205
 * @todo CS Cleanup - can't avoid "prefixed by package" error
206
 * @todo depend on PHP_Compat for this?
207
 */
208
if (!function_exists('array_key_exists')) {
209
    /**
210
     * Determines if a given key exists in a given array
211
     *
212
     * @param mixed $key    key to search for
213
     * @param array $search the array of keys to search
214
     *
215
     * @return bool whether or not the key was found
216
     * @ignore
217
     */
218
    function array_key_exists($key, $search)
219
    {
220
        foreach ($search as $keys => $nul) {
221
            if ($key == $keys) return true;
222
        }
223
        return false;
224
    }
225
}
226
 
227
/**
228
 * construct an "is_a()" method
229
 * if the runtime PHP version doesn't have one
230
 *
231
 * @todo CS Cleanup - can't avoid "prefixed by package" error
232
 * @todo depend on PHP_Compat for this?
233
 */
234
if (!function_exists('is_a')) {
235
    /**
236
     * Determines if one item "is" an object of the other item
237
     *
238
     * @param string $classname  the class in question
239
     * @param string $classquery the "is it a" class
240
     *
241
     * @return bool whether or not the class "is" one
242
     * @ignore
243
     */
244
    function is_a($classname, $classquery)
245
    {
246
        $father = get_parent_class($classname);
247
        if (strtolower($father) == strtolower($classquery)) {
248
            return true;
249
        } elseif (!empty($father)) {
250
            return is_a($father, $classquery);
251
        } else {
252
            return false;
253
        }
254
    }
255
}
256
 
257
 
258
/**
259
 * Debugging output
260
 *
261
 * @param string $s the "debug message" string to echo out
262
 *
263
 * @return void
264
 * @todo CS Cleanup - can't avoid "prefixed by package" error
265
 */
266
function debug($s)
267
{
268
    echo "$s\n";
269
}
270
 
271
/**
272
 * Returns a formatted var_dump for debugging purposes.
273
 *
274
 * @param string $s string to display
275
 * @param mixed  $v unlimited number of variables to display with var_dump()
276
 *
277
 * @return void
278
 */
279
function fancy_debug($s,$v)
280
{
281
    if (isset($GLOBALS['dont_debug']) && $GLOBALS['dont_debug']) return;
282
    debug($s."\n\n</pre><blockquote><pre>");
283
    var_dump($v);
284
    if (func_num_args()>2) {
285
        for ($i=2;$i<func_num_args();$i++) {
286
            $a = func_get_arg($i);
287
            // debug(" ");
288
            var_dump($a);
289
        }
290
    }
291
    debug("</pre></blockquote><pre>\n\n");
292
}
293
 
294
/**
295
 * Returns a lower-cased version of get_class for PHP 5
296
 *
297
 * get_class() returns case as declared in the file in PHP 5
298
 *
299
 * @param object $object the object to get the classname for
300
 *
301
 * @return string the class name of the given object
302
 * @todo CS cleanup - rename function to PhpDocumentor_get_class
303
 */
304
function phpDocumentor_get_class($object)
305
{
306
    if (is_object($object)) {
307
        return strtolower(get_class($object));
308
    }
309
    return false;
310
}
311
 
312
?>