phpDocumentor
[ class tree: phpDocumentor ] [ index: phpDocumentor ] [ all elements ]

Source for file Io.inc

Documentation is available at Io.inc

  1. <?php
  2. /**
  3.  * File and input handling routines
  4.  * 
  5.  * This class parses command-line options, and works with files to
  6.  * generate lists of files to parse based on the ignore/include options
  7.  * 
  8.  * phpDocumentor :: automatic documentation generator
  9.  * 
  10.  * PHP versions 4 and 5
  11.  *
  12.  * Copyright (c) 2000-2006 Joshua Eichorn, Gregory Beaver
  13.  * 
  14.  * LICENSE:
  15.  * 
  16.  * This library is free software; you can redistribute it
  17.  * and/or modify it under the terms of the GNU Lesser General
  18.  * Public License as published by the Free Software Foundation;
  19.  * either version 2.1 of the License, or (at your option) any
  20.  * later version.
  21.  * 
  22.  * This library is distributed in the hope that it will be useful,
  23.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  25.  * Lesser General Public License for more details.
  26.  * 
  27.  * You should have received a copy of the GNU Lesser General Public
  28.  * License along with this library; if not, write to the Free Software
  29.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  30.  *
  31.  * @package    phpDocumentor
  32.  * @author     Joshua Eichorn <jeichorn@phpdoc.org>
  33.  * @author     Gregory Beaver <cellog@php.net>
  34.  * @copyright  2000-2006 Joshua Eichorn, Gregory Beaver
  35.  * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL
  36.  * @version    CVS: $Id: Io.inc,v 1.15.2.3 2007/03/29 19:09:42 ashnazg Exp $
  37.  * @filesource
  38.  * @link       http://www.phpdoc.org
  39.  * @link       http://pear.php.net/PhpDocumentor
  40.  * @since      0.1
  41.  */
  42. /**
  43.  * Class to handle file and user io opperations
  44.  *
  45.  * @author    Joshua Eichorn <jeichorn@phpdoc.org>
  46.  * @author     Gregory Beaver <cellog@php.net>
  47.  * @version    $Id: Io.inc,v 1.15.2.3 2007/03/29 19:09:42 ashnazg Exp $
  48.  * @package     phpDocumentor
  49.  */
  50. class Io 
  51. {
  52.     
  53.     /**
  54.      * Holds all the options that are avaible to the cmd line interface
  55.      * and to the different web interfaces
  56.      */
  57.     var $phpDocOptions;
  58.     /**
  59.      * Format: array(array(regexp-ready string to search for whole path,
  60.      * regexp-ready string to search for basename of ignore strings),...)
  61.      * @var false|array
  62.      */
  63.     var $ignore = false;
  64.     /**
  65.      * A specific array of values that boolean-based arguments can understand,
  66.      * aided by the {@link decideOnOrOff()} helper method.
  67.      * @var array 
  68.      */
  69.     var $valid_booleans = array
  70.     (
  71.         ''' ''on''On''ON''y''Y''yes''Yes''YES''true''True''TRUE''1'
  72.         'off''Off''OFF''n''N''no''No''NO''false''False''FALSE''0'
  73.     );
  74.     
  75.     /**
  76.      * creates an array $this->phpDocOptions and sets program options in it.
  77.      * Array is in the format of:
  78.      * <pre>
  79.      * [filename][tag][] = "f";
  80.      * [filename][tag][] = "-file";
  81.      * [filename][desc] "name of file to parse"
  82.      * </pre>
  83.      */
  84.     function Io()
  85.     {
  86.         $this->phpDocOptions['filename']['tag'= array"-f""--filename");
  87.         $this->phpDocOptions['filename']['desc'"name of file(s) to parse ',' file1,file2.  Can contain complete path and * ? wildcards";
  88.         $this->phpDocOptions['filename']['type'"path";
  89.  
  90.         $this->phpDocOptions['directory']['tag'= array"-d""--directory");
  91.         $this->phpDocOptions['directory']['desc'"name of a directory(s) to parse directory1,directory2";
  92.         $this->phpDocOptions['directory']['type'"path";
  93.  
  94.         $this->phpDocOptions['examplesdir']['tag'= array"-ed""--examplesdir");
  95.         $this->phpDocOptions['examplesdir']['desc'"full path of the directory to look for example files from @example tags";
  96.         $this->phpDocOptions['examplesdir']['type'"path";
  97.  
  98.         $this->phpDocOptions['templatebase']['tag'= array"-tb""--templatebase");
  99.         $this->phpDocOptions['templatebase']['desc'"base location of all templates for this parse.";
  100.         $this->phpDocOptions['templatebase']['type'"path";
  101.  
  102.         $this->phpDocOptions['target']['tag'= array("-t""--target");
  103.         $this->phpDocOptions['target']['desc'"path where to save the generated files";
  104.         $this->phpDocOptions['target']['type'"path";
  105.         
  106.         $this->phpDocOptions['ignore']['tag'= array("-i""--ignore");
  107.         $this->phpDocOptions['ignore']['desc'"file(s) that will be ignored, multiple separated by ','.  Wildcards * and ? are ok";
  108.         $this->phpDocOptions['ignore']['type'"path";
  109.  
  110.         $this->phpDocOptions['ignoretags']['tag'= array("-it""--ignore-tags");
  111.         $this->phpDocOptions['ignoretags']['desc'"tags to ignore for this parse.  @package, @subpackage, @access and @ignore may not be ignored.";
  112.         $this->phpDocOptions['ignoretags']['type'"value";
  113.  
  114.         $this->phpDocOptions['hidden']['tag'= array("-dh""--hidden");
  115.         $this->phpDocOptions['hidden']['desc'"set equal to on (-dh on) to descend into hidden directories (directories starting with '.'), default is off";
  116.         $this->phpDocOptions['hidden']['type'"set";
  117.         $this->phpDocOptions['hidden']['validvalues'$this->valid_booleans;
  118.  
  119.         $this->phpDocOptions['quiet']['tag'= array("-q""--quiet");
  120.         $this->phpDocOptions['quiet']['desc'"do not display parsing/conversion messages.  Useful for cron jobs on/off default off";
  121.         $this->phpDocOptions['quiet']['type'"set";
  122.         $this->phpDocOptions['quiet']['validvalues'$this->valid_booleans;
  123.  
  124.         $this->phpDocOptions['title']['tag'= array("-ti","--title");
  125.         $this->phpDocOptions['title']['desc'"title of generated documentation, default is 'Generated Documentation'";
  126.         $this->phpDocOptions['title']['type'"value";
  127.  
  128.         $this->phpDocOptions['help']['tag'= array("-h""--help");
  129.         $this->phpDocOptions['help']['desc'"    show this help message";
  130.  
  131.         $this->phpDocOptions['useconfig']['tag'= array("-c","--useconfig");
  132.         $this->phpDocOptions['useconfig']['desc'"Use a Config file in the users/ subdirectory for all command-line options";
  133.         $this->phpDocOptions['useconfig']['type'"value";
  134.  
  135.         $this->phpDocOptions['parseprivate']['tag'= array("-pp","--parseprivate");
  136.         $this->phpDocOptions['parseprivate']['desc'"parse @internal and elements marked private with @access.  Use on/off, default off";
  137.         $this->phpDocOptions['parseprivate']['type'"set";
  138.         $this->phpDocOptions['parseprivate']['validvalues'= array('on''off');
  139.  
  140.         $this->phpDocOptions['packageoutput']['tag'= array("-po","--packageoutput");
  141.         $this->phpDocOptions['packageoutput']['desc'"output documentation only for selected packages.  Use a comma-delimited list";
  142.         $this->phpDocOptions['packageoutput']['type'"value";
  143.  
  144.         $this->phpDocOptions['defaultpackagename']['tag'= array("-dn","--defaultpackagename");
  145.         $this->phpDocOptions['defaultpackagename']['desc'"name to use for the default package.  If not specified, uses 'default'";
  146.         $this->phpDocOptions['defaultpackagename']['type'"value";
  147.  
  148.         $this->phpDocOptions['defaultcategoryname']['tag'= array("-dc","--defaultcategoryname");
  149.         $this->phpDocOptions['defaultcategoryname']['desc'"name to use for the default category.  If not specified, uses 'default'";
  150.         $this->phpDocOptions['defaultcategoryname']['type'"value";
  151.  
  152.         $this->phpDocOptions['output']['tag'= array("-o","--output");
  153.         $this->phpDocOptions['output']['desc'"output information to use separated by ','.  Format: output:converter:templatedir like \"HTML:frames:phpedit\"";
  154.         $this->phpDocOptions['output']['type'"value";
  155.  
  156.         $this->phpDocOptions['converterparams']['tag'= array("-cp","--converterparams");
  157.         $this->phpDocOptions['converterparams']['desc'"dynamic parameters for a converter, separate values with commas";
  158.         $this->phpDocOptions['converterparams']['type'"value";
  159.  
  160.         $this->phpDocOptions['customtags']['tag'= array("-ct","--customtags");
  161.         $this->phpDocOptions['customtags']['desc'"custom tags, will be recognized and put in tags[] instead of unknowntags[]";
  162.         $this->phpDocOptions['customtags']['type'"value";
  163.  
  164.         $this->phpDocOptions['sourcecode']['tag'= array("-s","--sourcecode");
  165.         $this->phpDocOptions['sourcecode']['desc'"generate highlighted sourcecode for every parsed file (PHP 4.3.0+ only) on/off default off";
  166.         $this->phpDocOptions['sourcecode']['type'"set";
  167.         $this->phpDocOptions['sourcecode']['validvalues'= array('on''off');
  168.  
  169.         $this->phpDocOptions['javadocdesc']['tag'= array("-j","--javadocdesc");
  170.         $this->phpDocOptions['javadocdesc']['desc'"JavaDoc-compliant description parsing.  Use on/off, default off (more flexibility)";
  171.         $this->phpDocOptions['javadocdesc']['type'"set";
  172.         $this->phpDocOptions['javadocdesc']['validvalues'= array('on''off');
  173.  
  174.         $this->phpDocOptions['pear']['tag'= array("-p","--pear");
  175.         $this->phpDocOptions['pear']['desc'"Parse a PEAR-style repository (package is directory, _members are @access private) on/off default off";
  176.         $this->phpDocOptions['pear']['type'"set";
  177.         $this->phpDocOptions['pear']['validvalues'= array('on''off');
  178.  
  179.         $this->phpDocOptions['readmeinstallchangelog']['tag'= array("-ric","--readmeinstallchangelog");
  180.         $this->phpDocOptions['readmeinstallchangelog']['desc'"Specify custom filenames to parse like README, INSTALL or CHANGELOG files";
  181.         $this->phpDocOptions['readmeinstallchangelog']['type'"value";
  182.  
  183.         $this->phpDocOptions['general']['message'="You can have multiple directories and multiple files, as well as a combination of both options";
  184.     }
  185.  
  186.     
  187.     /**
  188.      * create the help message for display on the command-line
  189.      * @return string a string containing a help message
  190.      */
  191.     function displayHelpMsg()
  192.     {
  193.         unset($ret);
  194.         $ret "\n";
  195.         foreach($this->phpDocOptions as $data)
  196.         {
  197.             unset($tag);
  198.             $tag "";
  199.             if (isset($data['tag']))
  200.             {
  201.                 if (is_array($data['tag'])) {
  202.                     foreach($data['tag'as $param{
  203.                         $tag .= "$param    ";
  204.                     }
  205.                 }
  206.         $taglen = 34;
  207.         $outputwidth = 79;
  208.         $tagspace str_repeat(" ",$taglen);
  209.                 $tmp "  ".trim($tag).$tagspace;
  210.                 $tmp substr($tmp,0,$taglen);
  211.                 $d wordwrap(ltrim($data['desc']),($outputwidth-$taglen));
  212.         $dt explode("\n",$d);
  213.         $dt[0$tmp .$dt[0];
  214.         for($i=1;$i<count($dt);$i++)
  215.         {
  216.             $dt[$i$tagspace.$dt[$i];
  217.         }
  218.         $ret .= implode("\n",$dt)."\n\n";
  219.         
  220.             }
  221.         }
  222.         $ret .= "\n".wordwrap($data['message'],$outputwidth)."\n";
  223.         return $ret
  224.     }
  225.     
  226.     /**
  227.      * calls {@link file_exists()} for each value in include_path,
  228.      * then calls {@link is_readable()} when it finds the file
  229.      * @param string 
  230.      * @return boolean 
  231.      */
  232.     function isIncludeable($filename)
  233.     {
  234.         $test realpath($filename);
  235.         if ($test && is_readable($test)) {
  236.             return true; // for absolute paths
  237.         }
  238.         $ip get_include_path();
  239.         if (PHPDOCUMENTOR_WINDOWS)
  240.         {
  241.             $ip explode(';'$ip);
  242.         else {
  243.             $ip explode(':'$ip);
  244.         }
  245.         foreach($ip as $path)
  246.         {
  247.             if ($a realpath($path . DIRECTORY_SEPARATOR . $filename))
  248.             {
  249.                 if (is_readable($a))
  250.                 {
  251.                     return true;
  252.                 }
  253.             }
  254.         }
  255.         return false;
  256.     }
  257.  
  258.     /**
  259.      * Parses $_SERVER['argv'] and creates a setup array
  260.      * @return array a setup array
  261.      * @global array command-line arguments
  262.      */
  263.     function parseArgv()
  264.     {
  265.         global $argv;
  266.         // defaults for setting
  267.         $setting['hidden'"off";
  268.         $setting['template''templates' PATH_DELIMITER .'default' PATH_DELIMITER;
  269.  
  270.         $valnext "junk";
  271.         $data = array();
  272.         if(isset($argv&& is_array($argv))
  273.         {
  274.             foreach ($argv as $cmd)
  275.             {
  276.                 //if($cmd === 'phpdoc' || basename($cmd)==='phpdoc')
  277.                 //    continue;
  278.  
  279.                 if ($cmd == '--'{
  280.                     continue;
  281.                 }
  282.                 if ($cmd == '-h' || $cmd == '--help')
  283.                 {
  284.                     echo $this->displayHelpMsg();
  285.                     die();
  286.                 }
  287.                 if (isset($data['type']&& $data['type'== 'set'{
  288.                     if (!in_array(strtolower($cmd)$data['validvalues']true)) {
  289.                         addErrorDie(PDERROR_INVALID_VALUES$valnext$cmd,
  290.                             '(' implode(', '$data['validvalues']')');
  291.                     }
  292.                 }
  293.                 $setting[$valnext$cmd;
  294.                 foreach$this->phpDocOptions as $name => $data )
  295.                 {
  296.                     if (!empty($data['tag']))
  297.                     {
  298.                         if (in_array($cmd,$data['tag']))
  299.                         {
  300.                             $valnext $name;
  301.                             break;
  302.                         
  303.                         else
  304.                         {
  305.                             $valnext "junk";
  306.                         }
  307.                     }
  308.                 }
  309.                 if ($valnext == 'junk' && (strpos(trim($cmd),'-'=== 0))
  310.                 {
  311.                     addErrorDie(PDERROR_UNKNOWN_COMMANDLINE,$cmd);
  312.                 }
  313.             }
  314.         else
  315.         {
  316.             echo "Please use php-cli.exe in windows, or set register_argc_argv On";
  317.             die;
  318.         }
  319.         /* $setting will always have at least 2 elements
  320.         [hidden] => off
  321.         [template] => templates/default
  322.          */
  323.         if (count($setting< 3{
  324.             echo $this->displayhelpMsg();
  325.             die();
  326.         }
  327.         return $setting;
  328.     }
  329.  
  330.  
  331.     /**
  332.      * @return array list of files in a directory
  333.      * @param string $directory full path to the directory you want the list of
  334.      * @param off|onwhether to list files that begin with . like .bash_history
  335.      */
  336.     function dirList($directory$hidden "off")
  337.     {
  338.         $directory realpath($directory);
  339.         $ret = false;
  340.         if (@is_dir($directory))
  341.         {
  342.             $ret = array();
  343.             $d @dir($directory)// thanks to Jason E Sweat (jsweat@users.sourceforge.net) for fix
  344.             while($d && ($entry=$d->read()) !== false{
  345.                 if (strcmp($entry,"."!= 0 && strcmp($entry,".."!= 0{
  346.                 if ($hidden == "off")
  347.                 {
  348.                     if (substr($entry,0,1== ".")
  349.                     {
  350.                         $getentry = false;
  351.                     else {
  352.                         $getentry = true;
  353.                     }
  354.         
  355.                 else {
  356.                     $getentry = true;
  357.                 }
  358.                 
  359.                 if ($getentry == true)
  360.                 {
  361.                     if (is_file($directory PATH_DELIMITER . $entry)) {
  362.                         $ret[$directory PATH_DELIMITER . $entry;
  363.                     }
  364.                     if (is_dir($directory PATH_DELIMITER . $entry)) {
  365.                         $tmp $this->dirList($directory PATH_DELIMITER . $entry$hidden);
  366.                         if (is_array($tmp)) {
  367.                             foreach($tmp as $ent{
  368.                                 $ret[$ent;
  369.                             }
  370.                         }
  371.                     }
  372.                 }
  373.             }
  374.         }
  375.         if ($d$d->close();
  376.         else {
  377.             die("directory: '$directory'  not found\n");
  378.         }
  379.         return $ret;
  380.     }
  381.  
  382.     /**
  383.      * Retrieve common directory (case-insensitive in windows)
  384.      *
  385.      * takes the list of files, and returns the subdirectory they share in common,
  386.      * so in this list:
  387.      *
  388.      * <code>
  389.      * array(
  390.      * "/dir1/dir2/subdir/dir3/filename.ext",
  391.      * "/dir1/dir2/subdir/dir4/filename.ext",
  392.      * "/dir1/dir2/mydir/dir5/filename.ext");
  393.      * </code>
  394.      *
  395.      * getBase will return "/dir1/dir2"
  396.      * @param array array of strings
  397.      */
  398.     function getBase($filelist)
  399.     {
  400.         $masterPath = false;
  401.         foreach($filelist as $path)
  402.         {
  403.             if (!$masterPath)
  404.             {
  405.                 $masterPath str_replace('\\','/',dirname($path));
  406.             else
  407.             {
  408.                 if (dirname($path!= $masterPath)
  409.                 {
  410.                     $mp split(PATH_DELIMITER,$masterPath);
  411.                     $np split(PATH_DELIMITER,str_replace('\\','/',dirname($path)));
  412.                     if (count($npcount($mp))
  413.                     {
  414.                         $masterPath join($npPATH_DELIMITER);
  415.                     else
  416.                     {
  417.                         $test = false;
  418.                         $found = false;
  419.                         for($i=0;$i count($mp&& $i count($np);$i++)
  420.                         {
  421.                             if (PHPDOCUMENTOR_WINDOWS)
  422.                             {
  423.                                 if (strtolower($mp[$i]!= strtolower($np[$i])) $found $i;
  424.                             else
  425.                             {
  426.                                 if ($mp[$i!= $np[$i]$found $i;
  427.                             }
  428.                         }
  429.                         if ($found !== false)
  430.                         {
  431.                             $mp array_slice($mp,0,$found);
  432.                             $masterPath join($mp,PATH_DELIMITER);
  433.                         }
  434.                     }
  435.                 }
  436.             }
  437.         }
  438.         return $masterPath;
  439.     }
  440.     
  441.     /**
  442.      * Retrieve tutorial subdirectories and their contents from the list of
  443.      * files to parse
  444.      * @param array array of paths (strings)
  445.      * @return array array(filelist - tutorials, tutorials)
  446.      */
  447.     function getTutorials($filelist)
  448.     {
  449.         $list $tutorials = array();
  450.         foreach($filelist as $file)
  451.         {
  452.             if (strpos($file,'tutorials/'!== false)
  453.             {
  454.                 $tutedir explode('/',substr($file,strpos($file,'tutorials/')));
  455.                 array_shift($tutedir);
  456.                 if (count($tutedir<= 3)
  457.                 {
  458.                     $res = array();
  459.                     // kludge - will need to fix for 2.0
  460.                     $res['category'$GLOBALS['phpDocumentor_DefaultCategoryName'];
  461.                     $res['package'array_shift($tutedir);
  462.                     $res['subpackage''';
  463.                     if (count($tutedir> 1)
  464.                     $res['subpackage'array_shift($tutedir);
  465.                     $f array_shift($tutedir);
  466.                     $res['tutename'$f;
  467.                     $f explode('.',$f);
  468.                     $res['tutetype'array_pop($f);
  469.                     if ($res['tutetype'== 'ini'continue;
  470.                     $res['path'$file;
  471.                     if (@file_exists($file '.ini'))
  472.                     {
  473.                         $res['ini'phpDocumentor_parse_ini_file($file '.ini'true);
  474.                     else
  475.                     {
  476.                         $res['ini'= false;
  477.                     }
  478.                     $tutorials[$res;
  479.                 }
  480.             else $list[$file;
  481.         }
  482.         return array($list,$tutorials);
  483.     }
  484.     
  485.     /**
  486.      * @param string base directory from {@link getBase()}
  487.      * @param array file list from {@link dirList()}
  488.      * @return array array(filelist - README/INSTALL/CHANGELOG,
  489.      *                      README/INSTALL/CHANGELOG)
  490.      */
  491.     function getReadmeInstallChangelog($base,$filelist)
  492.     {
  493.         $list $ric = array();
  494.         $names $GLOBALS['_phpDocumentor_RIC_files'];
  495.         foreach($filelist as $file)
  496.         {
  497.             if ((dirname($file== $base&& in_array(strtoupper(basename($file))$names))
  498.             // be sure to change $this->checkIgnore() if any other files are added here!!
  499.                 $ric[$file;
  500.             else
  501.             {
  502.                 $list[$file;
  503.             }
  504.         }
  505.         return array($list,$ric);
  506.     }
  507.   
  508.     function getDirTree($dir$base_dir$ignore = array()$hidden="off")
  509.     {
  510.         $allfiles $this->dirList($dir,$hidden);
  511.         $struc = array();
  512.         foreach($allfiles as $file)
  513.         {
  514.             if ($this->checkIgnore(basename($file),dirname($file),$ignore)) continue;
  515.             $path substr(dirname($file),strlen(str_replace('\\','/',realpath($base_dir)))+1);
  516.             if (!$path$path '/';
  517.             $parts pathinfo($file);
  518.             if (!isset($parts['extension']))
  519.             {
  520.                 $parts['extension''';
  521.             }
  522.             $struc[$path][= array(
  523.                 'file' => $parts['basename'],
  524.                 'ext' => $parts['extension'],
  525.                 'path' => $file);
  526.         }
  527.         uksort($struc,'strnatcasecmp');
  528.         foreach($struc as $key => $ind)
  529.         {
  530.             usort($ind,'Ioinc_sortfiles');
  531.             $struc[$key$ind;
  532.             $save $key;
  533.             if ($key != '/')
  534.             {
  535.                 $key explode('/',$key);
  536.                 while (count($key))
  537.                 {
  538.                     array_pop($key);
  539.                     if (isset($struc[join('/',$key)]))
  540.                     {
  541.                         $struc[join('/',$key)][substr($save,strlen(join('/',$key)) + 1)$ind;
  542.                         unset($struc[$save]);
  543.                     }
  544.                 }
  545.             }
  546.         }
  547.         foreach($struc as $key => $ind)
  548.         {
  549.             if ($key != '/')
  550.             {
  551.                 if (count(explode('/',$key)) == 1)
  552.                 {
  553.                     $struc['/'][$key$struc[$key];
  554.                     unset($struc[$key]);
  555.                 }
  556.             }
  557.         }
  558.         $tempstruc $struc;
  559.         unset($tempstruc['/']);
  560.         $leftover_dirs array_keys($tempstruc);
  561.         $splitdirs = array();
  562.         foreach($leftover_dirs as $dir)
  563.         {
  564.             $splitdirs[explode('/',$dir);
  565.         }
  566.         $leftover_dirs = array();
  567.  
  568.         foreach($splitdirs as $dir)
  569.         {
  570.             $save join($dir,'/');
  571.             $struc['/'setup_dirs($struc['/']$dir$tempstruc[$save]);
  572.             unset($struc[$save]);
  573.         }
  574.         @uksort($struc['/'],'Ioinc_mystrucsort');
  575.         return $struc;
  576.     }
  577.     
  578.     /**
  579.      * Reads a file and returns it as a string
  580.      * Does basic error checking
  581.      *
  582.      * file extensions are set in {@link phpdoc.inc}
  583.      *
  584.      * @global array PHP File extensions, used to validate that $path is a PHP File
  585.      * @global array PHP File extensions in a CVS repository, used to validate that $path is a PHP File
  586.      * @param    string    $path 
  587.      */
  588.     function readPhpFile($path$quietMode = false)
  589.     {
  590.         global $_phpDocumentor_cvsphpfile_exts$_phpDocumentor_phpfile_exts;
  591.         // tiberiusblue addition
  592.         $cvsExt $_phpDocumentor_cvsphpfile_exts
  593.         $ext $_phpDocumentor_phpfile_exts;
  594.         if (file_exists($path))
  595.         {
  596.             if (is_file($path))
  597.             {
  598.                 // check extension
  599.                 $tmp explode(".",$path);
  600.                 // tiberiusblue addition
  601.                 $tmp2 $tmp;
  602.                 if (in_array(array_pop($tmp),$ext))
  603.                 {
  604.                     phpDocumentor_out(" -- Parsing file\n");
  605.                     flush();
  606.                     if (function_exists('file_get_contents')) {
  607.                         return file_get_contents($path);
  608.                     }
  609.                     $fp fopen($path,"r");
  610.                     $ret fread($fp,filesize($path));
  611.                     fclose($fp);
  612.                     return $ret;
  613.                 elseif (in_array(array_pop($tmp2),$cvsExt)) 
  614.                 
  615.                     phpDocumentor_out(" CVS file [EXPERIMENTAL]\n")
  616.                     flush();
  617.                     if (function_exists('file_get_contents')) {
  618.                         $ret file_get_contents($path);
  619.                     else {
  620.                         $fp fopen($path,"r")
  621.                         $ret fread($fp,filesize($path))
  622.                         fclose($fp)
  623.                     }
  624.                     $ret strstr($ret,"<?");
  625.                     $ret substr($ret,0,strpos($ret,"@\n"));
  626.                     $ret str_replace("@@","@",$ret)
  627.                     return $ret
  628.                 else
  629.                 {
  630.                     phpDocumentor_out(" -- File not parsed, not a php file\n");
  631.                     flush();
  632.                 }
  633.             else {
  634.                 phpDocumentor_out(" -- Unable to read file, not a file\n");
  635.                 flush();
  636.             }
  637.         else {
  638.             phpDocumentor_out(" -- Unable to read file, file does not exist\n");
  639.             flush();
  640.            }
  641.     }
  642.  
  643.     /**
  644.      * Tell whether to ignore a file or a directory
  645.      * allows * and ? wildcards
  646.      *
  647.      * @author Greg Beaver <cellog@users.sourceforge.net>
  648.      * @param    string  $file    just the file name of the file or directory,
  649.      *                           in the case of directories this is the last dir
  650.      * @param    string  $path    the full path
  651.      * @param    array   $ignore 
  652.      * @return   bool    true if $path should be ignored, false if it should not
  653.      */
  654.     function checkIgnore($file,$path,$ignore,$ignore_no_ext = true)
  655.     {
  656.         global $_phpDocumentor_RIC_files;
  657.         $path realpath($path);
  658.         if (!count($ignore)) return false;
  659.         if ($ignore_no_ext && 
  660.             !in_array(strtoupper($file)$_phpDocumentor_RIC_files))
  661.         {
  662.             if (!is_numeric(strpos($file,'.'))) return true;
  663.         }
  664.         if (!isset($this->ignore|| !$this->ignore)
  665.         {
  666.             $this->_setupIgnore($ignore);
  667.             if (!$this->ignore)
  668.             {
  669.                 return false;
  670.             }
  671.         }
  672.         if (is_array($this->ignore))
  673.         {
  674.             foreach($this->ignore as $match)
  675.             {
  676.                 // match is an array if the ignore parameter was a /path/to/pattern
  677.                 if (is_array($match))
  678.                 {
  679.                     // check to see if the path matches with a path delimiter appended
  680.                     preg_match('/^' strtoupper($match[0]).'$/'strtoupper($pathPATH_DELIMITER,$find);
  681.                     if (!count($find))
  682.                     {
  683.                         // check to see if it matches without an appended path delimiter
  684.                         preg_match('/^' strtoupper($match[0]).'$/'strtoupper($path)$find);
  685.                     }
  686.                     if (count($find))
  687.                     {
  688.                         // check to see if the file matches the file portion of the regex string
  689.                         preg_match('/^' strtoupper($match[1]).'$/'strtoupper($file)$find);
  690.                         if (count($find))
  691.                         {
  692.                             return true;
  693.                         }
  694.                     }
  695.                     // check to see if the full path matches the regex
  696.                     preg_match('/^' strtoupper($match[0]).'$/',
  697.                                strtoupper($path . DIRECTORY_SEPARATOR . $file)$find);
  698.                     if (count($find))
  699.                     {
  700.                         return true;
  701.                     }
  702.                 else
  703.                 {
  704.                     // ignore parameter was just a pattern with no path delimiters
  705.                     // check it against the path
  706.                     preg_match('/^' strtoupper($match).'$/'strtoupper($path)$find);
  707.                     if (count($find))
  708.                     {
  709.                         return true;
  710.                     }
  711.                     // check it against the file only
  712.                     preg_match('/^' strtoupper($match).'$/'strtoupper($file)$find);
  713.                     if (count($find))
  714.                     {
  715.                         return true;
  716.                     }
  717.                 }
  718.             }
  719.         }
  720.         return false;
  721.     }
  722.     
  723.     /**
  724.      * Construct the {@link $ignore} array
  725.      * @author Greg Beaver <cellog@users.sourceforge.net>
  726.      * @param array strings of files/paths/wildcards to ignore
  727.      * @access protected
  728.      */
  729.     function _setupIgnore($ignore)
  730.     {
  731.         $ig = array();
  732.         if (is_array($ignore))
  733.         {
  734.             for($i=0; $i<count($ignore);$i++)
  735.             {
  736.                 $ignore[$istrtr($ignore[$i]"\\""/");
  737.                 $ignore[$istr_replace('//','/',$ignore[$i]);
  738.                 if (!empty($ignore[$i]))
  739.                 {
  740.                     if (!is_numeric(strpos($ignore[$i],PATH_DELIMITER)))
  741.                     {
  742.                         $ig[$this->getRegExpableSearchString($ignore[$i]);
  743.                     else
  744.                     {
  745.                         if (basename($ignore[$i]PATH_DELIMITER == $ignore[$i])
  746.                         $ig[$this->getRegExpableSearchString($ignore[$i]);
  747.                         else
  748.                         $ig[= array($this->getRegExpableSearchString($ignore[$i]),$this->getRegExpableSearchString(basename($ignore[$i])));
  749.                     }
  750.                 }
  751.             }
  752.             if (count($ig)) $this->ignore = $ig;
  753.         else $this->ignore = false;
  754.     }
  755.     
  756.     /**
  757.      * Converts $s into a string that can be used with preg_match
  758.      * @param string $s string with wildcards ? and *
  759.      * @author Greg Beaver <cellog@users.sourceforge.net>
  760.      * @return string converts * to .*, ? to ., etc.
  761.      */
  762.     function getRegExpableSearchString($s)
  763.     {
  764.         $y '\/';
  765.         if (DIRECTORY_SEPARATOR == '\\')
  766.         {
  767.             $y '\\\\';
  768.         }
  769.         $s str_replace('/'DIRECTORY_SEPARATOR$s);
  770.         $x strtr($sarray('?' => '.','*' => '.*','.' => '\\.','\\' => '\\\\','/' => '\\/',
  771.                                 '[' => '\\[',']' => '\\]','-' => '\\-'));
  772.         if (strpos($sDIRECTORY_SEPARATOR!== false &&
  773.             strrpos($sDIRECTORY_SEPARATOR=== strlen($s- 1)
  774.         {
  775.             $x = "(?:.*$y$x?.*|$x.*)";
  776.         }
  777.         return $x;
  778.     }
  779.     
  780.     /**
  781.      * Removes files from the $dir array that do not match the search string in
  782.      * $match
  783.      * @param array $dir array of filenames (full path)
  784.      * @param string $match search string with wildcards
  785.      * @author Greg Beaver <cellog@users.sourceforge.net>
  786.      * @return string|arraylisting of every file in a directory that matches
  787.      *                       the search string
  788.      */
  789.     function removeNonMatches($dir$match)
  790.     {
  791.         $match $this->getRegExpableSearchString($match);
  792.         $nodir = false;
  793.         if (!is_array($dir))
  794.         {
  795.             $dir = array($dir);
  796.             $nodir = true;
  797.         }
  798.         foreach($dir as $i => $file)
  799.         {
  800.             preg_match('/^'.$match.'$/',basename($file),$find);
  801.             if (!count($find)) unset($dir[$i]);
  802.         }
  803.         if ($nodirreturn $dir[0];
  804.         return $dir;
  805.     }
  806.     
  807.     /**
  808.      * Take a filename with wildcards and return all files that match the
  809.      * wildcards
  810.      * @param string $file a full path from the -f command-line parameter, with
  811.      *  potential * and ? wildcards.
  812.      * @return mixed if $file contains wildcards, returns an array of matching
  813.      *                files, otherwise returns false
  814.      * @author Greg Beaver <cellog@users.sourceforge.net>
  815.      */
  816.     function getAllFiles($file)
  817.     {
  818.         $path realpath(dirname($file));
  819.         $file basename($file);
  820.         // any wildcards?
  821.         if (is_numeric(strpos($file,'?')) || is_numeric(strpos($file,'*')))
  822.         {
  823.             $files $this->dirList($path);
  824.             $a $this->removeNonMatches($files,$file);
  825.             return $a;
  826.         }
  827.         return false;
  828.     }
  829. }
  830.  
  831. /**#@+
  832.  * Sorting functions for the file list
  833.  * @param string
  834.  * @param string
  835.  */
  836. function Ioinc_sortfiles($a$b)
  837. {
  838.     return strnatcasecmp($a['file'],$b['file']);
  839. }
  840.  
  841. function Ioinc_mystrucsort($a$b)
  842. {
  843.     if (is_numeric($a&& is_string($b)) return 1;
  844.     if (is_numeric($b&& is_string($a)) return -1;
  845.     if (is_numeric($a&& is_numeric($b))
  846.     {
  847.         if ($a $breturn 1;
  848.         if ($a $breturn -1;
  849.         if ($a == $breturn 0;
  850.     }
  851.     return strnatcasecmp($a,$b);
  852. }
  853. /**#@-*/
  854.  
  855. /**
  856.  * Recursively add all the subdirectories of $contents to $dir without erasing anything in
  857.  * $dir
  858.  * @param array 
  859.  * @param array 
  860.  * @return array processed $dir
  861.  */
  862. function set_dir($dir,$contents)
  863. {
  864.     while(list($one,$twoeach($contents))
  865.     {
  866.         if (isset($dir[$one]))
  867.         {
  868.             $dir[$oneset_dir($dir[$one],$contents[$one]);
  869.         else $dir[$one$two;
  870.     }
  871.     return $dir;
  872. }
  873.  
  874. /**
  875.  * Recursively move contents of $struc into associative array
  876.  *
  877.  * The contents of $struc have many indexes like 'dir/subdir/subdir2'.
  878.  * This function converts them to
  879.  * array('dir' => array('subdir' => array('subdir2')))
  880.  * @param array struc is array('dir' => array of files in dir,'dir/subdir' => array of files in dir/subdir,...)
  881.  * @param array array form of 'dir/subdir/subdir2' array('dir','subdir','subdir2')
  882.  * @return array same as struc but with array('dir' => array(file1,file2,'subdir' => array(file1,...)))
  883.  */
  884. function setup_dirs($struc,$dir,$contents)
  885. {
  886.     if (!count($dir))
  887.     {
  888.         foreach($contents as $dir => $files)
  889.         {
  890.             if (is_string($dir))
  891.             {
  892.                 if (strpos($dir,'/'))
  893.                 {
  894.                     $test = true;
  895.                     $a $contents[$dir];
  896.                     unset($contents[$dir]);
  897.                     $b explode('/',$dir);
  898.                     $c array_shift($b);
  899.                     if (isset($contents[$c]))
  900.                     {
  901.                         $contents[$cset_dir($contents[$c],setup_dirs(array(),$b,$a));
  902.                     else $contents[$csetup_dirs(array(),$b,$a);
  903.                 }
  904.             }
  905.         }
  906.         return $contents;
  907.     }
  908.     $me array_shift($dir);
  909.     if (!isset($struc[$me])) $struc[$me= array();
  910.     $struc[$mesetup_dirs($struc[$me],$dir,$contents);
  911.     return $struc;
  912. }
  913.  
  914. if (!function_exists('get_include_path')) {
  915. function get_include_path()
  916. {
  917.     return ini_get('include_path');
  918. }
  919. }
  920. ?>

Documentation generated on Mon, 11 Mar 2019 14:58:52 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.