home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / PHP / Beautifier / Batch / Output / Files.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  3.1 KB  |  86 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * PHP_Beautifier_Batch_Files
  5. * Handle the batch process for one/multiple php files to one out
  6. *
  7. * PHP version 5
  8. *
  9. * LICENSE: This source file is subject to version 3.0 of the PHP license
  10. * that is available through the world-wide-web at the following URI:
  11. * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  12. * the PHP License and are unable to obtain it through the web, please
  13. * send a note to license@php.net so we can mail you a copy immediately.
  14. * @category   PHP
  15. * @package PHP_Beautifier
  16. * @subpackage Batch
  17. * @author Claudio Bustos <cdx@users.sourceforge.com>
  18. * @copyright  2004-2006 Claudio Bustos
  19. * @link     http://pear.php.net/package/PHP_Beautifier
  20. * @link     http://beautifyphp.sourceforge.net
  21. * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  22. * @version    CVS: $Id:$
  23. */
  24. /**
  25. * PHP_Beautifier_Batch_Files
  26. * Handle the batch process for one/multiple php files to one out
  27. *
  28. * @category   PHP
  29. * @package PHP_Beautifier
  30. * @author Claudio Bustos <cdx@users.sourceforge.com>
  31. * @copyright  2004-2006 Claudio Bustos
  32. * @link     http://pear.php.net/package/PHP_Beautifier
  33. * @link     http://beautifyphp.sourceforge.net
  34. * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  35. * @version    Release: 0.1.14
  36. */
  37. class PHP_Beautifier_Batch_Output_Files extends PHP_Beautifier_Batch_Output {
  38.     public function get() 
  39.     {
  40.         $aInputFiles = $this->oBatch->getInputFiles();
  41.         if (count($aInputFiles) == 1) {
  42.             $this->beautifierSetInputFile(reset($aInputFiles));
  43.             $this->beautifierProcess();
  44.             return $this->beautifierGet();
  45.         } else {
  46.             $sText = '';
  47.             foreach($aInputFiles as $sFile) {
  48.                 $this->beautifierSetInputFile($sFile);
  49.                 $this->beautifierProcess();
  50.                 $sText.= $this->getWithHeader($sFile);
  51.             }
  52.             return $sText;
  53.         }
  54.     }
  55.     private function getWithHeader($sFile) 
  56.     {
  57.         $sNewLine = $this->oBatch->callBeautifier($this, 'getNewLine');
  58.         $sHeader = '- BEGIN OF '.$sFile.' -'.$sNewLine;
  59.         $sLine = str_repeat('-', strlen($sHeader) -1) .$sNewLine;
  60.         $sEnd = '- END OF '.$sFile.str_repeat(' ', strlen($sHeader) -strlen($sFile) -12) .' -'.$sNewLine;
  61.         $sText = $sLine.$sHeader.$sLine.$sNewLine;
  62.         $sText.= $this->beautifierGet();
  63.         $sText.= $sNewLine.$sLine.$sEnd.$sLine.$sNewLine;
  64.         return $sText;
  65.     }
  66.     public function save() 
  67.     {
  68.         $bCli = php_sapi_name() == 'cli';
  69.         $sFile = $this->oBatch->getOutputPath();
  70.         if ($bCli and $sFile == STDOUT) {
  71.             $fp = STDOUT;
  72.         } else {
  73.             $fp = fopen($this->oBatch->getOutputPath() , "w");
  74.         }
  75.         if (!$fp) {
  76.             throw (new Exception("Can't save file $sFile"));
  77.         }
  78.         $sText = $this->get();
  79.         fputs($fp, $sText, strlen($sText));
  80.         if (!($bCli and $fp == STDOUT)) {
  81.             fclose($fp);
  82.         }
  83.         return true;
  84.     }
  85. }
  86. ?>