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.     /**
  22.     * Start the tool
  23.     *
  24.     * @static
  25.     */
  26.     function run()
  27.     {
  28.         $args $GLOBALS['argv'];
  29.         array_shift($args);
  30.         new HTML_Template_PHPLIB_Tool($args);
  31.     }//function run()
  32.  
  33.  
  34.  
  35.     /**
  36.     * Returns the action to execute
  37.     *
  38.     * @param array &$args Array of command line arguments
  39.     *
  40.     * @return string Action to execute
  41.     */
  42.     function getAction(&$args)
  43.     {
  44.         if (count($args== 0{
  45.             return 'help';
  46.         }
  47.         $arg array_shift($args);
  48.         switch ($arg{
  49.         case 'v':
  50.         case 'validate':
  51.         case '-v':
  52.         case '--validate':
  53.             return 'validate';
  54.         case 'g':
  55.         case 'generate':
  56.         case '-g':
  57.         case '--generate':
  58.             return 'generate';
  59.         default:
  60.             return 'help';
  61.         }
  62.     }//function getAction(&$args)
  63.  
  64.  
  65.  
  66.     /**
  67.     * Echoes the message and exist php with the given
  68.     *  exit code
  69.     *
  70.     * @param string $strMessage Message to display
  71.     * @param int    $nExitCode  Exit code
  72.     *
  73.     * @return void 
  74.     */
  75.     function dieHard($strMessage$nExitCode)
  76.     {
  77.         echo $strMessage;
  78.         exit($nExitCode);
  79.     }//function dieHard($strMessage, $nExitCode)
  80.  
  81.  
  82.  
  83.     /**
  84.     * Prints the help message to stdout
  85.     *
  86.     * @return void 
  87.     */
  88.     function doHelp()
  89.     {
  90.         echo <<<EOT
  91. Usage: html_template_phplibtool action parameters
  92.  
  93. Tool to validate and work with HTML templates
  94.  
  95. mode: (- and -- are optional)
  96.  h,  help      Show this help screen
  97.  g,  generate  Generate PHP code for the template
  98.  v,  validate  Validate a template file
  99.  
  100. EOT;
  101.     }//function doHelp()
  102.  
  103.  
  104.  
  105.     /**
  106.     * Validates the files given on the cmdline
  107.     *
  108.     * @param array $args Command line arguments (files)
  109.     *
  110.     * @return void 
  111.     */
  112.     function doValidate($args)
  113.     {
  114.         if (count($args== 0{
  115.             $this->dieHard("No template files to validate\n"1);
  116.         }
  117.  
  118.         require_once 'HTML/Template/PHPLIB/Validator.php';
  119.         $nError = 0;
  120.         foreach ($args as $file{
  121.             if (file_exists($file)) {
  122.                 $arErrors HTML_Template_PHPLIB_Validator::validate($file);
  123.                 if ($arErrors === true{
  124.                     echo 'No errors found in ' $file "\n";
  125.                     $nError =  0;
  126.                 else if ($arErrors === false{
  127.                     echo 'Some unexpected error in ' $file "\n";
  128.                     $nError =  3;
  129.                 else {
  130.                     echo count($arErrors' errors in ' $file "\n";
  131.                     foreach ($arErrors as $arError{
  132.                         echo ' Line #' $arError['line'': ' $arError['message'"\n";
  133.                     }
  134.                     $nError = 10;
  135.                 }
  136.             else {
  137.                 echo 'File does not exist: ' $file "\n";
  138.                 $nError = 4;
  139.             }
  140.         }
  141.         $this->dieHard(''$nError);
  142.     }//function doValidate($args)
  143.  
  144.  
  145.  
  146.     /**
  147.     * Generates PHP code for the given template file
  148.     *
  149.     * @param array $args Command line arguments
  150.     *
  151.     * @return void 
  152.     */
  153.     function doGenerate($args)
  154.     {
  155.         if (count($args== 0{
  156.             $this->dieHard("No template file given\n"1);
  157.         }
  158.  
  159.         $strFile $args[0];
  160.         require_once 'HTML/Template/PHPLIB/Generator.php';
  161.             $strFile
  162.         );
  163.  
  164.         $this->dieHard($strCode0);
  165.     }//function doGenerate($args)
  166.  
  167. }//class HTML_Template_PHPLIB_Tool
  168.  
  169. ?>

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