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

Source for file Tool.php

Documentation is available at Tool.php

  1. <?php
  2.  
  3. /**
  4. * Command line tool to use the HTML_Template_PHPLIB validator and generator.
  5. *
  6. @category HTML
  7. @package HTML_Template_PHPLIB
  8. @author   Christian Weiske <cweiske@php.net>
  9. @license  http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
  10. @link     http://pear.php.net/package/HTML_Template_PHPLIB
  11. */
  12. {
  13.     function HTML_Template_PHPLIB_Tool($args)
  14.     {
  15.         $strAction $this->getAction($args);
  16.         $this->{'do' ucfirst($strAction)}($args);        
  17.     }//function HTML_Template_PHPLIB_Tool($args)
  18.     
  19.     
  20.     
  21.     function getAction(&$args)
  22.     {
  23.         if (count($args== 0{
  24.             return 'help';
  25.         }
  26.         $arg array_shift($args);
  27.         switch ($arg{
  28.         case 'v':
  29.         case 'validate':
  30.         case '-v':
  31.         case '--validate':
  32.             return 'validate';
  33.         default:
  34.             return 'help';
  35.         }
  36.     }//function getAction(&$args)
  37.     
  38.     
  39.     
  40.     function dieHard($strMessage$nExitCode)
  41.     {
  42.         echo $strMessage;
  43.         exit($nExitCode);
  44.     }//function dieHard($strMessage, $nExitCode)
  45.     
  46.     
  47.     
  48.     function doHelp()
  49.     {
  50.         echo <<<EOT
  51. Usage: html_template_phplibtool action parameters
  52.  
  53. Tool to validate and work with HTML templates
  54.  
  55. mode: (- and -- are optional)
  56.  h,  help      Show this help screen
  57.  v,  validate  Validate a template file
  58.  
  59. EOT;
  60.     }//function doHelp()
  61.     
  62.     
  63.     
  64.     function doValidate($args)
  65.     {
  66.         if (count($args== 0{
  67.             $this->dieHard("No template files to validate\n"1);
  68.         }
  69.         
  70.         require_once 'HTML/Template/PHPLIB/Validator.php';
  71.         $nError = 0;
  72.         foreach ($args as $file{
  73.             if (file_exists($file)) {
  74.                 $arErrors HTML_Template_PHPLIB_Validator::validate($file);
  75.                 if ($arErrors === true{
  76.                     echo 'No errors found in ' $file "\n";
  77.                     $nError =  0;
  78.                 else if ($arErrors === false{
  79.                     echo 'Some unexpected error in ' $file "\n";
  80.                     $nError =  3;
  81.                 else {
  82.                     echo count($arErrors' errors in ' $file "\n";
  83.                     foreach ($arErrors as $arError{
  84.                         echo ' Line #' $arError['line'': ' $arError['message'"\n";
  85.                     }
  86.                     $nError = 10;
  87.                 }
  88.             else {
  89.                 echo 'File does not exist: ' $file "\n";
  90.                 $nError = 4;
  91.             }
  92.         }
  93.         $this->dieHard(''$nError);
  94.     }//function doValidate($args)
  95.  
  96.  
  97.  
  98.     /**
  99.     * Start the tool
  100.     *
  101.     * @static
  102.     */
  103.     function run()
  104.     {
  105.         $args $GLOBALS['argv'];
  106.         array_shift($args);
  107.         new HTML_Template_PHPLIB_Tool($args);        
  108.     }//function run()
  109.  
  110. }//class HTML_Template_PHPLIB_Tool
  111.  
  112. ?>

Documentation generated on Mon, 11 Mar 2019 15:10:07 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.