home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Web Server / PHP.EXE / pear / PHPDoc / core / PhpdocSetupHandler.php < prev   
Encoding:
PHP Script  |  2001-02-18  |  6.7 KB  |  217 lines

  1. <?php
  2. /**
  3. * Handles the "setup".
  4. *
  5. * This class provides all methods neccessary to "setup" Phpdoc and check the 
  6. * current setup.
  7. * @version  $Id: PhpdocSetupHandler.php,v 1.6 2001/02/18 15:29:29 uw Exp $
  8. * @author   Ulf Wendel <ulf@redsys.de>
  9. */
  10. class PhpdocSetupHandler extends PhpdocArgvHandler {
  11.  
  12.     /**
  13.     * Name of the target directory.
  14.     *
  15.     * @var      string  $target
  16.     * @access   private
  17.     */                                
  18.     var $target = "";    
  19.     
  20.     /**
  21.     * Name of the application parsed
  22.     *
  23.     * @var  string  $application
  24.     * @see  setApplication()
  25.     */
  26.     var $application = "PHPDoc";
  27.     
  28.     /**
  29.     * Basedir for all file operations
  30.     *
  31.     * @var  string
  32.     * @see  setApplication()
  33.     */
  34.     var $basedir = "";
  35.     
  36.     /**
  37.     * Suffix for all rendered files in the application (except for the xml files).
  38.     *
  39.     * @var  string  targetFileSuffix
  40.     * @see  setTargetFileSuffix()
  41.     */
  42.     var    $targetFileSuffix = ".html";
  43.     
  44.     /**
  45.     * Suffix of all source code files in the application
  46.     *
  47.     * If you used other file suffixes than ".php" in you have to override this.
  48.     *
  49.     * @var  array    sourceFileSuffix
  50.     * @see  setSourceFileSuffix()
  51.     */
  52.     var    $sourceFileSuffix = array ( "php" );
  53.     
  54.     /**
  55.     * Directory with the php sources to parse.
  56.     *
  57.     * @var   string    
  58.     * @see   setSourceDirectory()
  59.     */
  60.     var $sourceDirectory = "";    
  61.     
  62.     /**
  63.     * Sets the name of the directory with the source to scan.
  64.     *
  65.     * @param    string
  66.     * @access   public
  67.     */
  68.     function setSourceDirectory($sourcedir) {
  69.         $this->sourceDirectory = $this->getCheckedDirname($sourcedir);
  70.     } // end end func setSourceDirectory
  71.     
  72.     /**
  73.     * Sets the name of the directory with the templates.
  74.     *
  75.     * @param    string
  76.     * @access   public
  77.     */
  78.     function setTemplateDirectory($sourcedir) {
  79.         $this->templateRoot = $this->getCheckedDirname($sourcedir);
  80.     } // end func setTemplateDirectory
  81.     
  82.     /**
  83.     * Sets the name of your application. 
  84.     * 
  85.     * The application name gets used on many places in the default templates.
  86.     * 
  87.     * @param    string      $application    name of the application
  88.     * @return   bool        $ok
  89.     * @throws   PhpdocError    
  90.     * @access   public
  91.     */    
  92.     function setApplication($application) {
  93.         if ("" == $application) {
  94.             $this->err[] = new PhpdocError("No application name given.", __FILE__, __LINE__);
  95.             return false;
  96.         }
  97.         
  98.         $this->application = $application;
  99.         return true;
  100.     } // end func setApplication
  101.     
  102.     /**
  103.     * Suffix for all rendered files in the application (not for the xml files)
  104.     *
  105.     * By default the the suffix is set to ".html".
  106.     *
  107.     * @param    string  $suffix string with the suffix
  108.     * @return   boolean $ok
  109.     * @see      $targetFileSuffix
  110.     * @author   Thomas Weinert <subjective@subjective.de>
  111.     */
  112.     function setTargetFileSuffix($suffix) {
  113.         if ("" != $suffix && "." != $suffix[0]) {
  114.             $this->err[] = new PhpdocError("Make sure that the file extension starts with a dot.", __FILE__, __LINE__);
  115.             return false; 
  116.         }
  117.         
  118.         $this->targetFileSuffix = $suffix;
  119.         return true;
  120.     }
  121.  
  122.     /**
  123.     * Suffix of all source code files in the application
  124.     *
  125.     * By default only files with the suffix ".php" are recognized as
  126.     * php source code files and parsed. If you used other
  127.     * suffixes such as ".inc" you have to tell phpdoc to parse
  128.     * them.
  129.     *
  130.     * @param    mixed   $suffix        string with one suffix or array of suffixes
  131.     * @return   boolean $ok
  132.     * @throws   PhpdocError
  133.     * @see      $sourceFileSuffix
  134.     */
  135.     function setSourceFileSuffix($suffix) {
  136.         if ( (!is_array($suffix) && "" == $suffix) || (is_array($suffix) && 0 == count($suffix)) ) {
  137.             $this->err[] = new PhpdocError("No suffix specified.", __FILE__, __LINE__);
  138.             return false;
  139.         }
  140.         if (!is_array($suffix)) 
  141.             $suffix = array($suffix);        
  142.         
  143.         $this->sourceFileSuffix = $suffix;    
  144.         return true;
  145.     } // end func setSourceFileSuffix
  146.  
  147.     /**
  148.     * Sets the target where the generated files are saved.
  149.     * 
  150.     * @param    string  $target
  151.     * @return   boolean $ok 
  152.     * @throws   PhpdocError
  153.     * @access   public
  154.     */
  155.     function setTarget($target) {
  156.         if ("" == $target) {
  157.             $this->err[] = new PhpdocError("No target specified.", __FILE__, __LINE__);
  158.             return false;
  159.         }
  160.         
  161.         if (!is_dir($target)) {
  162.             $ok = mkdir($target, 0755);
  163.             if (!$ok) {
  164.                 $this->err[] = new PhpdocError("setTarget(), can't create a directory '$target'.", __FILE__, __LINE__);
  165.                 return false;
  166.             }
  167.         }
  168.             
  169.         $this->target = $this->getCheckedDirname($target);
  170.         return true;
  171.     } // end func setTarget
  172.  
  173.     /**
  174.     * Checks the current status of the object. Are all necessary informations to start parsing available?
  175.     *
  176.     * @param    mixed   $errors
  177.     * @return   array   $errors
  178.     */
  179.     function checkStatus($errors = "") {
  180.         if (!is_array($errors))
  181.             $errors = array();
  182. /*
  183.                 
  184.         if (0==count($this->files) && ""==$this->directory) 
  185.             $errors[] = array (
  186.                                                     "msg"     => "No source files or source directory specified.",
  187.                                                     "type"    => "misconfiguration",
  188.                                                     "errno"    => 6
  189.                                                 );
  190.                                                 
  191.         if (0!=count($this->files) && ""!=$this->directory) 
  192.             $errors[] = array(
  193.                                                     "msg"        => "Define eighter some files or a diretory.",
  194.                                                     "type"    => "misconfiguration",
  195.                                                     "errno"    => 7
  196.                                             );
  197.     */    
  198.         return $errors;
  199.     } // end func checkStatus
  200.     
  201.     /**
  202.     * Adds a slash at the end of the given filename if neccessary.
  203.     *
  204.     * @param    string    Directoryname
  205.     * @return    string    Directoryname
  206.     */
  207.     function getCheckedDirname($dirname) {
  208.  
  209.         if ("" != $dirname && "/" != substr($dirname, -1)) 
  210.             $dirname .= "/";
  211.             
  212.         return $dirname;
  213.     } // end func getCheckedDirname
  214.  
  215. } // end class PhpdocSetupHandler
  216. ?>