3 * File and input handling routines
\r
5 * This class parses command-line options, and works with files to
\r
6 * generate lists of files to parse based on the ignore/include options
\r
8 * phpDocumentor :: automatic documentation generator
\r
10 * PHP versions 4 and 5
\r
12 * Copyright (c) 2000-2006 Joshua Eichorn, Gregory Beaver
\r
16 * This library is free software; you can redistribute it
\r
17 * and/or modify it under the terms of the GNU Lesser General
\r
18 * Public License as published by the Free Software Foundation;
\r
19 * either version 2.1 of the License, or (at your option) any
\r
22 * This library is distributed in the hope that it will be useful,
\r
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
25 * Lesser General Public License for more details.
\r
27 * You should have received a copy of the GNU Lesser General Public
\r
28 * License along with this library; if not, write to the Free Software
\r
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
31 * @package phpDocumentor
\r
32 * @author Joshua Eichorn <jeichorn@phpdoc.org>
\r
33 * @author Gregory Beaver <cellog@php.net>
\r
34 * @copyright 2000-2006 Joshua Eichorn, Gregory Beaver
\r
35 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
\r
36 * @version CVS: $Id: Io.inc,v 1.18 2007/12/08 01:31:50 ashnazg Exp $
\r
38 * @link http://www.phpdoc.org
\r
39 * @link http://pear.php.net/PhpDocumentor
\r
43 * Class to handle file and user io opperations
\r
45 * @author Joshua Eichorn <jeichorn@phpdoc.org>
\r
46 * @author Gregory Beaver <cellog@php.net>
\r
47 * @version $Id: Io.inc,v 1.18 2007/12/08 01:31:50 ashnazg Exp $
\r
48 * @package phpDocumentor
\r
54 * Holds all the options that are avaible to the cmd line interface
\r
55 * and to the different web interfaces
\r
59 * Format: array(array(regexp-ready string to search for whole path,
\r
60 * regexp-ready string to search for basename of ignore strings),...)
\r
65 * A specific array of values that boolean-based arguments can understand,
\r
66 * aided by the {@link decideOnOrOff()} helper method.
\r
68 * Use lowercase letters always, to simplify string comparisons
\r
71 var $valid_booleans = array
\r
73 '', ' ', 'on', 'y', 'yes', 'true', '1',
\r
74 'off', 'n', 'no', 'false', '0'
\r
79 * creates an array $this->phpDocOptions and sets program options in it.
\r
80 * Array is in the format of:
\r
82 * [filename][tag][] = "f";
\r
83 * [filename][tag][] = "-file";
\r
84 * [filename][desc] "name of file to parse"
\r
89 $this->phpDocOptions['filename']['tag'] = array( "-f", "--filename");
\r
90 $this->phpDocOptions['filename']['desc'] = "name of file(s) to parse ',' file1,file2. Can contain complete path and * ? wildcards";
\r
91 $this->phpDocOptions['filename']['type'] = "path";
\r
93 $this->phpDocOptions['directory']['tag'] = array( "-d", "--directory");
\r
94 $this->phpDocOptions['directory']['desc'] = "name of a directory(s) to parse directory1,directory2";
\r
95 $this->phpDocOptions['directory']['type'] = "path";
\r
97 $this->phpDocOptions['examplesdir']['tag'] = array( "-ed", "--examplesdir");
\r
98 $this->phpDocOptions['examplesdir']['desc'] = "full path of the directory to look for example files from @example tags";
\r
99 $this->phpDocOptions['examplesdir']['type'] = "path";
\r
101 $this->phpDocOptions['templatebase']['tag'] = array( "-tb", "--templatebase");
\r
102 $this->phpDocOptions['templatebase']['desc'] = "base location of all templates for this parse.";
\r
103 $this->phpDocOptions['templatebase']['type'] = "path";
\r
105 $this->phpDocOptions['target']['tag'] = array("-t", "--target");
\r
106 $this->phpDocOptions['target']['desc'] = "path where to save the generated files";
\r
107 $this->phpDocOptions['target']['type'] = "path";
\r
109 $this->phpDocOptions['ignore']['tag'] = array("-i", "--ignore");
\r
110 $this->phpDocOptions['ignore']['desc'] = "file(s) that will be ignored, multiple separated by ','. Wildcards * and ? are ok";
\r
111 $this->phpDocOptions['ignore']['type'] = "path";
\r
113 $this->phpDocOptions['ignoresymlinks']['tag'] = array("-is", "--ignoresymlinks");
\r
114 $this->phpDocOptions['ignoresymlinks']['desc'] = "ignore symlinks to other files or directories, default is off";
\r
115 $this->phpDocOptions['ignoresymlinks']['type'] = "set";
\r
116 $this->phpDocOptions['ignoresymlinks']['validvalues'] = $this->valid_booleans;
\r
118 $this->phpDocOptions['ignoretags']['tag'] = array("-it", "--ignore-tags");
\r
119 $this->phpDocOptions['ignoretags']['desc'] = "tags to ignore for this parse. @package, @subpackage, @access and @ignore may not be ignored.";
\r
120 $this->phpDocOptions['ignoretags']['type'] = "value";
\r
122 $this->phpDocOptions['hidden']['tag'] = array("-dh", "--hidden");
\r
123 $this->phpDocOptions['hidden']['desc'] = "set equal to on (-dh on) to descend into hidden directories (directories starting with '.'), default is off";
\r
124 $this->phpDocOptions['hidden']['type'] = "set";
\r
125 $this->phpDocOptions['hidden']['validvalues'] = $this->valid_booleans;
\r
127 $this->phpDocOptions['quiet']['tag'] = array("-q", "--quiet");
\r
128 $this->phpDocOptions['quiet']['desc'] = "do not display parsing/conversion messages. Useful for cron jobs on/off default off";
\r
129 $this->phpDocOptions['quiet']['type'] = "set";
\r
130 $this->phpDocOptions['quiet']['validvalues'] = $this->valid_booleans;
\r
132 $this->phpDocOptions['undocumentedelements']['tag'] = array("-ue", "--undocumentedelements");
\r
133 $this->phpDocOptions['undocumentedelements']['desc'] = "Control whether or not warnings will be shown for undocumented elements. Useful for identifying classes and methods that haven't yet been documented on/off default off";
\r
134 $this->phpDocOptions['undocumentedelements']['type'] = "set";
\r
135 $this->phpDocOptions['undocumentedelements']['validvalues'] = $this->valid_booleans;
\r
137 $this->phpDocOptions['title']['tag'] = array("-ti","--title");
\r
138 $this->phpDocOptions['title']['desc'] = "title of generated documentation, default is 'Generated Documentation'";
\r
139 $this->phpDocOptions['title']['type'] = "value";
\r
141 $this->phpDocOptions['help']['tag'] = array("-h", "--help");
\r
142 $this->phpDocOptions['help']['desc'] = " show this help message";
\r
144 $this->phpDocOptions['useconfig']['tag'] = array("-c","--useconfig");
\r
145 $this->phpDocOptions['useconfig']['desc'] = "Use a Config file in the users/ subdirectory for all command-line options";
\r
146 $this->phpDocOptions['useconfig']['type'] = "value";
\r
148 $this->phpDocOptions['parseprivate']['tag'] = array("-pp","--parseprivate");
\r
149 $this->phpDocOptions['parseprivate']['desc'] = "parse @internal and elements marked private with @access. Use on/off, default off";
\r
150 $this->phpDocOptions['parseprivate']['type'] = "set";
\r
151 $this->phpDocOptions['parseprivate']['validvalues'] = array('on', 'off');
\r
153 $this->phpDocOptions['packageoutput']['tag'] = array("-po","--packageoutput");
\r
154 $this->phpDocOptions['packageoutput']['desc'] = "output documentation only for selected packages. Use a comma-delimited list";
\r
155 $this->phpDocOptions['packageoutput']['type'] = "value";
\r
157 $this->phpDocOptions['defaultpackagename']['tag'] = array("-dn","--defaultpackagename");
\r
158 $this->phpDocOptions['defaultpackagename']['desc'] = "name to use for the default package. If not specified, uses 'default'";
\r
159 $this->phpDocOptions['defaultpackagename']['type'] = "value";
\r
161 $this->phpDocOptions['defaultcategoryname']['tag'] = array("-dc","--defaultcategoryname");
\r
162 $this->phpDocOptions['defaultcategoryname']['desc'] = "name to use for the default category. If not specified, uses 'default'";
\r
163 $this->phpDocOptions['defaultcategoryname']['type'] = "value";
\r
165 $this->phpDocOptions['output']['tag'] = array("-o","--output");
\r
166 $this->phpDocOptions['output']['desc'] = "output information to use separated by ','. Format: output:converter:templatedir like \"HTML:frames:phpedit\"";
\r
167 $this->phpDocOptions['output']['type'] = "value";
\r
169 $this->phpDocOptions['converterparams']['tag'] = array("-cp","--converterparams");
\r
170 $this->phpDocOptions['converterparams']['desc'] = "dynamic parameters for a converter, separate values with commas";
\r
171 $this->phpDocOptions['converterparams']['type'] = "value";
\r
173 $this->phpDocOptions['customtags']['tag'] = array("-ct","--customtags");
\r
174 $this->phpDocOptions['customtags']['desc'] = "custom tags, will be recognized and put in tags[] instead of unknowntags[]";
\r
175 $this->phpDocOptions['customtags']['type'] = "value";
\r
177 $this->phpDocOptions['sourcecode']['tag'] = array("-s","--sourcecode");
\r
178 $this->phpDocOptions['sourcecode']['desc'] = "generate highlighted sourcecode for every parsed file (PHP 4.3.0+ only) on/off default off";
\r
179 $this->phpDocOptions['sourcecode']['type'] = "set";
\r
180 $this->phpDocOptions['sourcecode']['validvalues'] = array('on', 'off');
\r
182 $this->phpDocOptions['javadocdesc']['tag'] = array("-j","--javadocdesc");
\r
183 $this->phpDocOptions['javadocdesc']['desc'] = "JavaDoc-compliant description parsing. Use on/off, default off (more flexibility)";
\r
184 $this->phpDocOptions['javadocdesc']['type'] = "set";
\r
185 $this->phpDocOptions['javadocdesc']['validvalues'] = array('on', 'off');
\r
187 $this->phpDocOptions['pear']['tag'] = array("-p","--pear");
\r
188 $this->phpDocOptions['pear']['desc'] = "Parse a PEAR-style repository (package is directory, _members are @access private) on/off default off";
\r
189 $this->phpDocOptions['pear']['type'] = "set";
\r
190 $this->phpDocOptions['pear']['validvalues'] = array('on', 'off');
\r
192 $this->phpDocOptions['readmeinstallchangelog']['tag'] = array("-ric","--readmeinstallchangelog");
\r
193 $this->phpDocOptions['readmeinstallchangelog']['desc'] = "Specify custom filenames to parse like README, INSTALL or CHANGELOG files";
\r
194 $this->phpDocOptions['readmeinstallchangelog']['type'] = "value";
\r
196 $this->phpDocOptions['general']['message'] ="You can have multiple directories and multiple files, as well as a combination of both options";
\r
201 * create the help message for display on the command-line
\r
202 * @return string a string containing a help message
\r
204 function displayHelpMsg()
\r
208 foreach($this->phpDocOptions as $data)
\r
212 if (isset($data['tag']))
\r
214 if (is_array($data['tag'])) {
\r
215 foreach($data['tag'] as $param) {
\r
221 $tagspace = str_repeat(" ",$taglen);
\r
222 $tmp = " ".trim($tag).$tagspace;
\r
223 $tmp = substr($tmp,0,$taglen);
\r
224 $d = wordwrap(ltrim($data['desc']),($outputwidth-$taglen));
\r
225 $dt = explode("\n",$d);
\r
226 $dt[0] = $tmp .$dt[0];
\r
227 for($i=1;$i<count($dt);$i++)
\r
229 $dt[$i] = $tagspace.$dt[$i];
\r
231 $ret .= implode("\n",$dt)."\n\n";
\r
235 $ret .= "\n".wordwrap($data['message'],$outputwidth)."\n";
\r
240 * calls {@link file_exists()} for each value in include_path,
\r
241 * then calls {@link is_readable()} when it finds the file
\r
245 function isIncludeable($filename)
\r
247 $test = realpath($filename);
\r
248 if ($test && is_readable($test)) {
\r
249 return true; // for absolute paths
\r
251 $ip = get_include_path();
\r
252 if (PHPDOCUMENTOR_WINDOWS)
\r
254 $ip = explode(';', $ip);
\r
256 $ip = explode(':', $ip);
\r
258 foreach($ip as $path)
\r
260 if ($a = realpath($path . DIRECTORY_SEPARATOR . $filename))
\r
262 if (is_readable($a))
\r
272 * Parses $_SERVER['argv'] and creates a setup array
\r
273 * @return array a setup array
\r
274 * @global array command-line arguments
\r
275 * @todo replace with Console_* ?
\r
277 function parseArgv()
\r
281 // defaults for setting
\r
282 $setting['hidden'] = "off";
\r
283 $setting['ignoresymlinks'] = 'off';
\r
284 $setting['template'] = 'templates' . PATH_DELIMITER .'default' . PATH_DELIMITER;
\r
288 if(isset($argv) && is_array($argv))
\r
290 foreach ($argv as $cmd)
\r
292 if ($cmd == '--') {
\r
295 if ($cmd == '-h' || $cmd == '--help')
\r
297 echo $this->displayHelpMsg();
\r
301 // at first, set the arg value as if we
\r
302 // already know it's formatted normally, e.g.
\r
304 $setting[$valnext] = $cmd;
\r
306 if (isset($data['type']) && $data['type'] == 'set') {
\r
308 if ($valnext !== 'junk' && strpos(trim($cmd),'-') === 0) {
\r
309 // if valnext isn't 'junk' (i.e it was an arg option)
\r
310 // then the first arg needs an implicit "" as its value, e.g.
\r
311 // ... -q -pp ... ===> ... -q '' -pp ...
\r
312 $setting[$valnext] = '';
\r
314 } else if (!in_array(strtolower($cmd), $data['validvalues'], true)) {
\r
315 // the arg value is not a valid value
\r
316 addErrorDie(PDERROR_INVALID_VALUES, $valnext, $cmd,
\r
317 '(' . implode(', ', $data['validvalues']) . ')');
\r
321 foreach( $this->phpDocOptions as $name => $data )
\r
323 if (!empty($data['tag']))
\r
325 if (in_array($cmd,$data['tag']))
\r
337 if ($valnext == 'junk' && (strpos(trim($cmd),'-') === 0)) {
\r
338 // this indicates the last arg of the command
\r
339 // is an arg option (-) that was preceded by unrecognized "junk"
\r
340 addErrorDie(PDERROR_UNKNOWN_COMMANDLINE,$cmd);
\r
342 } else if ($valnext != 'junk' && (strpos(trim($cmd),'-') === 0)) {
\r
343 // this indicates the last arg of the command
\r
344 // is an arg option (-) without an arg value
\r
346 // add an empty arg "value" for this arg "option"
\r
347 $setting[$valnext] = '';
\r
354 echo "Please use php-cli.exe in windows, or set register_argc_argv On";
\r
357 /* $setting will always have at least 3 elements
\r
359 [ignoresymlinks] => 'off'
\r
360 [template] => templates/default
\r
362 if (count($setting) < 4) {
\r
363 echo $this->displayhelpMsg();
\r
372 * @return array list of files in a directory
\r
373 * @param string $directory full path to the directory you want the list of
\r
374 * @param bool whether to list files that begin with . like .bash_history
\r
375 * @param bool whether to ignore symlinks
\r
377 function dirList($orig_directory, $hidden = false, $ignore_symlinks = false)
\r
379 $directory = realpath($orig_directory);
\r
381 if (! @is_dir($directory))
\r
383 die("directory: '$directory' not found\n");
\r
386 $d = @dir($directory); // thanks to Jason E Sweat (jsweat@users.sourceforge.net) for fix
\r
387 while($d && ($entry=$d->read()) !== false) {
\r
388 if (strcmp($entry,".") == 0 || strcmp($entry,"..") == 0) {
\r
392 // skip hidden files, if we're supposed to
\r
395 if (substr($entry,0,1) == ".")
\r
397 phpDocumentor_out("Hidden " . $directory . PATH_DELIMITER . $entry . " Ignored\n");
\r
402 // skip symlink files, if we're supposed to
\r
403 if ($ignore_symlinks)
\r
405 if (is_link($directory . PATH_DELIMITER . $entry))
\r
407 phpDocumentor_out("Symlink " . $directory . PATH_DELIMITER . $entry . " Ignored\n");
\r
412 if (is_file($directory . PATH_DELIMITER . $entry)) {
\r
413 $ret[] = $directory . PATH_DELIMITER . $entry;
\r
415 if (is_dir($directory . PATH_DELIMITER . $entry)) {
\r
416 $tmp = $this->dirList($directory . PATH_DELIMITER . $entry, $hidden, $ignore_symlinks);
\r
417 if (is_array($tmp)) {
\r
418 foreach($tmp as $ent) {
\r
424 if ($d) $d->close();
\r
429 * Retrieve common directory (case-insensitive in windows)
\r
431 * takes the list of files, and returns the subdirectory they share in common,
\r
436 * "/dir1/dir2/subdir/dir3/filename.ext",
\r
437 * "/dir1/dir2/subdir/dir4/filename.ext",
\r
438 * "/dir1/dir2/mydir/dir5/filename.ext");
\r
441 * getBase will return "/dir1/dir2"
\r
442 * @param array array of strings
\r
444 function getBase($filelist)
\r
446 $masterPath = false;
\r
447 foreach($filelist as $path)
\r
451 $masterPath = str_replace('\\','/',dirname($path));
\r
454 if (dirname($path) != $masterPath)
\r
456 $mp = split(PATH_DELIMITER,$masterPath);
\r
457 $np = split(PATH_DELIMITER,str_replace('\\','/',dirname($path)));
\r
458 if (count($np) < count($mp))
\r
460 $masterPath = join($np, PATH_DELIMITER);
\r
465 for($i=0;$i < count($mp) && $i < count($np);$i++)
\r
467 if (PHPDOCUMENTOR_WINDOWS)
\r
469 if (strtolower($mp[$i]) != strtolower($np[$i])) $found = $i;
\r
472 if ($mp[$i] != $np[$i]) $found = $i;
\r
475 if ($found !== false)
\r
477 $mp = array_slice($mp,0,$found);
\r
478 $masterPath = join($mp,PATH_DELIMITER);
\r
484 return $masterPath;
\r
488 * Retrieve tutorial subdirectories and their contents from the list of
\r
490 * @param array array of paths (strings)
\r
491 * @return array array(filelist - tutorials, tutorials)
\r
493 function getTutorials($filelist)
\r
495 $list = $tutorials = array();
\r
496 foreach($filelist as $file)
\r
498 if (strpos($file,'tutorials/') !== false)
\r
500 $tutedir = explode('/',substr($file,strpos($file,'tutorials/')));
\r
501 array_shift($tutedir);
\r
502 if (count($tutedir) <= 3)
\r
505 // kludge - will need to fix for 2.0
\r
506 $res['category'] = $GLOBALS['phpDocumentor_DefaultCategoryName'];
\r
507 $res['package'] = array_shift($tutedir);
\r
508 $res['subpackage'] = '';
\r
509 if (count($tutedir) > 1)
\r
510 $res['subpackage'] = array_shift($tutedir);
\r
511 $f = array_shift($tutedir);
\r
512 $res['tutename'] = $f;
\r
513 $f = explode('.',$f);
\r
514 $res['tutetype'] = array_pop($f);
\r
515 if ($res['tutetype'] == 'ini') continue;
\r
516 $res['path'] = $file;
\r
517 if (@file_exists($file . '.ini'))
\r
519 $res['ini'] = phpDocumentor_parse_ini_file($file . '.ini', true);
\r
522 $res['ini'] = false;
\r
524 $tutorials[] = $res;
\r
526 } else $list[] = $file;
\r
528 return array($list,$tutorials);
\r
532 * @param string base directory from {@link getBase()}
\r
533 * @param array file list from {@link dirList()}
\r
534 * @return array array(filelist - README/INSTALL/CHANGELOG,
\r
535 * README/INSTALL/CHANGELOG)
\r
537 function getReadmeInstallChangelog($base,$filelist)
\r
539 $list = $ric = array();
\r
540 $names = $GLOBALS['_phpDocumentor_RIC_files'];
\r
541 foreach($filelist as $file)
\r
543 if ((dirname($file) == $base) && in_array(strtoupper(basename($file)), $names))
\r
544 { // be sure to change $this->checkIgnore() if any other files are added here!!
\r
551 return array($list,$ric);
\r
555 * @param string directory
\r
556 * @param string base directory
\r
557 * @param array array of ignored items
\r
558 * @param boolean the "hidden" flag
\r
559 * @param boolean the "ignoresymlinks" flag
\r
561 * @uses checkIgnore
\r
564 function getDirTree($dir, $base_dir, $ignore = array(), $hidden = false, $ignoresymlinks = false)
\r
566 $allfiles = $this->dirList($dir,$hidden,$ignoresymlinks);
\r
568 foreach($allfiles as $file)
\r
570 if ($this->checkIgnore(basename($file),dirname(realpath($file)),$ignore,$ignoresymlinks)) continue;
\r
571 if (PHPDOCUMENTOR_WINDOWS) {
\r
572 $path = substr(dirname($file),strlen(str_replace('\\','/',realpath($base_dir))));
\r
574 $path = substr(dirname($file),strlen(str_replace('\\','/',realpath($base_dir)))+1);
\r
576 if (!$path) $path = '/';
\r
577 $parts = pathinfo($file);
\r
578 if (!isset($parts['extension']))
\r
580 $parts['extension'] = '';
\r
582 $struc[$path][] = array(
\r
583 'file' => $parts['basename'],
\r
584 'ext' => $parts['extension'],
\r
587 uksort($struc,'strnatcasecmp');
\r
588 foreach($struc as $key => $ind)
\r
590 usort($ind,'Ioinc_sortfiles');
\r
591 $struc[$key] = $ind;
\r
595 $key = explode('/',$key);
\r
596 while (count($key))
\r
599 if (isset($struc[join('/',$key)]))
\r
601 $struc[join('/',$key)][substr($save,strlen(join('/',$key)) + 1)] = $ind;
\r
602 unset($struc[$save]);
\r
607 foreach($struc as $key => $ind)
\r
611 if (count(explode('/',$key)) == 1)
\r
613 $struc['/'][$key] = $struc[$key];
\r
614 unset($struc[$key]);
\r
618 $tempstruc = $struc;
\r
619 unset($tempstruc['/']);
\r
620 $leftover_dirs = array_keys($tempstruc);
\r
621 $splitdirs = array();
\r
622 foreach($leftover_dirs as $dir)
\r
624 $splitdirs[] = explode('/',$dir);
\r
626 $leftover_dirs = array();
\r
628 foreach($splitdirs as $dir)
\r
630 $save = join($dir,'/');
\r
631 $struc['/'] = setup_dirs($struc['/'], $dir, $tempstruc[$save]);
\r
632 unset($struc[$save]);
\r
634 @uksort($struc['/'],'Ioinc_mystrucsort');
\r
639 * Reads a file and returns it as a string
\r
640 * Does basic error checking
\r
642 * file extensions are set in {@link phpdoc.inc}
\r
644 * @global array PHP File extensions, used to validate that $path is a PHP File
\r
645 * @global array PHP File extensions in a CVS repository, used to validate that $path is a PHP File
\r
646 * @param string $path
\r
648 function readPhpFile($path, $quietMode = false)
\r
650 global $_phpDocumentor_cvsphpfile_exts, $_phpDocumentor_phpfile_exts;
\r
651 // tiberiusblue addition
\r
652 $cvsExt = $_phpDocumentor_cvsphpfile_exts;
\r
653 $ext = $_phpDocumentor_phpfile_exts;
\r
654 if (file_exists($path))
\r
656 if (is_file($path))
\r
659 $tmp = explode(".",$path);
\r
660 // tiberiusblue addition
\r
662 if (in_array(array_pop($tmp),$ext))
\r
664 phpDocumentor_out(" -- Parsing file\n");
\r
666 if (function_exists('file_get_contents')) {
\r
667 return file_get_contents($path);
\r
669 $fp = fopen($path,"r");
\r
670 $ret = fread($fp,filesize($path));
\r
673 } elseif (in_array(array_pop($tmp2),$cvsExt))
\r
675 phpDocumentor_out(" CVS file [EXPERIMENTAL]\n");
\r
677 if (function_exists('file_get_contents')) {
\r
678 $ret = file_get_contents($path);
\r
680 $fp = fopen($path,"r");
\r
681 $ret = fread($fp,filesize($path));
\r
684 $ret = strstr($ret,"<?");
\r
685 $ret = substr($ret,0,strpos($ret,"@\n"));
\r
686 $ret = str_replace("@@","@",$ret);
\r
690 phpDocumentor_out(" -- File not parsed, not a php file\n");
\r
694 phpDocumentor_out(" -- Unable to read file, not a file\n");
\r
698 phpDocumentor_out(" -- Unable to read file, file does not exist\n");
\r
704 * Tell whether to ignore a file or a directory
\r
705 * allows * and ? wildcards
\r
707 * @author Greg Beaver <cellog@php.net>
\r
708 * @param string $file just the file name of the file or directory,
\r
709 * in the case of directories this is the last dir
\r
710 * @param string $path the path to consider (should be checked by
\r
711 * realpath() before, and may be relative)
\r
712 * @param array $ignore
\r
714 * @param bool Ignore symlinks?
\r
715 * @return bool true if $path should be ignored, false if it should not
\r
717 function checkIgnore($file,$path,$ignore,$ignore_no_ext = true,$ignoresymlinks = false)
\r
719 global $_phpDocumentor_RIC_files;
\r
721 if ($ignoresymlinks && is_link($path . PATH_DELIMITER . $file)) return false;
\r
723 if (!count($ignore)) return false;
\r
725 if (!isset($this->ignore))
\r
727 $this->_setupIgnore($ignore);
\r
729 if (!$this->ignore)
\r
734 if ($ignore_no_ext &&
\r
735 !in_array(strtoupper($file), $_phpDocumentor_RIC_files))
\r
737 if (!is_numeric(strpos($file,'.'))) return true;
\r
739 if (is_array($this->ignore))
\r
741 foreach($this->ignore as $match)
\r
743 // match is an array if the ignore parameter was a /path/to/pattern
\r
744 if (is_array($match))
\r
746 // check to see if the path matches with a path delimiter appended
\r
747 preg_match('/^' . strtoupper($match[0]).'$/', strtoupper($path) . PATH_DELIMITER,$find);
\r
750 // check to see if it matches without an appended path delimiter
\r
751 preg_match('/^' . strtoupper($match[0]).'$/', strtoupper($path), $find);
\r
755 // check to see if the file matches the file portion of the regex string
\r
756 preg_match('/^' . strtoupper($match[1]).'$/', strtoupper($file), $find);
\r
762 // check to see if the full path matches the regex
\r
763 preg_match('/^' . strtoupper($match[0]).'$/',
\r
764 strtoupper($path . DIRECTORY_SEPARATOR . $file), $find);
\r
771 // ignore parameter was just a pattern with no path delimiters
\r
772 // check it against the path
\r
773 preg_match('/^' . strtoupper($match).'$/', strtoupper($path), $find);
\r
778 // check it against the file only
\r
779 preg_match('/^' . strtoupper($match).'$/', strtoupper($file), $find);
\r
791 * Construct the {@link $ignore} array
\r
792 * @author Greg Beaver <cellog@php.net>
\r
793 * @param array strings of files/paths/wildcards to ignore
\r
794 * @access protected
\r
796 function _setupIgnore($ignore)
\r
799 if ( ! is_array($ignore))
\r
801 $this->ignore = false;
\r
804 for($i=0; $i<count($ignore);$i++)
\r
806 if (empty($ignore[$i]))
\r
809 $ignore[$i] = strtr($ignore[$i], '\\', '/');
\r
810 $ignore[$i] = str_replace('//','/',$ignore[$i]);
\r
812 if (!is_numeric(strpos($ignore[$i],PATH_DELIMITER)))
\r
814 $ig[] = $this->getRegExpableSearchString($ignore[$i]);
\r
817 if (basename($ignore[$i]) . PATH_DELIMITER == $ignore[$i])
\r
818 $ig[] = $this->getRegExpableSearchString($ignore[$i]);
\r
820 $ig[] = array($this->getRegExpableSearchString($ignore[$i]),$this->getRegExpableSearchString(basename($ignore[$i])));
\r
823 if (count($ig)) $this->ignore = $ig;
\r
827 * Converts $s into a string that can be used with preg_match
\r
828 * @param string $s string with wildcards ? and *
\r
829 * @author Greg Beaver <cellog@php.net>
\r
830 * @return string converts * to .*, ? to ., etc.
\r
832 function getRegExpableSearchString($s)
\r
835 if (DIRECTORY_SEPARATOR == '\\')
\r
839 $s = str_replace('/', DIRECTORY_SEPARATOR, $s);
\r
840 $x = strtr($s, array('?' => '.','*' => '.*','.' => '\\.','\\' => '\\\\','/' => '\\/',
\r
841 '[' => '\\[',']' => '\\]','-' => '\\-'));
\r
842 if (strpos($s, DIRECTORY_SEPARATOR) !== false &&
\r
843 strrpos($s, DIRECTORY_SEPARATOR) === strlen($s) - 1)
\r
845 $x = "(?:.*$y$x?.*|$x.*)";
\r
851 * Removes files from the $dir array that do not match the search string in
\r
853 * @param array $dir array of filenames (full path)
\r
854 * @param string $match search string with wildcards
\r
855 * @author Greg Beaver <cellog@php.net>
\r
856 * @return string|array listing of every file in a directory that matches
\r
857 * the search string
\r
859 function removeNonMatches($dir, $match)
\r
861 $match = $this->getRegExpableSearchString($match);
\r
863 if (!is_array($dir))
\r
865 $dir = array($dir);
\r
868 foreach($dir as $i => $file)
\r
870 preg_match('/^'.$match.'$/',basename($file),$find);
\r
871 if (!count($find)) unset($dir[$i]);
\r
873 if ($nodir) return $dir[0];
\r
878 * Take a filename with wildcards and return all files that match the
\r
880 * @param string $file a full path from the -f command-line parameter, with
\r
881 * potential * and ? wildcards.
\r
882 * @return mixed if $file contains wildcards, returns an array of matching
\r
883 * files, otherwise returns false
\r
884 * @author Greg Beaver <cellog@php.net>
\r
886 * @uses removeNonMatches
\r
888 function getAllFiles($file)
\r
890 $path = realpath(dirname($file));
\r
891 $file = basename($file);
\r
893 if (is_numeric(strpos($file,'?')) || is_numeric(strpos($file,'*')))
\r
895 $files = $this->dirList($path);
\r
896 $a = $this->removeNonMatches($files,$file);
\r
904 * Sorting functions for the file list
\r
908 function Ioinc_sortfiles($a, $b)
\r
910 return strnatcasecmp($a['file'],$b['file']);
\r
913 function Ioinc_mystrucsort($a, $b)
\r
915 if (is_numeric($a) && is_string($b)) return 1;
\r
916 if (is_numeric($b) && is_string($a)) return -1;
\r
917 if (is_numeric($a) && is_numeric($b))
\r
919 if ($a > $b) return 1;
\r
920 if ($a < $b) return -1;
\r
921 if ($a == $b) return 0;
\r
923 return strnatcasecmp($a,$b);
\r
928 * Recursively add all the subdirectories of $contents to $dir without erasing anything in
\r
932 * @return array processed $dir
\r
934 function set_dir($dir,$contents)
\r
936 while(list($one,$two) = each($contents))
\r
938 if (isset($dir[$one]))
\r
940 $dir[$one] = set_dir($dir[$one],$contents[$one]);
\r
941 } else $dir[$one] = $two;
\r
947 * Recursively move contents of $struc into associative array
\r
949 * The contents of $struc have many indexes like 'dir/subdir/subdir2'.
\r
950 * This function converts them to
\r
951 * array('dir' => array('subdir' => array('subdir2')))
\r
952 * @param array struc is array('dir' => array of files in dir,'dir/subdir' => array of files in dir/subdir,...)
\r
953 * @param array array form of 'dir/subdir/subdir2' array('dir','subdir','subdir2')
\r
954 * @return array same as struc but with array('dir' => array(file1,file2,'subdir' => array(file1,...)))
\r
956 function setup_dirs($struc,$dir,$contents)
\r
960 foreach($contents as $dir => $files)
\r
962 if (is_string($dir))
\r
964 if (strpos($dir,'/'))
\r
967 $a = $contents[$dir];
\r
968 unset($contents[$dir]);
\r
969 $b = explode('/',$dir);
\r
970 $c = array_shift($b);
\r
971 if (isset($contents[$c]))
\r
973 $contents[$c] = set_dir($contents[$c],setup_dirs(array(),$b,$a));
\r
974 } else $contents[$c] = setup_dirs(array(),$b,$a);
\r
980 $me = array_shift($dir);
\r
981 if (!isset($struc[$me])) $struc[$me] = array();
\r
982 $struc[$me] = setup_dirs($struc[$me],$dir,$contents);
\r
986 if (!function_exists('get_include_path')) {
\r
987 function get_include_path()
\r
989 return ini_get('include_path');
\r