├── .gitignore ├── Beautifier.php ├── Beautifier ├── Batch.php ├── Batch │ ├── Output.php │ └── Output │ │ ├── Directory.php │ │ ├── DirectoryBz2.php │ │ ├── DirectoryGz.php │ │ ├── DirectoryTar.php │ │ ├── Files.php │ │ ├── FilesBz2.php │ │ ├── FilesGz.php │ │ └── FilesTar.php ├── Common.php ├── Decorator.php ├── Exception.php ├── Filter.php ├── Filter │ ├── ArrayNested.filter.php │ ├── BreakLongLists.filter.php │ ├── Default.filter.php │ ├── DocBlock.filter.php │ ├── EqualsAlign.filter.php │ ├── Fluent.filter.php │ ├── IndentStyles.filter.php │ ├── KeepEmptyLines.filter.php │ ├── ListClassFunction.filter.php │ ├── Lowercase.filter.php │ ├── NewLines.filter.php │ ├── Pear.filter.php │ ├── SpaceOpAssignments.filter.php │ └── phpBB.filter.php ├── StreamWrapper.php ├── StreamWrapper │ └── Tarz.php └── Tokenizer.php ├── Doc_PHP_Beautifier.ini ├── README.txt ├── Rakefile ├── composer.json ├── crear_phps.sh ├── examples ├── README ├── example.js ├── example_array.php ├── example_comments.php ├── example_html.php ├── example_lowercase.php ├── example_main.php ├── example_pear.php ├── heredoc_test.php ├── log.txt └── run_me.php ├── licenses ├── apache.txt ├── bsd.txt ├── lgpl.txt ├── pear.txt └── php.txt ├── package2.xml ├── scripts ├── php_beautifier └── php_beautifier.bat ├── site ├── button-php_beautifier.png ├── demo │ └── index.php ├── example.phps ├── example_callbacks.php ├── example_output.phps ├── index.php ├── style.css ├── uml │ ├── PackageOverviewbatch.jpg │ ├── PackageOverviewbeautifier.jpg │ ├── PackageOverviewpear.jpg │ ├── PackageOverviewstreamwrapper.jpg │ ├── PackageOverwievphp.jpg │ └── PackagePHP_Beautifier.jpg └── view_source.php ├── tests ├── Beautifier │ ├── Beautifier.tar.bz2 │ ├── Beautifier.tar.gz │ ├── Filter │ │ ├── ArrayNestedTest.php │ │ ├── DocBlockTest.php │ │ ├── IndentStylesTest.php │ │ ├── PearTest.php │ │ ├── arraynested_sample_file.phps │ │ ├── docblock_sample_file.phps │ │ ├── indentstyles_bsd_sample_file.phps │ │ ├── indentstyles_gnu_sample_file.phps │ │ ├── indentstyles_kr_sample_file.phps │ │ ├── indentstyles_ws_sample_file.phps │ │ └── pear_sample_file.phps │ └── StreamWrapperTest.php ├── BeautifierBugsTest.php ├── BeautifierCommonTest.php ├── BeautifierInternalTest.php ├── BeautifierTest.php └── Helpers.php ├── tutorials ├── PHP_Beautifier │ ├── .htaccess │ ├── Batch │ │ └── Batch.cls │ ├── Filter │ │ ├── Filter.create.pkg │ │ ├── Filter2.pkg │ │ └── Filter2.pkg.ini │ ├── PHP_Beautifier.callbacks.pkg │ ├── PHP_Beautifier.howtouse.commandline.pkg │ ├── PHP_Beautifier.howtouse.pkg │ ├── PHP_Beautifier.howtouse.pkg.ini │ ├── PHP_Beautifier.howtouse.script.pkg │ ├── PHP_Beautifier.pkg │ └── PHP_Beautifier.pkg.ini ├── doc2html.bat └── html2doc.bat └── uml ├── PHP_Beautifier.dia ├── PHP_Beautifier.xmi ├── PHP_Beautifier.zargo ├── PHP_Beautifier.zuml ├── PHP_Beautifier.zuml.bak.0 ├── PHP_Beautifier.zuml.bak.1 ├── PHP_Beautifier.zuml.bak.2 ├── PHP_Beautifier.zuml.bak.3 └── PHP_Beautifier.zuml.bak.4 /.gitignore: -------------------------------------------------------------------------------- 1 | docs/* 2 | site/docs 3 | *.log 4 | create_doc 5 | subir_sitio 6 | *~ 7 | pkg 8 | *.tgz 9 | *.phar 10 | composer.lock 11 | /vendor 12 | /bin 13 | 14 | -------------------------------------------------------------------------------- /Beautifier/Batch/Output.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2004-2010 Claudio Bustos 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version CVS: $Id:$ 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://beautifyphp.sourceforge.net 23 | */ 24 | /** 25 | * Abstract class to superclass all batch class 26 | * 27 | * @category PHP 28 | * @package PHP_Beautifier 29 | * @author Claudio Bustos 30 | * @copyright 2004-2010 Claudio Bustos 31 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 32 | * @version Release: @package_version@ 33 | * @link http://pear.php.net/package/PHP_Beautifier 34 | * @link http://beautifyphp.sourceforge.net 35 | */ 36 | abstract class PHP_Beautifier_Batch_Output 37 | { 38 | protected $oBatch; 39 | /** 40 | * __construct 41 | * 42 | * @param PHP_Beautifier_Batch $oBatch PHP_Beautifier_Batch Object 43 | * 44 | * @access public 45 | * @return void 46 | */ 47 | public function __construct(PHP_Beautifier_Batch $oBatch) 48 | { 49 | $this->oBatch = $oBatch; 50 | } 51 | /** 52 | * beautifierSetInputFile 53 | * 54 | * @param mixed $sFile Input file 55 | * 56 | * @access protected 57 | * @return void 58 | */ 59 | protected function beautifierSetInputFile($sFile) 60 | { 61 | return $this->oBatch->callBeautifier( 62 | $this, 63 | 'setInputFile', 64 | array($sFile) 65 | ); 66 | } 67 | /** 68 | * beautifierProcess 69 | * 70 | * @access protected 71 | * @return void 72 | */ 73 | protected function beautifierProcess() 74 | { 75 | return $this->oBatch->callBeautifier($this, 'process'); 76 | } 77 | /** 78 | * beautifierGet 79 | * 80 | * @access protected 81 | * @return void 82 | */ 83 | protected function beautifierGet() 84 | { 85 | return $this->oBatch->callBeautifier($this, 'get'); 86 | } 87 | /** 88 | * beautifierSave 89 | * 90 | * @param mixed $sFile Output file 91 | * 92 | * @access protected 93 | * @return void 94 | */ 95 | protected function beautifierSave($sFile) 96 | { 97 | return $this->oBatch->callBeautifier( 98 | $this, 99 | 'save', 100 | array($sFile) 101 | ); 102 | } 103 | /** 104 | * get 105 | * 106 | * @access public 107 | * @return void 108 | */ 109 | public function get() 110 | { 111 | } 112 | /** 113 | * save 114 | * 115 | * @access public 116 | * @return void 117 | */ 118 | public function save() 119 | { 120 | } 121 | } 122 | ?> 123 | -------------------------------------------------------------------------------- /Beautifier/Batch/Output/Directory.php: -------------------------------------------------------------------------------- 1 | 19 | * @copyright 2004-2010 Claudio Bustos 20 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 21 | * @version CVS: $Id:$ 22 | * @link http://pear.php.net/package/PHP_Beautifier 23 | * @link http://beautifyphp.sourceforge.net 24 | */ 25 | /** 26 | * PHP_Beautifier_Batch_Files 27 | * Handle the batch process for multiple php files to one directory 28 | * 29 | * @category PHP 30 | * @package PHP_Beautifier 31 | * @author Claudio Bustos 32 | * @copyright 2004-2010 Claudio Bustos 33 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 34 | * @version Release: @package_version@ 35 | * @link http://pear.php.net/package/PHP_Beautifier 36 | * @link http://beautifyphp.sourceforge.net 37 | */ 38 | class PHP_Beautifier_Batch_Output_Directory extends PHP_Beautifier_Batch_Output 39 | { 40 | /** 41 | * save 42 | * 43 | * @access public 44 | * @return bool 45 | */ 46 | public function save() 47 | { 48 | $aInputFiles = $this->oBatch->getInputFiles(); 49 | $sOutputPath = $this->oBatch->getOutputPath(); 50 | $aOutputFiles = PHP_Beautifier_Common::getSavePath($aInputFiles, $sOutputPath); 51 | $oLog = PHP_Beautifier_Common::getLog(); 52 | for ($x = 0;$xbeautifierSetInputFile($aInputFiles[$x]); 55 | $this->beautifierProcess(); 56 | PHP_Beautifier_Common::createDir($aOutputFiles[$x]); 57 | $this->beautifierSave($aOutputFiles[$x]); 58 | } 59 | catch(Exception $oExp) { 60 | $oLog->log($oExp->getMessage(), PEAR_LOG_ERR); 61 | } 62 | } 63 | return true; 64 | } 65 | 66 | /** 67 | * Send the output of the files, one after another 68 | * With a little header 69 | * 70 | * @access public 71 | * @return string 72 | */ 73 | public function get() 74 | { 75 | $aInputFiles = $this->oBatch->getInputFiles(); 76 | $sText = ''; 77 | foreach ($aInputFiles as $sFile) { 78 | $this->beautifierSetInputFile($sFile); 79 | $this->beautifierProcess(); 80 | $sText.= $this->beautifierGet()."\n"; 81 | } 82 | return $sText; 83 | } 84 | } 85 | ?> 86 | -------------------------------------------------------------------------------- /Beautifier/Batch/Output/DirectoryBz2.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2004-2010 Claudio Bustos 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version CVS: $Id:$ 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://beautifyphp.sourceforge.net 23 | */ 24 | /** 25 | * Include PHP_Beautifier_Batch_DirectoryTar 26 | */ 27 | require_once 'DirectoryTar.php'; 28 | /** 29 | * PHP_Beautifier_Batch_FilesGz 30 | * 31 | * Compress all the files to one bz2 file 32 | * 33 | * @category PHP 34 | * @package PHP_Beautifier 35 | * @subpackage Batch 36 | * @author Claudio Bustos 37 | * @copyright 2004-2010 Claudio Bustos 38 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 39 | * @version Release: @package_version@ 40 | * @link http://pear.php.net/package/PHP_Beautifier 41 | * @link http://beautifyphp.sourceforge.net 42 | */ 43 | class PHP_Beautifier_Batch_Output_DirectoryBz2 extends PHP_Beautifier_Batch_DirectoryTar 44 | { 45 | /** 46 | * getTar 47 | * 48 | * @param mixed $sFileName File name 49 | * 50 | * @access protected 51 | * @return void 52 | */ 53 | protected function getTar($sFileName) 54 | { 55 | return new Archive_Tar($sFileName.'.tar.bz2', 'bz2'); 56 | } 57 | } 58 | ?> 59 | -------------------------------------------------------------------------------- /Beautifier/Batch/Output/DirectoryGz.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2004-2010 Claudio Bustos 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version CVS: $Id:$ 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://beautifyphp.sourceforge.net 23 | */ 24 | /** 25 | * Include PHP_Beautifier_Batch_DirectoryTar 26 | */ 27 | require_once 'DirectoryTar.php'; 28 | /** 29 | * PHP_Beautifier_Batch_FilesGz 30 | * 31 | * Compress all the files to one tgz file 32 | * 33 | * @category PHP 34 | * @package PHP_Beautifier 35 | * @subpackage Batch 36 | * @author Claudio Bustos 37 | * @copyright 2004-2010 Claudio Bustos 38 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 39 | * @version Release: @package_version@ 40 | * @link http://pear.php.net/package/PHP_Beautifier 41 | * @link http://beautifyphp.sourceforge.net 42 | */ 43 | class PHP_Beautifier_Batch_Output_DirectoryGz extends PHP_Beautifier_Batch_Output_DirectoryTar 44 | { 45 | /** 46 | * getTar 47 | * 48 | * @param mixed $sFileName File name 49 | * 50 | * @access protected 51 | * @return void 52 | */ 53 | protected function getTar($sFileName) 54 | { 55 | return new Archive_Tar($sFileName.'.tgz', 'gz'); 56 | } 57 | } 58 | ?> 59 | -------------------------------------------------------------------------------- /Beautifier/Batch/Output/DirectoryTar.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2004-2010 Claudio Bustos 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version CVS: $Id:$ 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://beautifyphp.sourceforge.net 23 | */ 24 | /** 25 | * Include Archive_Tar 26 | */ 27 | require_once 'Archive/Tar.php'; 28 | /** 29 | * PHP_Beautifier_Batch_FilesGz 30 | * 31 | * Manage compression of many files to one compressed file (gz or bz2) 32 | * 33 | * @category PHP 34 | * @package PHP_Beautifier 35 | * @subpackage Batch 36 | * @author Claudio Bustos 37 | * @copyright 2004-2010 Claudio Bustos 38 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 39 | * @version Release: @package_version@ 40 | * @link http://pear.php.net/package/PHP_Beautifier 41 | * @link http://beautifyphp.sourceforge.net 42 | */ 43 | abstract class PHP_Beautifier_Batch_Output_DirectoryTar extends PHP_Beautifier_Batch_Output 44 | { 45 | /** 46 | * save 47 | * 48 | * @access public 49 | * @return void 50 | */ 51 | public function save() 52 | { 53 | $aInputFiles = $this->oBatch->getInputFiles(); 54 | $sOutputPath = $this->oBatch->getOutputPath(); 55 | $aOutputFiles = PHP_Beautifier_Common::getSavePath($aInputFiles, $sOutputPath); 56 | for ($x = 0;$xgetTar($aOutputFiles[$x]); 59 | $this->beautifierSetInputFile($aInputFiles[$x]); 60 | $this->beautifierProcess(); 61 | PHP_Beautifier_Common::createDir($aOutputFiles[$x]); 62 | $oTar->addString(basename($aOutputFiles[$x]), $this->beautifierGet()); 63 | } 64 | return true; 65 | } 66 | 67 | /** 68 | * getTar 69 | * 70 | * @param mixed $sFileName File name 71 | * 72 | * @todo implements this 73 | * @access protected 74 | * @return void 75 | */ 76 | protected function getTar($sFileName) 77 | { 78 | } 79 | } 80 | ?> 81 | -------------------------------------------------------------------------------- /Beautifier/Batch/Output/Files.php: -------------------------------------------------------------------------------- 1 | 19 | * @copyright 2004-2010 Claudio Bustos 20 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 21 | * @version CVS: $Id:$ 22 | * @link http://pear.php.net/package/PHP_Beautifier 23 | * @link http://beautifyphp.sourceforge.net 24 | */ 25 | /** 26 | * PHP_Beautifier_Batch_Files 27 | * Handle the batch process for one/multiple php files to one out 28 | * 29 | * @category PHP 30 | * @package PHP_Beautifier 31 | * @author Claudio Bustos 32 | * @copyright 2004-2010 Claudio Bustos 33 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 34 | * @version Release: @package_version@ 35 | * @link http://pear.php.net/package/PHP_Beautifier 36 | * @link http://beautifyphp.sourceforge.net 37 | */ 38 | class PHP_Beautifier_Batch_Output_Files extends PHP_Beautifier_Batch_Output 39 | { 40 | /** 41 | * get 42 | * 43 | * @access public 44 | * @return void 45 | */ 46 | public function get() 47 | { 48 | $aInputFiles = $this->oBatch->getInputFiles(); 49 | if (count($aInputFiles) == 1) { 50 | $this->beautifierSetInputFile(reset($aInputFiles)); 51 | $this->beautifierProcess(); 52 | return $this->beautifierGet(); 53 | } else { 54 | $sText = ''; 55 | foreach ($aInputFiles as $sFile) { 56 | $this->beautifierSetInputFile($sFile); 57 | $this->beautifierProcess(); 58 | $sText.= $this->_getWithHeader($sFile); 59 | } 60 | return $sText; 61 | } 62 | } 63 | /** 64 | * _getWithHeader 65 | * 66 | * @param mixed $sFile File 67 | * 68 | * @access private 69 | * @return void 70 | */ 71 | private function _getWithHeader($sFile) 72 | { 73 | $sNewLine = $this->oBatch->callBeautifier($this, 'getNewLine'); 74 | $sHeader = '- BEGIN OF '.$sFile.' -'.$sNewLine; 75 | $sLine = str_repeat('-', strlen($sHeader) -1) .$sNewLine; 76 | $sEnd = '- END OF '.$sFile.str_repeat(' ', strlen($sHeader) -strlen($sFile) -12) .' -'.$sNewLine; 77 | $sText = $sLine.$sHeader.$sLine.$sNewLine; 78 | $sText.= $this->beautifierGet(); 79 | $sText.= $sNewLine.$sLine.$sEnd.$sLine.$sNewLine; 80 | return $sText; 81 | } 82 | /** 83 | * save 84 | * 85 | * @access public 86 | * @return void 87 | */ 88 | public function save() 89 | { 90 | $bCli = php_sapi_name() == 'cli'; 91 | $sFile = $this->oBatch->getOutputPath(); 92 | if ($bCli and $sFile == STDOUT) { 93 | $fp = STDOUT; 94 | } else { 95 | $fp = fopen($this->oBatch->getOutputPath(), "w"); 96 | } 97 | if (!$fp) { 98 | throw (new Exception("Can't save file $sFile")); 99 | } 100 | $sText = $this->get(); 101 | fputs($fp, $sText, strlen($sText)); 102 | if (!($bCli and $fp == STDOUT)) { 103 | fclose($fp); 104 | } 105 | return true; 106 | } 107 | } 108 | ?> 109 | -------------------------------------------------------------------------------- /Beautifier/Batch/Output/FilesBz2.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2004-2010 Claudio Bustos 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version CVS: $Id:$ 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://beautifyphp.sourceforge.net 23 | */ 24 | /** 25 | * Include PHP_Beautifier_Batch_FilesGz 26 | */ 27 | require_once 'FilesTar.php'; 28 | /** 29 | * Handle the batch process for one/multiple php files to one tar bzip2 file 30 | * 31 | * @category PHP 32 | * @package PHP_Beautifier 33 | * @author Claudio Bustos 34 | * @copyright 2004-2010 Claudio Bustos 35 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 36 | * @version Release: @package_version@ 37 | * @link http://pear.php.net/package/PHP_Beautifier 38 | * @link http://beautifyphp.sourceforge.net 39 | */ 40 | class PHP_Beautifier_Batch_Output_FilesBz2 extends PHP_Beautifier_Batch_Output_FilesTar 41 | { 42 | protected $sCompress = 'bz2'; 43 | protected $sExt = 'tar.bz2'; 44 | } 45 | ?> 46 | -------------------------------------------------------------------------------- /Beautifier/Batch/Output/FilesGz.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2004-2010 Claudio Bustos 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version CVS: $Id:$ 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://beautifyphp.sourceforge.net 23 | */ 24 | /** 25 | * Include PHP_Beautifier_Batch_FilesGz 26 | */ 27 | require_once 'FilesTar.php'; 28 | /** 29 | * Handle the batch process for one/multiple php files to one tar gzip file 30 | * 31 | * @category PHP 32 | * @package PHP_Beautifier 33 | * @author Claudio Bustos 34 | * @copyright 2004-2010 Claudio Bustos 35 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 36 | * @version Release: @package_version@ 37 | * @link http://pear.php.net/package/PHP_Beautifier 38 | * @link http://beautifyphp.sourceforge.net 39 | */ 40 | class PHP_Beautifier_Batch_Output_FilesGz extends PHP_Beautifier_Batch_Output_FilesTar 41 | { 42 | protected $sCompress = 'gz'; 43 | protected $sExt = 'tgz'; 44 | } 45 | ?> 46 | -------------------------------------------------------------------------------- /Beautifier/Batch/Output/FilesTar.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2004-2010 Claudio Bustos 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version CVS: $Id:$ 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://beautifyphp.sourceforge.net 23 | */ 24 | /** 25 | * Require Archive_Tar 26 | */ 27 | require_once 'Archive/Tar.php'; 28 | /** 29 | * Handle the batch process for one/multiple php files to one tar compressed file 30 | * 31 | * @category PHP 32 | * @package PHP_Beautifier 33 | * @author Claudio Bustos 34 | * @copyright 2004-2010 Claudio Bustos 35 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 36 | * @version Release: @package_version@ 37 | * @link http://pear.php.net/package/PHP_Beautifier 38 | * @link http://beautifyphp.sourceforge.net 39 | */ 40 | class PHP_Beautifier_Batch_Output_FilesTar extends PHP_Beautifier_Batch_Output 41 | { 42 | protected $oTar; 43 | protected $sCompress=false; 44 | protected $sExt="tar"; 45 | /** 46 | * __construct 47 | * 48 | * @param PHP_Beautifier_Batch $oBatch PHP_Beautifier_Batch Object 49 | * 50 | * @access public 51 | * @return void 52 | */ 53 | public function __construct(PHP_Beautifier_Batch $oBatch) 54 | { 55 | parent::__construct($oBatch); 56 | $sOutput = $this->oBatch->getOutputPath(); 57 | $sOutput = preg_replace("/(\.tar|\.tar\.gz|\.tgz|\.gz|\.tar\.bz2)$/", '', $sOutput) .".".$this->sExt; 58 | PHP_Beautifier_Common::createDir($sOutput); 59 | $this->oTar = new Archive_Tar($sOutput, $this->sCompress); 60 | } 61 | /** 62 | * get 63 | * 64 | * @access public 65 | * @return void 66 | */ 67 | public function get() 68 | { 69 | throw (new Exception("TODO")); 70 | } 71 | /** 72 | * save 73 | * 74 | * @access public 75 | * @return void 76 | */ 77 | public function save() 78 | { 79 | $aInputFiles = $this->oBatch->getInputFiles(); 80 | $aOutputFiles = PHP_Beautifier_Common::getSavePath($aInputFiles); 81 | for ($x = 0;$xbeautifierSetInputFile($aInputFiles[$x]); 83 | $this->beautifierProcess(); 84 | $this->oTar->addString($aOutputFiles[$x], $this->beautifierGet()); 85 | } 86 | } 87 | } 88 | ?> 89 | -------------------------------------------------------------------------------- /Beautifier/Decorator.php: -------------------------------------------------------------------------------- 1 | 16 | * @copyright 2004-2010 Claudio Bustos 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * @version CVS: $Id:$ 19 | * @link http://pear.php.net/package/PHP_Beautifier 20 | * @link http://beautifyphp.sourceforge.net 21 | */ 22 | /** 23 | * Implements the Decorator Pattern 24 | * 25 | * @category PHP 26 | * @package PHP_Beautifier 27 | * @author Claudio Bustos 28 | * @copyright 2004-2006 Claudio Bustos 29 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 30 | * @version Release: @package_version@ 31 | * @link http://pear.php.net/package/PHP_Beautifier 32 | * @link http://beautifyphp.sourceforge.net 33 | */ 34 | abstract class PHP_Beautifier_Decorator implements PHP_Beautifier_Interface 35 | { 36 | protected $oBeaut; 37 | /** 38 | * __construct 39 | * 40 | * @param PHP_Beautifier_Interface $oBeaut PHP_Beautifier Object 41 | * 42 | * @access protected 43 | * @return void 44 | */ 45 | function __construct(PHP_Beautifier_Interface $oBeaut) 46 | { 47 | $this->oBeaut = $oBeaut; 48 | } 49 | 50 | /** 51 | * __call 52 | * 53 | * @param mixed $sMethod Method name 54 | * @param mixed $aArgs Method arguments 55 | * 56 | * @access protected 57 | * @return void 58 | */ 59 | function __call($sMethod, $aArgs) 60 | { 61 | if (!method_exists($this->oBeaut, $sMethod)) { 62 | throw (new Exception("Method '$sMethod' doesn't exists")); 63 | } else { 64 | return call_user_func_array( 65 | array( 66 | $this->oBeaut, 67 | $sMethod 68 | ), 69 | $aArgs 70 | ); 71 | } 72 | } 73 | } 74 | ?> 75 | -------------------------------------------------------------------------------- /Beautifier/Exception.php: -------------------------------------------------------------------------------- 1 | 17 | * @copyright 2004-2010 Claudio Bustos 18 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 19 | * @version CVS: $Id:$ 20 | * @link http://pear.php.net/package/PHP_Beautifier 21 | * @link http://beautifyphp.sourceforge.net 22 | */ 23 | /** 24 | * Exception for Filters 25 | * 26 | * @category PHP 27 | * @package PHP_Beautifier 28 | * @author Claudio Bustos 29 | * @copyright 2004-2006 Claudio Bustos 30 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 31 | * @version Release: @package_version@ 32 | * @link http://pear.php.net/package/PHP_Beautifier 33 | * @link http://beautifyphp.sourceforge.net 34 | */ 35 | class Exception_PHP_Beautifier_Filter extends PEAR_Exception 36 | { 37 | } 38 | ?> 39 | -------------------------------------------------------------------------------- /Beautifier/Filter/ArrayNested.filter.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2004-2010 Claudio Bustos 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version CVS: $Id:$ 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://beautifyphp.sourceforge.net 23 | */ 24 | /** 25 | * Filter Array Nested: Indent the array structures 26 | * Ex. 27 | * 28 | * $aMyArray = array( 29 | * array( 30 | * array( 31 | * array( 32 | * 'el'=>1, 33 | * 'el'=>2 34 | * ) 35 | * ) 36 | * ) 37 | * ); 38 | * 39 | * 40 | * @category PHP 41 | * @package PHP_Beautifier 42 | * @subpackage Filter 43 | * @author Claudio Bustos 44 | * @copyright 2004-2010 Claudio Bustos 45 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 46 | * @version Release: @package_version@ 47 | * @link http://pear.php.net/package/PHP_Beautifier 48 | * @link http://beautifyphp.sourceforge.net 49 | */ 50 | class PHP_Beautifier_Filter_ArrayNested extends PHP_Beautifier_Filter 51 | { 52 | /** 53 | * t_parenthesis_open 54 | * 55 | * @param mixed $sTag The tag to be procesed 56 | * 57 | * @access public 58 | * @return void 59 | */ 60 | public function t_parenthesis_open($sTag) 61 | { 62 | $this->oBeaut->add($sTag); 63 | if ($this->oBeaut->getControlParenthesis() == T_ARRAY) { 64 | $this->oBeaut->addNewLine(); 65 | $this->oBeaut->incIndent(); 66 | $this->oBeaut->addIndent(); 67 | } 68 | } 69 | /** 70 | * t_parenthesis_close 71 | * 72 | * @param mixed $sTag The tag to be procesed 73 | * 74 | * @access public 75 | * @return void 76 | */ 77 | public function t_parenthesis_close($sTag) 78 | { 79 | $this->oBeaut->removeWhitespace(); 80 | if ($this->oBeaut->getControlParenthesis() == T_ARRAY) { 81 | $this->oBeaut->decIndent(); 82 | if ($this->oBeaut->getPreviousTokenContent() != '(') { 83 | $this->oBeaut->addNewLine(); 84 | $this->oBeaut->addIndent(); 85 | } 86 | $this->oBeaut->add($sTag . ' '); 87 | } else { 88 | $this->oBeaut->add($sTag . ' '); 89 | } 90 | } 91 | /** 92 | * t_comma 93 | * 94 | * @param mixed $sTag The tag to be procesed 95 | * 96 | * @access public 97 | * @return void 98 | */ 99 | public function t_comma($sTag) 100 | { 101 | if ($this->oBeaut->getControlParenthesis() != T_ARRAY) { 102 | $this->oBeaut->add($sTag . ' '); 103 | } else { 104 | $this->oBeaut->add($sTag); 105 | $this->oBeaut->addNewLine(); 106 | $this->oBeaut->addIndent(); 107 | } 108 | } 109 | } 110 | ?> 111 | -------------------------------------------------------------------------------- /Beautifier/Filter/BreakLongLists.filter.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2014 Elod Csirmaz, based on ArrayNested by Claudio Bustos 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version CVS: $Id:$ 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://beautifyphp.sourceforge.net 23 | */ 24 | /** 25 | * Break long arrays, function definitions and function calls 26 | * 27 | * Break array()s, function definitions and function calls into multiple lines that, 28 | * on a single line, would be longer than a given limit. This limit defaults to 70, 29 | * and can be specified using the 'maxlen' parameter: 30 | * 31 | * --filters="BreakLongLists(maxlen=20)" 32 | * 33 | * @category PHP 34 | * @package PHP_Beautifier 35 | * @subpackage Filter 36 | * @author Elod Csirmaz 37 | * @copyright 2014 Elod Csirmaz, based on ArrayNested by Claudio Bustos 38 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 39 | * @version CVS: $Id:$ 40 | * @link http://pear.php.net/package/PHP_Beautifier 41 | * @link http://beautifyphp.sourceforge.net 42 | */ 43 | /** 44 | * Based on: 45 | * Filter Array Nested: Indent the array structures 46 | * Ex. 47 | * 48 | * $aMyArray = array( 49 | * array( 50 | * array( 51 | * array( 52 | * 'el'=>1, 53 | * 'el'=>2 54 | * ) 55 | * ) 56 | * ) 57 | * ); 58 | * 59 | * 60 | * @category PHP 61 | * @package PHP_Beautifier 62 | * @subpackage Filter 63 | * @author Claudio Bustos 64 | * @copyright 2004-2010 Claudio Bustos 65 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 66 | * @version Release: @package_version@ 67 | * @link http://pear.php.net/package/PHP_Beautifier 68 | * @link http://beautifyphp.sourceforge.net 69 | */ 70 | class PHP_Beautifier_Filter_BreakLongLists extends PHP_Beautifier_Filter 71 | { 72 | protected $aSettings = array('maxlen' => '70'); 73 | var $stack = array(); 74 | protected $sDescription = 'Break long arrays, function definitions and function calls'; 75 | public function __construct(PHP_Beautifier $oBeaut, $aSettings = array()) 76 | { 77 | parent::__construct($oBeaut, $aSettings); 78 | $this->addSettingDefinition('maxlen', 'text', 'Break array()s into multiple lines above this length'); 79 | } 80 | // This method determines whether the breaking should take place 81 | private function in_scope($control) 82 | { 83 | $control = $this->oBeaut->getControlParenthesis(); 84 | if ($control == T_ARRAY || $control == T_FUNCTION || $control == T_STRING) { 85 | return true; 86 | } 87 | return false; 88 | } 89 | /** 90 | * t_parenthesis_open 91 | * 92 | * @param mixed $sTag The tag to be procesed 93 | * 94 | * @access public 95 | * @return void 96 | */ 97 | public function t_parenthesis_open($sTag) 98 | { 99 | $this->oBeaut->add($sTag); 100 | if ($this->in_scope()) { 101 | $this->oBeaut->addNewLine(); 102 | $this->oBeaut->incIndent(); 103 | $this->oBeaut->addIndent(); 104 | array_push($this->stack, count($this->oBeaut->aOut)); 105 | array_push($this->stack, $this->oBeaut->iCount); 106 | } 107 | } 108 | /** 109 | * t_parenthesis_close 110 | * 111 | * @param mixed $sTag The tag to be procesed 112 | * 113 | * @access public 114 | * @return void 115 | */ 116 | public function t_parenthesis_close($sTag) 117 | { 118 | $this->oBeaut->removeWhitespace(); 119 | $isShortArray = false; 120 | if ($this->in_scope()) { 121 | $begiCount = array_pop($this->stack); 122 | $begOutCount = array_pop($this->stack); 123 | // Check if there are embedded comments 124 | // It is unsafe to delete newlines if there are 125 | $hasComment = false; 126 | for ($i = $begiCount; $i < $this->oBeaut->iCount; $i++) { 127 | $p = $this->oBeaut->getToken($i); 128 | if ($p[0] == T_COMMENT) { 129 | $hasComment = true; 130 | break; 131 | } 132 | } 133 | if (!$hasComment) { 134 | // Check how long the array is, without whitespace 135 | $arraystr = ''; 136 | for ($i = $begOutCount; $i < count($this->oBeaut->aOut); $i++) { 137 | $arraystr.= $this->oBeaut->aOut[$i]; 138 | } 139 | $arraystr = preg_replace('/\s/', '', $arraystr); 140 | // If it is too short, remove whitespace we added before. 141 | // The aOut[] elements are: 142 | // -2: newline 143 | // -1: indent 144 | // $begOutCount: FIRST ELEMENT 145 | // +1: comma 146 | // +2: newline 147 | // +3: indent 148 | // +4: SECOND ELEMENT 149 | if (strlen($arraystr) < $this->aSettings['maxlen']) { 150 | $isShortArray = true; 151 | $begCount2 = $begOutCount - 2; 152 | if ($begCount2 < 0) { 153 | $begCount2 = 0; 154 | } 155 | for ($i = $begCount2; $i < count($this->oBeaut->aOut); $i++) { 156 | $new = $this->oBeaut->aOut[$i]; 157 | $new = preg_replace('/^\r?\n$/', '', $new); 158 | $new = preg_replace('/^[ \t]+$/', ($i < $begOutCount ? '' : ' '), $new); 159 | $this->oBeaut->aOut[$i] = $new; 160 | } 161 | } 162 | } 163 | // 164 | $this->oBeaut->decIndent(); 165 | if ($this->oBeaut->getPreviousTokenContent() != '(' && !$isShortArray) { 166 | $this->oBeaut->addNewLine(); 167 | $this->oBeaut->addIndent(); 168 | } 169 | $this->oBeaut->add($sTag . ' '); 170 | } else { 171 | $this->oBeaut->add($sTag . ' '); 172 | } 173 | } 174 | /** 175 | * t_comma 176 | * 177 | * @param mixed $sTag The tag to be procesed 178 | * 179 | * @access public 180 | * @return void 181 | */ 182 | public function t_comma($sTag) 183 | { 184 | $this->oBeaut->removeWhitespace(); 185 | if ($this->in_scope()) { 186 | $this->oBeaut->add($sTag); 187 | $this->oBeaut->addNewLine(); 188 | $this->oBeaut->addIndent(); 189 | } else { 190 | $this->oBeaut->add($sTag . ' '); 191 | } 192 | } 193 | } 194 | ?> 195 | -------------------------------------------------------------------------------- /Beautifier/Filter/DocBlock.filter.php: -------------------------------------------------------------------------------- 1 | 19 | * @copyright 2010 Jesús Espino 20 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 21 | * @version CVS: $Id:$ 22 | * @link http://pear.php.net/package/PHP_Beautifier 23 | * @link http://beautifyphp.sourceforge.net 24 | */ 25 | /** 26 | * Filter Doc Blocks: Use DocBlockGenerator for beautify the phpdoc comments. 27 | * Ex. 28 | *
29 |  * /**
30 |  *  * @category   PHP
31 |  *  * @package    PHP_Beautifier
32 |  *  * @subpackage Filter
33 |  *  * @author     Jesús Espino 
34 |  *  * @copyright  2010 Jesús Espino
35 |  *  * @link       http://pear.php.net/package/PHP_Beautifier
36 |  *  * @link       http://beautifyphp.sourceforge.net
37 |  *  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
38 |  *  * @version    Release: @package_version@
39 |  *  *'/
40 |  * 
41 | * 42 | * @category PHP 43 | * @package PHP_Beautifier 44 | * @subpackage Filter 45 | * @author Jesús Espino 46 | * @copyright 2010 Jesús Espino 47 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 48 | * @version Release: @package_version@ 49 | * @link http://pear.php.net/package/PHP_Beautifier 50 | * @link http://beautifyphp.sourceforge.net 51 | */ 52 | class PHP_Beautifier_Filter_DocBlock extends PHP_Beautifier_Filter 53 | { 54 | /** 55 | * t_doc_comment 56 | * 57 | * @param mixed $sTag The tag to be processed 58 | * 59 | * @access public 60 | * @return void 61 | */ 62 | public function t_doc_comment($sTag) 63 | { 64 | include_once "PHP/DocBlockGenerator/Align.php"; 65 | $aligner = new PHP_DocBlockGenerator_Align(); 66 | $this->oBeaut->removeWhiteSpace(); 67 | $this->oBeaut->addNewLineIndent(); 68 | $this->oBeaut->add($aligner->alignTags($sTag)); 69 | $this->oBeaut->addNewLineIndent(); 70 | } 71 | } 72 | ?> 73 | -------------------------------------------------------------------------------- /Beautifier/Filter/EqualsAlign.filter.php: -------------------------------------------------------------------------------- 1 | 19 | * @copyright 2010 Jesús Espino 20 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 21 | * @version CVS: $Id:$ 22 | * @link http://pear.php.net/package/PHP_Beautifier 23 | * @link http://beautifyphp.sourceforge.net 24 | */ 25 | /** 26 | * Filter EqualsAlign: Align the equals symbols in contiguous lines. 27 | * 28 | * @category PHP 29 | * @package PHP_Beautifier 30 | * @subpackage Filter 31 | * @author Jesús Espino 32 | * @copyright 2010 Jesús Espino 33 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 34 | * @version Release: @package_version@ 35 | * @link http://pear.php.net/package/PHP_Beautifier 36 | * @link http://beautifyphp.sourceforge.net 37 | */ 38 | class PHP_Beautifier_Filter_EqualsAlign extends PHP_Beautifier_Filter 39 | { 40 | var $maxVarSize = 0; 41 | var $equalsToModify = array(); 42 | /** 43 | * t_assigment 44 | * 45 | * @param mixed $sTag The tag to be processed 46 | * 47 | * @access public 48 | * @return void 49 | */ 50 | public function t_assigment($sTag) 51 | { 52 | $var_size = 0; 53 | $counter = 1; 54 | $next = $this->oBeaut->getToken($this->oBeaut->iCount+$counter); 55 | $ends = 0; 56 | while ($next!="=" && $ends<2 && $next!=null) { 57 | if ($next == ";") { 58 | $ends++; 59 | } 60 | $counter++; 61 | $next = $this->oBeaut->getToken($this->oBeaut->iCount+$counter); 62 | } 63 | 64 | $counter = 1; 65 | $prev = $this->oBeaut->getToken($this->oBeaut->iCount-$counter); 66 | while ($prev[0]==T_WHITESPACE) { 67 | $counter++; 68 | $prev = $this->oBeaut->getToken($this->oBeaut->iCount-$counter); 69 | } 70 | while (($prev[0]==T_VARIABLE || $prev[0]==T_OBJECT_OPERATOR || $prev[0]==T_STRING ) && $prev!=null) { 71 | $var_size+=strlen($prev[1]); 72 | $counter++; 73 | $prev = $this->oBeaut->getToken($this->oBeaut->iCount-$counter); 74 | } 75 | 76 | if ($this->maxVarSize<$var_size) { 77 | $this->maxVarSize = $var_size; 78 | } 79 | $this->equalsToModify[] = array('position'=>count($this->oBeaut->aOut)+1,'size'=>$var_size); 80 | if ($next!="=") { 81 | foreach ($this->equalsToModify as $equal) { 82 | $this->oBeaut->aOut[$equal['position']-2]=$this->oBeaut->aOut[$equal['position']-2].str_repeat(" ", $this->maxVarSize-$equal['size']); 83 | } 84 | $this->maxVarSize = 0; 85 | $this->equalsToModify = array(); 86 | } 87 | 88 | $this->oBeaut->add(" ".$sTag." "); 89 | } 90 | } 91 | ?> 92 | -------------------------------------------------------------------------------- /Beautifier/Filter/Fluent.filter.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2010 Jesús Espino 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version CVS: $Id:$ 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://beautifyphp.sourceforge.net 23 | */ 24 | /** 25 | * Filter Fluent: Create fluent style for multi-level object access. 26 | * Ex. 27 | * 28 | * $this 29 | * ->addFile("a.txt") 30 | * ->addFile("b.txt") 31 | * ->addFile("c.txt"); 32 | * $this->addFile("d.txt"); 33 | * 34 | * 35 | * @category PHP 36 | * @package PHP_Beautifier 37 | * @subpackage Filter 38 | * @author Jesús Espino 39 | * @copyright 2010 Jesús Espino 40 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 41 | * @version Release: @package_version@ 42 | * @link http://pear.php.net/package/PHP_Beautifier 43 | * @link http://beautifyphp.sourceforge.net 44 | */ 45 | class PHP_Beautifier_Filter_Fluent extends PHP_Beautifier_Filter 46 | { 47 | /** 48 | * t_object_operator 49 | * 50 | * @param mixed $sTag The tag to be processed 51 | * 52 | * @access public 53 | * @return void 54 | */ 55 | public function t_object_operator($sTag) 56 | { 57 | $counter = 1; 58 | $next = $this->oBeaut->getToken($this->oBeaut->iCount + $counter); 59 | $parenthesis = 0; 60 | $brace = 0; 61 | while ($next && ($parenthesis > 0 || $brace > 0 || $next[0] != T_OBJECT_OPERATOR) 62 | && ($next != ";" )) { 63 | $counter++; 64 | switch ($next) { 65 | case '(' : $parenthesis += 1; break; 66 | case ')' : $parenthesis -= 1; break; 67 | case '[' : $brace += 1; break; 68 | case ']' : $brace -= 1; break; 69 | } 70 | if ($parenthesis <= 0 && $brace == 0 && !in_array($next[0], 71 | array(T_VARIABLE,T_PAAMAYIM_NEKUDOTAYIM,T_WHITESPACE,T_DOUBLE_COLON,T_STRING))) 72 | break; 73 | $next = $this->oBeaut->getToken($this->oBeaut->iCount + $counter); 74 | } 75 | $counter = 1; 76 | $prev = $this->oBeaut->getToken($this->oBeaut->iCount - $counter); 77 | $parenthesis = 0; 78 | $brace = 0; 79 | while ($prev && (($prev[0] != T_OBJECT_OPERATOR) && ($prev[0] != T_VARIABLE))) { 80 | $counter++; 81 | switch ($next) { 82 | case '(' : $parenthesis += 1; break; 83 | case ')' : $parenthesis -= 1; break; 84 | case '[' : $brace += 1; break; 85 | case ']' : $brace -= 1; break; 86 | } 87 | if ($parenthesis >= 0 && $brace == 0 && !in_array($next[0], 88 | array(T_PAAMAYIM_NEKUDOTAYIM,T_WHITESPACE,T_DOUBLE_COLON,T_STRING))) 89 | break; 90 | $prev = $this->oBeaut->getToken($this->oBeaut->iCount - $counter); 91 | } 92 | $this->oBeaut->removeWhiteSpace(); 93 | if ($next[0] == T_OBJECT_OPERATOR || $prev[0] == T_OBJECT_OPERATOR) { 94 | $this->oBeaut->addNewLineIndent(); 95 | for ($x = 0;$x < $this->oBeaut->getIndentNumber();$x++) { 96 | $this->oBeaut->add($this->oBeaut->getIndentChar()); 97 | } 98 | } 99 | $this->oBeaut->add($sTag); 100 | } 101 | } 102 | ?> 103 | -------------------------------------------------------------------------------- /Beautifier/Filter/KeepEmptyLines.filter.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2014 Elod Csirmaz 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version 1.0 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://beautifyphp.sourceforge.net 23 | */ 24 | /** 25 | * Keep a single empty line where empty lines can be found 26 | * 27 | * @category PHP 28 | * @package PHP_Beautifier 29 | * @subpackage Filter 30 | * @author Elod Csirmaz 31 | * @copyright 2014 Elod Csirmaz 32 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 33 | * @version 1.0 34 | * @link http://pear.php.net/package/PHP_Beautifier 35 | * @link http://beautifyphp.sourceforge.net 36 | */ 37 | class PHP_Beautifier_Filter_KeepEmptyLines extends PHP_Beautifier_Filter 38 | { 39 | protected $sDescription = 'Keep a single empty line where empty lines can be found'; 40 | public function __construct(PHP_Beautifier $oBeaut, $aSettings = array()) 41 | { 42 | parent::__construct($oBeaut, $aSettings); 43 | $this->oBeaut->setNoDeletePreviousSpaceHack(); 44 | } 45 | public function t_whitespace($sTag) 46 | { 47 | if (preg_match('/\n\s*\r?\n/', $sTag)) { 48 | $this->oBeaut->removeWhitespace(); 49 | $this->oBeaut->aOut[count($this->oBeaut->aOut) - 1].= "\n/**ndps**/\n"; // see setNoDeletePreviousSpaceHack 50 | $this->oBeaut->addIndent(); 51 | } 52 | } 53 | } 54 | ?> 55 | -------------------------------------------------------------------------------- /Beautifier/Filter/ListClassFunction.filter.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2004-2010 Claudio Bustos 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version CVS: $Id:$ 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://beautifyphp.sourceforge.net 23 | */ 24 | /** 25 | * Create a list of functions and classes in the script 26 | * By default, this Filter puts the list at the beggining of the script. 27 | * If you want it in another position, put a comment like that 28 | *
 29 |  * // Class and Function List
 30 |  * 
31 | * The script lookup for the string 'Class and Function List' in a comment and 32 | * replace the entire comment with the list 33 | * The settings are 34 | * - list_functions: List functions (0 or 1). Default:1 35 | * - list_classes: List classes (0 or 1). Default:1 36 | * 37 | * @todo List functions inside classes as methods 38 | * @category PHP 39 | * @package PHP_Beautifier 40 | * @subpackage Filter 41 | * @author Claudio Bustos 42 | * @copyright 2004-2010 Claudio Bustos 43 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 44 | * @version Release: @package_version@ 45 | * @link http://pear.php.net/package/PHP_Beautifier 46 | * @link http://beautifyphp.sourceforge.net 47 | */ 48 | class PHP_Beautifier_Filter_ListClassFunction extends PHP_Beautifier_Filter 49 | { 50 | protected $aFilterTokenFunctions = array( 51 | T_CLASS => 't_class', 52 | T_FUNCTION => 't_function', 53 | T_COMMENT => 't_comment', 54 | T_OPEN_TAG => 't_open_tag' 55 | ); 56 | private $_aFunctions = array(); 57 | private $_aClasses = array(); 58 | private $_iComment; 59 | private $_iOpenTag = null; 60 | protected $aSettings = array( 61 | 'list_functions' => true, 62 | 'list_classes' => true 63 | ); 64 | protected $sDescription = 'Create a list of functions and classes in the script'; 65 | private $_aInclude = array( 66 | 'functions' => true, 67 | 'classes' => true 68 | ); 69 | /** 70 | * __construct 71 | * 72 | * @param PHP_Beautifier $oBeaut PHP_Beautifier Object 73 | * @param array $aSettings Settings for the PHP_Beautifier 74 | * 75 | * @access public 76 | * @return void 77 | */ 78 | public function __construct(PHP_Beautifier $oBeaut, $aSettings = array()) 79 | { 80 | parent::__construct($oBeaut, $aSettings); 81 | $this->addSettingDefinition('list_functions', 'bool', 'List Functions inside the file'); 82 | $this->addSettingDefinition('list_classes', 'bool', 'List Classes inside the file'); 83 | } 84 | /** 85 | * t_function 86 | * 87 | * @param mixed $sTag The tag to be processed 88 | * 89 | * @access public 90 | * @return void 91 | */ 92 | function t_function($sTag) 93 | { 94 | if ($this->_aInclude['functions']) { 95 | $sNext = $this->oBeaut->getNextTokenContent(1); 96 | if ($sNext == '&') { 97 | $sNext.= $this->oBeaut->getNextTokenContent(2); 98 | } 99 | array_push($this->_aFunctions, $sNext); 100 | } 101 | return PHP_Beautifier_Filter::BYPASS; 102 | } 103 | /** 104 | * includeInList 105 | * 106 | * @param mixed $sTag The tag to include in the list (classes|functions) 107 | * @param mixed $sValue The flag to enable or thisable the $sTag list (true|false) 108 | * 109 | * @access public 110 | * @return void 111 | */ 112 | function includeInList($sTag, $sValue) 113 | { 114 | $this->_aInclude[$sTag] = $sValue; 115 | } 116 | /** 117 | * t_class 118 | * 119 | * @param mixed $sTag The tag to be processed 120 | * 121 | * @access public 122 | * @return void 123 | */ 124 | function t_class($sTag) 125 | { 126 | if ($this->_aInclude['classes']) { 127 | $sClassName = $this->oBeaut->getNextTokenContent(1); 128 | if ($this->oBeaut->isNextTokenConstant(T_EXTENDS, 2)) { 129 | $sClassName.= ' extends ' . $this->oBeaut->getNextTokenContent(3); 130 | } 131 | array_push($this->_aClasses, $sClassName); 132 | } 133 | return PHP_Beautifier_Filter::BYPASS; 134 | } 135 | /** 136 | * t_doc_comment 137 | * 138 | * @param mixed $sTag The tag to be processed 139 | * 140 | * @access public 141 | * @return void 142 | */ 143 | function t_doc_comment($sTag) 144 | { 145 | if (strpos($sTag, 'Class and Function List') !== false) { 146 | $this->_iComment = $this->oBeaut->iCount; 147 | } 148 | return PHP_Beautifier_Filter::BYPASS; 149 | } 150 | /** 151 | * t_open_tag 152 | * 153 | * @param mixed $sTag The tag to be processed 154 | * 155 | * @access public 156 | * @return void 157 | */ 158 | function t_open_tag($sTag) 159 | { 160 | if (is_null($this->_iOpenTag)) { 161 | $this->_iOpenTag = $this->oBeaut->iCount; 162 | } 163 | return PHP_Beautifier_Filter::BYPASS; 164 | } 165 | /** 166 | * postProcess 167 | * 168 | * @access public 169 | * @return void 170 | */ 171 | function postProcess() 172 | { 173 | $sNL = $this->oBeaut->sNewLine; 174 | $aOut = array( 175 | "/**", 176 | "* Class and Function List:" 177 | ); 178 | if ($this->getSetting('list_functions')) { 179 | $aOut[] = "* Function list:"; 180 | foreach ($this->_aFunctions as $sFunction) { 181 | $aOut[] = "* - " . $sFunction . "()"; 182 | } 183 | } 184 | if ($this->getSetting('list_classes')) { 185 | $aOut[] = "* Classes list:"; 186 | foreach ($this->_aClasses as $sClass) { 187 | $aOut[] = "* - " . $sClass; 188 | } 189 | } 190 | $aOut[] = "*/"; 191 | if ($this->_iComment) { 192 | // Determine the previous Indent 193 | $sComment = $this->oBeaut->getTokenAssocText($this->_iComment); 194 | if (preg_match("/" . addcslashes($sNL, "\r\n") . "([ \t]+)/ms", $sComment, $aMatch)) { 195 | $sPrevio = $sNL . $aMatch[1]; 196 | } else { 197 | $sPrevio = $sNL; 198 | } 199 | $sText = implode($sPrevio, $aOut) . $sNL; 200 | $this->oBeaut->replaceTokenAssoc($this->_iComment, $sText); 201 | } else { 202 | $sPrevio = $sNL /*.str_repeat($this->oBeaut->sIndentChar, $this->oBeaut->iIndentNumber)*/; 203 | $sTag = trim($this->oBeaut->getTokenAssocText($this->_iOpenTag)) . "\n"; 204 | $sText = $sPrevio . implode($sPrevio, $aOut); 205 | $this->oBeaut->replaceTokenAssoc($this->_iOpenTag, rtrim($sTag) . $sText . $sPrevio); 206 | } 207 | } 208 | } 209 | ?> 210 | -------------------------------------------------------------------------------- /Beautifier/Filter/Lowercase.filter.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2004-2010 Claudio Bustos 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version CVS: $Id:$ 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://php.apsique.com/PHP_Beautifier 23 | * @since File available since Release 0.1.9 24 | */ 25 | /** 26 | * Lowercase: lowercase all control structures. 27 | * You should filter the code with this filter, and later parse 28 | * again the file with the others filters 29 | * Command line example: 30 | * 31 | * php_beautifier --filters "Lowercase()" 32 | * 33 | * @category PHP 34 | * @package PHP_Beautifier 35 | * @subpackage Filter 36 | * @author Claudio Bustos 37 | * @copyright 2004-2010 Claudio Bustos 38 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 39 | * @version Release: @package_version@ 40 | * @link http://pear.php.net/package/PHP_Beautifier 41 | * @link http://beautifyphp.sourceforge.net 42 | * @since Class available since Release 0.1.9 43 | */ 44 | class PHP_Beautifier_Filter_Lowercase extends PHP_Beautifier_Filter 45 | { 46 | protected $sDescription = 'Lowercase all control structures. Parse the output with another Filters'; 47 | private $_aControlSeq = array( 48 | T_IF, 49 | T_ELSE, 50 | T_ELSEIF, 51 | T_WHILE, 52 | T_DO, 53 | T_FOR, 54 | T_FOREACH, 55 | T_SWITCH, 56 | T_DECLARE, 57 | T_CASE, 58 | T_DEFAULT, 59 | T_TRY, 60 | T_CATCH, 61 | T_ENDWHILE, 62 | T_ENDFOREACH, 63 | T_ENDFOR, 64 | T_ENDDECLARE, 65 | T_ENDSWITCH, 66 | T_ENDIF, 67 | T_INCLUDE, 68 | T_INCLUDE_ONCE, 69 | T_REQUIRE, 70 | T_REQUIRE_ONCE, 71 | T_FUNCTION, 72 | T_PRINT, 73 | T_RETURN, 74 | T_ECHO, 75 | T_NEW, 76 | T_CLASS, 77 | T_VAR, 78 | T_GLOBAL, 79 | T_THROW, 80 | /* CONTROL */ 81 | T_IF, 82 | T_DO, 83 | T_WHILE, 84 | T_SWITCH, 85 | T_CASE, 86 | /* ELSE */ 87 | T_ELSEIF, 88 | T_ELSE, 89 | T_BREAK, 90 | /* ACCESS PHP 5 */ 91 | T_INTERFACE, 92 | T_FINAL, 93 | T_ABSTRACT, 94 | T_PRIVATE, 95 | T_PUBLIC, 96 | T_PROTECTED, 97 | T_CONST, 98 | T_STATIC, 99 | /* LOGICAL */ 100 | T_LOGICAL_OR, 101 | T_LOGICAL_XOR, 102 | T_LOGICAL_AND, 103 | T_BOOLEAN_OR, 104 | T_BOOLEAN_AND, 105 | ); 106 | private $_oLog; 107 | 108 | /** 109 | * __construct 110 | * 111 | * @param PHP_Beautifier $oBeaut PHP_Beautifier Object 112 | * @param array $aSettings Settings for the PHP_Beautifier 113 | * 114 | * @access public 115 | * @return void 116 | */ 117 | public function __construct(PHP_Beautifier $oBeaut, $aSettings = array()) 118 | { 119 | parent::__construct($oBeaut, $aSettings); 120 | $this->_oLog = PHP_Beautifier_Common::getLog(); 121 | } 122 | 123 | /** 124 | * t_string 125 | * 126 | * @param mixed $sTag The tag to be procesed 127 | * 128 | * @access public 129 | * @return void 130 | */ 131 | public function t_string($sTag) 132 | { 133 | if ($sTag=='TRUE' or $sTag=='FALSE') { 134 | $this->oBeaut->aCurrentToken[1]=strtolower($sTag); 135 | } 136 | return PHP_Beautifier_Filter::BYPASS; 137 | 138 | } 139 | 140 | /** 141 | * __call 142 | * 143 | * @param mixed $sMethod Method name 144 | * @param mixed $aArgs Method arguments 145 | * 146 | * @access public 147 | * @return void 148 | */ 149 | public function __call($sMethod, $aArgs) 150 | { 151 | $iToken = $this->aToken[0]; 152 | $sContent = $this->aToken[1]; 153 | if (in_array($iToken, $this->_aControlSeq)) { 154 | $this->_oLog->log("Lowercase:" . $sContent, PEAR_LOG_DEBUG); 155 | $this->oBeaut->aCurrentToken[1]=strtolower($sContent); 156 | 157 | } 158 | return PHP_Beautifier_Filter::BYPASS; 159 | } 160 | } 161 | ?> 162 | -------------------------------------------------------------------------------- /Beautifier/Filter/NewLines.filter.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2004-2010 Claudio Bustos 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version CVS: $Id:$ 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://beautifyphp.sourceforge.net 23 | * @since File available since Release 0.1.2 24 | */ 25 | /** 26 | * New Lines: Add new lines after o before specific contents 27 | * The settings are 'before' and 'after'. As value, use a colon separated 28 | * list of contents or tokens 29 | * 30 | * Command line example: 31 | * 32 | * php_beautifier --filters "NewLines(before=if:switch:T_CLASS,after=T_COMMENT:function)" 33 | * 34 | * @category PHP 35 | * @package PHP_Beautifier 36 | * @subpackage Filter 37 | * @author Claudio Bustos 38 | * @copyright 2004-2010 Claudio Bustos 39 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 40 | * @version Release: @package_version@ 41 | * @link http://pear.php.net/package/PHP_Beautifier 42 | * @link http://beautifyphp.sourceforge.net 43 | * @since Class available since Release 0.1.2 44 | */ 45 | class PHP_Beautifier_Filter_NewLines extends PHP_Beautifier_Filter 46 | { 47 | protected $aSettings = array( 48 | 'before' => false, 49 | 'after' => false 50 | ); 51 | protected $sDescription = 'Add new lines after or before specific contents'; 52 | private $_aBeforeToken = array(); 53 | private $_aBeforeContent = array(); 54 | private $_aAfterToken = array(); 55 | private $_aAfterContent = array(); 56 | /** 57 | * __construct 58 | * 59 | * @param PHP_Beautifier $oBeaut PHP_Beautifier Object 60 | * @param array $aSettings Settings for the PHP_Beautifier 61 | * 62 | * @access public 63 | * @return void 64 | */ 65 | public function __construct(PHP_Beautifier $oBeaut, $aSettings = array()) 66 | { 67 | parent::__construct($oBeaut, $aSettings); 68 | $this->addSettingDefinition('before', 'text', 'List of contents to put new lines before, separated by colons'); 69 | $this->addSettingDefinition('after', 'text', 'List of contents to put new lines after, separated by colons'); 70 | if (!empty($this->aSettings['before'])) { 71 | $aBefore = explode(':', str_replace(' ', '', $this->aSettings['before'])); 72 | foreach ($aBefore as $sBefore) { 73 | if (defined($sBefore)) { 74 | $this->_aBeforeToken[] = constant($sBefore); 75 | } else { 76 | $this->_aBeforeContent[] = $sBefore; 77 | } 78 | } 79 | } 80 | if (!empty($this->aSettings['after'])) { 81 | $aAfter = explode(':', str_replace(' ', '', $this->aSettings['after'])); 82 | foreach ($aAfter as $sAfter) { 83 | if (defined($sAfter)) { 84 | $this->_aAfterToken[] = constant($sAfter); 85 | } else { 86 | $this->_aAfterContent[] = $sAfter; 87 | } 88 | } 89 | } 90 | $this->oBeaut->setNoDeletePreviousSpaceHack(); 91 | } 92 | /** 93 | * __call 94 | * 95 | * @param mixed $sMethod Method name 96 | * @param mixed $aArgs Method arguments 97 | * 98 | * @access public 99 | * @return void 100 | */ 101 | public function __call($sMethod, $aArgs) 102 | { 103 | $iToken = $this->aToken[0]; 104 | $sContent = $this->aToken[1]; 105 | if (in_array($sContent, $this->_aBeforeContent) or in_array($iToken, $this->_aBeforeToken)) { 106 | $this->oBeaut->addNewLineIndent(); 107 | } 108 | if (in_array($sContent, $this->_aAfterContent) or in_array($iToken, $this->_aAfterToken)) { 109 | $this->oBeaut->setBeforeNewLine($this->oBeaut->sNewLine . '/**ndps**/'); 110 | } 111 | return PHP_Beautifier_Filter::BYPASS; 112 | } 113 | 114 | /** 115 | * Called from {@link PHP_Beautifier::process()} at the end of processing 116 | * The post-process must be made in {@link PHP_Beautifier::$aOut} 117 | * 118 | * @access public 119 | * @return void 120 | */ 121 | public function postProcess() 122 | { 123 | foreach ($this->oBeaut->aOut as $i => &$out) 124 | { 125 | if (is_string($out) && $out != '' && trim($out) == '') 126 | { 127 | $trimed = trim($out, $this->oBeaut->getIndentChar()); 128 | if ($trimed != $out && strpos($this->oBeaut->aOut[$i-1],"\n") !== false 129 | && strpos($this->oBeaut->aOut[$i+1],"\n") !== false ) 130 | { 131 | $out = $trimed; 132 | } 133 | } 134 | } 135 | } 136 | } 137 | ?> 138 | -------------------------------------------------------------------------------- /Beautifier/Filter/SpaceOpAssignments.filter.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2014 Elod Csirmaz 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version 1.0 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://beautifyphp.sourceforge.net 23 | */ 24 | /** 25 | * Add space before operator+assignments 26 | * 27 | * @category PHP 28 | * @package PHP_Beautifier 29 | * @subpackage Filter 30 | * @author Elod Csirmaz 31 | * @copyright 2014 Elod Csirmaz 32 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 33 | * @version 1.0 34 | * @link http://pear.php.net/package/PHP_Beautifier 35 | * @link http://beautifyphp.sourceforge.net 36 | */ 37 | class PHP_Beautifier_Filter_SpaceOpAssignments extends PHP_Beautifier_Filter 38 | { 39 | protected $sDescription = 'Add space before operator+assignments'; 40 | /** 41 | * t_assigment_pre 42 | * 43 | * @param mixed $sTag The tag to be processed 44 | * 45 | * @access public 46 | * @return void 47 | */ 48 | function t_assigment_pre($sTag) 49 | { 50 | $this->oBeaut->removeWhitespace(); 51 | $this->oBeaut->add(' ' . $sTag . ' '); 52 | } 53 | } 54 | ?> 55 | -------------------------------------------------------------------------------- /Beautifier/Filter/phpBB.filter.php: -------------------------------------------------------------------------------- 1 | 17 | * @copyright 2008 Jim Wigginton 18 | * @license http://www.gnu.org/licenses/lgpl.html LGPL 19 | * @version CVS: $Id:$ 20 | * @link http://pear.php.net/package/PHP_Beautifier 21 | */ 22 | /** 23 | * Require PEAR_Config 24 | */ 25 | require_once 'PEAR/Config.php'; 26 | /** 27 | * Filter the code to make it compatible with phpBB Coding Standards 28 | * 29 | * Among other differences from the PEAR Coding Standards, the phpBB coding standards use BSD style indenting. 30 | * 31 | * @category PHP 32 | * @package PHP_Beautifier 33 | * @subpackage Filter 34 | * @author Jim Wigginton 35 | * @copyright 2008 Jim Wigginton 36 | * @license http://www.gnu.org/licenses/lgpl.html LGPL 37 | * @version Release: 0.0.1 38 | * @link http://pear.php.net/package/PHP_Beautifier 39 | */ 40 | class PHP_Beautifier_Filter_phpBB extends PHP_Beautifier_Filter 41 | { 42 | protected $sDescription = 'Filter the code to make it compatible with phpBB Coding Standards'; 43 | private $_iNestedIfs = 0; 44 | /** 45 | * __construct 46 | * 47 | * @param PHP_Beautifier $oBeaut PHP_Beautifier Object 48 | * @param array $aSettings Settings for the PHP_Beautifier 49 | * 50 | * @access public 51 | * @return void 52 | */ 53 | public function __construct(PHP_Beautifier $oBeaut, $aSettings = array()) 54 | { 55 | parent::__construct($oBeaut, $aSettings); 56 | $oBeaut->setIndentChar("\t"); 57 | $oBeaut->setIndentNumber(1); 58 | $oBeaut->setNewLine(PHP_EOL); 59 | } 60 | /** 61 | * t_open_brace 62 | * 63 | * @param mixed $sTag The tag to be processed 64 | * 65 | * @access public 66 | * @return void 67 | */ 68 | function t_open_brace($sTag) 69 | { 70 | $this->oBeaut->addNewLineIndent(); 71 | $this->oBeaut->add($sTag); 72 | $this->oBeaut->incIndent(); 73 | $this->oBeaut->addNewLineIndent(); 74 | } 75 | /** 76 | * t_close_brace 77 | * 78 | * @param mixed $sTag The tag to be processed 79 | * 80 | * @access public 81 | * @return void 82 | */ 83 | function t_close_brace($sTag) 84 | { 85 | if ($this->oBeaut->getMode('string_index') or $this->oBeaut->getMode('double_quote')) { 86 | $this->oBeaut->add($sTag); 87 | } else { 88 | $this->oBeaut->removeWhitespace(); 89 | $this->oBeaut->decIndent(); 90 | $this->oBeaut->addNewLineIndent(); 91 | $this->oBeaut->add($sTag); 92 | $this->oBeaut->addNewLineIndent(); 93 | } 94 | } 95 | /** 96 | * t_else 97 | * 98 | * @param mixed $sTag The tag to be processed 99 | * 100 | * @access public 101 | * @return void 102 | */ 103 | function t_else($sTag) 104 | { 105 | $this->oBeaut->add($sTag); 106 | if (!$this->oBeaut->isNextTokenContent('{')) { 107 | $this->oBeaut->addNewLineIndent(); 108 | $this->oBeaut->add('{'); 109 | $this->oBeaut->incIndent(); 110 | $this->oBeaut->addNewLineIndent(); 111 | $this->_iNestedIfs++; 112 | } 113 | } 114 | /** 115 | * t_semi_colon 116 | * 117 | * @param mixed $sTag The tag to be processed 118 | * 119 | * @access public 120 | * @return void 121 | */ 122 | function t_semi_colon($sTag) 123 | { 124 | $this->oBeaut->removeWhitespace(); 125 | $this->oBeaut->add($sTag); 126 | if ($this->oBeaut->getControlParenthesis() != T_FOR) { 127 | if ($this->_iNestedIfs > 0) { 128 | $this->oBeaut->decIndent(); 129 | $this->oBeaut->addNewLineIndent(); 130 | $this->oBeaut->add('}'); 131 | $this->_iNestedIfs--; 132 | } 133 | $this->oBeaut->addNewLineIndent(); 134 | } 135 | } 136 | 137 | /** 138 | * preProcess 139 | * 140 | * @access public 141 | * @return void 142 | */ 143 | function preProcess() 144 | { 145 | $this->_iNestedIfs = 0; 146 | } 147 | } 148 | ?> 149 | -------------------------------------------------------------------------------- /Beautifier/StreamWrapper.php: -------------------------------------------------------------------------------- 1 | 17 | * @copyright 2004-2010 Claudio Bustos 18 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 19 | * @version CVS: $Id:$ 20 | * @link http://pear.php.net/package/PHP_Beautifier 21 | * @link http://beautifyphp.sourceforge.net 22 | */ 23 | /** 24 | * Interface for StreamWrapper 25 | * Read the documentation for streams wrappers on php manual. 26 | * 27 | * @category PHP 28 | * @package PHP_Beautifier 29 | * @subpackage StreamWrapper 30 | * @author Claudio Bustos 31 | * @copyright 2004-2010 Claudio Bustos 32 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 33 | * @version Release: @package_version@ 34 | * @link http://pear.php.net/package/PHP_Beautifier 35 | * @link http://beautifyphp.sourceforge.net 36 | */ 37 | interface PHP_Beautifier_StreamWrapper_Interface 38 | { 39 | /** 40 | * stream_open 41 | * 42 | * @param mixed $sPath Path 43 | * @param mixed $sMode Mode 44 | * @param mixed $iOptions Opitions 45 | * @param mixed &$sOpenedPath Opened Path 46 | * 47 | * @access public 48 | * @return void 49 | */ 50 | function stream_open($sPath, $sMode, $iOptions, &$sOpenedPath); 51 | /** 52 | * stream_close 53 | * 54 | * @access public 55 | * @return void 56 | */ 57 | function stream_close(); 58 | /** 59 | * stream_read 60 | * 61 | * @param mixed $iCount Count 62 | * 63 | * @access public 64 | * @return void 65 | */ 66 | function stream_read($iCount); 67 | /** 68 | * stream_write 69 | * 70 | * @param mixed $sData Data 71 | * 72 | * @access public 73 | * @return void 74 | */ 75 | function stream_write($sData); 76 | /** 77 | * stream_eof 78 | * 79 | * @access public 80 | * @return void 81 | */ 82 | function stream_eof(); 83 | /** 84 | * stream_tell 85 | * 86 | * @access public 87 | * @return void 88 | */ 89 | function stream_tell(); 90 | /** 91 | * stream_seek 92 | * 93 | * @param mixed $iOffset Offset 94 | * @param mixed $iWhence Whence 95 | * 96 | * @access public 97 | * @return void 98 | */ 99 | function stream_seek($iOffset, $iWhence); 100 | /** 101 | * stream_flush 102 | * 103 | * @access public 104 | * @return void 105 | */ 106 | function stream_flush(); 107 | /** 108 | * stream_stat 109 | * 110 | * @access public 111 | * @return void 112 | */ 113 | function stream_stat(); 114 | /** 115 | * unlink 116 | * 117 | * @param mixed $sPath Path 118 | * 119 | * @access public 120 | * @return void 121 | */ 122 | function unlink($sPath); 123 | /** 124 | * dir_opendir 125 | * 126 | * @param mixed $sPath Path to dir 127 | * @param mixed $iOptions Options 128 | * 129 | * @access public 130 | * @return void 131 | */ 132 | function dir_opendir($sPath, $iOptions); 133 | /** 134 | * dir_readdir 135 | * 136 | * @access public 137 | * @return void 138 | */ 139 | function dir_readdir(); 140 | /** 141 | * dir_rewinddir 142 | * 143 | * @access public 144 | * @return void 145 | */ 146 | function dir_rewinddir(); 147 | /** 148 | * dir_closedir 149 | * 150 | * @access public 151 | * @return void 152 | */ 153 | function dir_closedir(); 154 | } 155 | require_once 'StreamWrapper/Tarz.php'; 156 | ?> 157 | -------------------------------------------------------------------------------- /Beautifier/StreamWrapper/Tarz.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright 2004-2010 Claudio Bustos 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * @version CVS: $Id:$ 21 | * @link http://pear.php.net/package/PHP_Beautifier 22 | * @link http://beautifyphp.sourceforge.net 23 | */ 24 | /** 25 | * Require Archive_Tar 26 | */ 27 | require_once 'Archive/Tar.php'; 28 | /** 29 | * Custom stream to handle Tar files (compressed and uncompressed) 30 | * Use URL tarz://myfile.tgz#myfile.php 31 | * 32 | * @category PHP 33 | * @package PHP_Beautifier 34 | * @subpackage StreamWrapper 35 | * @author Claudio Bustos 36 | * @copyright 2004-2010 Claudio Bustos 37 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 38 | * @version Release: @package_version@ 39 | * @link http://pear.php.net/package/PHP_Beautifier 40 | * @link http://beautifyphp.sourceforge.net 41 | */ 42 | class PHP_Beautifier_StreamWrapper_Tarz implements PHP_Beautifier_StreamWrapper_Interface 43 | { 44 | public $oTar; 45 | public $sTar; 46 | public $sPath; 47 | public $sText; 48 | public $iSeek = 0; 49 | public $iSeekDir = 0; 50 | public $aContents = array(); 51 | 52 | /** 53 | * stream_open 54 | * 55 | * @param mixed $sPath Path 56 | * @param mixed $sMode Mode 57 | * @param mixed $iOptions Options 58 | * @param mixed &$sOpenedPath Opended Path 59 | * 60 | * @access public 61 | * @return void 62 | */ 63 | function stream_open($sPath, $sMode, $iOptions, &$sOpenedPath) 64 | { 65 | if ($this->getTar($sPath)) { 66 | //ArrayNested->off() 67 | $aContents = $this->oTar->listContent(); 68 | if (array_filter($aContents, array($this, 'tarFileExists'))) { 69 | $this->sText = $this->oTar->extractInString($this->sPath); 70 | return true; 71 | } 72 | } 73 | //ArrayNested->on() 74 | return false; 75 | } 76 | /** 77 | * getTar 78 | * 79 | * @param mixed $sPath Path 80 | * 81 | * @access public 82 | * @return void 83 | */ 84 | function getTar($sPath) 85 | { 86 | if (preg_match("/tarz:\/\/(.*?(\.tgz|\.tar\.gz|\.tar\.bz2|\.tar)+)(?:#\/?(.*))*/", $sPath, $aMatch)) { 87 | $this->sTar = $aMatch[1]; 88 | if (strpos($aMatch[2], 'gz') !== false) { 89 | $sCompress = 'gz'; 90 | } elseif (strpos($aMatch[2], 'bz2') !== false) { 91 | $sCompress = 'bz2'; 92 | } elseif (strpos($aMatch[2], 'tar') !== false) { 93 | $sCompress = false; 94 | } else { 95 | return false; 96 | } 97 | if (isset($aMatch[3])) { 98 | $this->sPath = $aMatch[3]; 99 | } 100 | if (file_exists($this->sTar)) { 101 | $this->oTar = new Archive_Tar($this->sTar, $sCompress); 102 | return true; 103 | } 104 | } else { 105 | return false; 106 | } 107 | } 108 | /** 109 | * stream_close 110 | * 111 | * @access public 112 | * @return void 113 | */ 114 | function stream_close() 115 | { 116 | unset($this->oTar, $this->sText, $this->sPath, $this->iSeek); 117 | } 118 | /** 119 | * stream_read 120 | * 121 | * @param mixed $iCount Count 122 | * 123 | * @access public 124 | * @return void 125 | */ 126 | function stream_read($iCount) 127 | { 128 | $sRet = substr($this->sText, $this->iSeek, $iCount); 129 | $this->iSeek+= strlen($sRet); 130 | return $sRet; 131 | } 132 | /** 133 | * stream_write 134 | * 135 | * @param mixed $sData Data 136 | * 137 | * @access public 138 | * @return void 139 | */ 140 | function stream_write($sData) 141 | { 142 | } 143 | /** 144 | * stream_eof 145 | * 146 | * @access public 147 | * @return void 148 | */ 149 | function stream_eof() 150 | { 151 | // BUG in 5.0.0RC1=") and version_compare(PHP_VERSION, '5.0.0.RC.4', "<")) { 154 | return !($this->iSeek >= strlen($this->sText)); 155 | } else { 156 | return $this->iSeek >= strlen($this->sText); 157 | } 158 | } 159 | /** 160 | * stream_tell 161 | * 162 | * @access public 163 | * @return void 164 | */ 165 | function stream_tell() 166 | { 167 | return $this->iSeek; 168 | } 169 | /** 170 | * stream_seek 171 | * 172 | * @param mixed $iOffset Offset 173 | * @param mixed $iWhence Whence 174 | * 175 | * @access public 176 | * @return void 177 | */ 178 | function stream_seek($iOffset, $iWhence) 179 | { 180 | switch ($iWhence) { 181 | case SEEK_SET: 182 | if ($iOffsetsText) and $iOffset >= 0) { 183 | $this->iSeek = $iOffset; 184 | return true; 185 | } else { 186 | return false; 187 | } 188 | break; 189 | 190 | case SEEK_CUR: 191 | if ($iOffset >= 0) { 192 | $this->iSeek+= $iOffset; 193 | return true; 194 | } else { 195 | return false; 196 | } 197 | break; 198 | 199 | case SEEK_END: 200 | if (strlen($this->sText) +$iOffset >= 0) { 201 | $this->iSeek = strlen($this->sText) +$iOffset; 202 | return true; 203 | } else { 204 | return false; 205 | } 206 | break; 207 | 208 | default: 209 | return false; 210 | } 211 | } 212 | /** 213 | * stream_flush 214 | * 215 | * @access public 216 | * @return void 217 | */ 218 | function stream_flush() 219 | { 220 | } 221 | /** 222 | * stream_stat 223 | * 224 | * @access public 225 | * @return void 226 | */ 227 | function stream_stat() 228 | { 229 | } 230 | /** 231 | * unlink 232 | * 233 | * @param mixed $sPath Path 234 | * 235 | * @access public 236 | * @return void 237 | */ 238 | function unlink($sPath) 239 | { 240 | } 241 | /** 242 | * dir_opendir 243 | * 244 | * @param mixed $sPath Path 245 | * @param mixed $iOptions Options 246 | * 247 | * @access public 248 | * @return void 249 | */ 250 | function dir_opendir($sPath, $iOptions) 251 | { 252 | if ($this->getTar($sPath)) { 253 | array_walk( 254 | $this->oTar->listContent(), 255 | array( 256 | $this, 257 | 'getFileList' 258 | ) 259 | ); 260 | return true; 261 | } else { 262 | return false; 263 | } 264 | } 265 | /** 266 | * dir_readdir 267 | * 268 | * @access public 269 | * @return void 270 | */ 271 | function dir_readdir() 272 | { 273 | if ($this->iSeekDir >= count($this->aContents)) { 274 | return false; 275 | } else { 276 | return $this->aContents[$this->iSeekDir++]; 277 | } 278 | } 279 | /** 280 | * dir_rewinddir 281 | * 282 | * @access public 283 | * @return void 284 | */ 285 | function dir_rewinddir() 286 | { 287 | $this->iSeekDir = 0; 288 | } 289 | /** 290 | * dir_closedir 291 | * 292 | * @access public 293 | * @return void 294 | */ 295 | function dir_closedir() 296 | { 297 | //unset($this->oTar, $this->aContents, $this->sPath, $this->iSeekDir); 298 | //return true; 299 | 300 | } 301 | /** 302 | * getFileList 303 | * 304 | * @param mixed $aInput Input 305 | * 306 | * @access public 307 | * @return void 308 | */ 309 | function getFileList($aInput) 310 | { 311 | $this->aContents[] = $aInput['filename']; 312 | } 313 | /** 314 | * tarFileExists 315 | * 316 | * @param mixed $aInput Input 317 | * 318 | * @access public 319 | * @return void 320 | */ 321 | function tarFileExists($aInput) 322 | { 323 | return ($aInput['filename'] == $this->sPath and empty($aInput['typeflag'])); 324 | } 325 | } 326 | stream_wrapper_register("tarz", "PHP_Beautifier_StreamWrapper_Tarz"); 327 | 328 | ?> 329 | -------------------------------------------------------------------------------- /Beautifier/Tokenizer.php: -------------------------------------------------------------------------------- 1 | 17 | * @copyright 2004-2010 Claudio Bustos 18 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 19 | * @version CVS: $Id:$ 20 | * @link http://pear.php.net/package/PHP_Beautifier 21 | * @link http://beautifyphp.sourceforge.net 22 | */ 23 | /** 24 | * Interface for Tokenizer 25 | * 26 | * In the constructor, you should send the text of the file / code 27 | * The function getTokens() should send the tokens for the code, like 28 | * token_get_all() 29 | * 30 | * @category PHP 31 | * @package PHP_Beautifier 32 | * @author Claudio Bustos 33 | * @copyright 2004-2010 Claudio Bustos 34 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 35 | * @version Release: @package_version@ 36 | * @link http://pear.php.net/package/PHP_Beautifier 37 | * @link http://beautifyphp.sourceforge.net 38 | */ 39 | interface PHP_Beautifier_Tokenizer_Interface 40 | { 41 | /** 42 | * __construct 43 | * 44 | * @param mixed $sText Data to be tokenized 45 | * 46 | * @access public 47 | * @return void 48 | */ 49 | public function __construct($sText); 50 | 51 | /** 52 | * getTokens 53 | * 54 | * @access public 55 | * @return void 56 | */ 57 | public function getTokens(); 58 | } 59 | ?> 60 | -------------------------------------------------------------------------------- /Doc_PHP_Beautifier.ini: -------------------------------------------------------------------------------- 1 | ;; phpDocumentor parse configuration file 2 | ;; 3 | ;; This file is designed to cut down on repetitive typing on the command-line or web interface 4 | ;; You can copy this file to create a number of configuration files that can be used with the 5 | ;; command-line switch -c, as in phpdoc -c default.ini or phpdoc -c myini.ini. The web 6 | ;; interface will automatically generate a list of .ini files that can be used. 7 | ;; 8 | ;; default.ini is used to generate the online manual at http://www.phpdoc.org/docs 9 | ;; 10 | ;; ALL .ini files must be in the user subdirectory of phpDocumentor with an extension of .ini 11 | ;; 12 | ;; Copyright 2002, Greg Beaver 13 | ;; 14 | ;; WARNING: do not change the name of any command-line parameters, phpDocumentor will ignore them 15 | 16 | [Parse Data] 17 | ;; title of all the documentation 18 | ;; legal values: any string 19 | title = PHP_Beautifier Docs 20 | 21 | ;; parse files that start with a . like .bash_profile 22 | ;; legal values: true, false 23 | hidden = false 24 | 25 | ;; show elements marked @access private in documentation by setting this to on 26 | ;; legal values: on, off 27 | parseprivate = off 28 | 29 | ;; parse with javadoc-like description (first sentence is always the short description) 30 | ;; legal values: on, off 31 | javadocdesc = off 32 | 33 | ;; add any custom @tags separated by commas here 34 | ;; legal values: any legal tagname separated by commas. 35 | customtags = throws 36 | 37 | ;; This is only used by the XML:DocBook/peardoc2 converter 38 | defaultcategoryname = PHP 39 | 40 | ;; what is the main package? 41 | ;; legal values: alphanumeric string plus - and _ 42 | defaultpackagename = PHP_Beautifier 43 | 44 | ;; output any parsing information? set to on for cron jobs 45 | ;; legal values: on 46 | ;quiet = on 47 | 48 | ;; parse a PEAR-style repository. Do not turn this on if your project does 49 | ;; not have a parent directory named "pear" 50 | ;; legal values: on/off 51 | pear = on 52 | 53 | ;; where should the documentation be written? 54 | ;; legal values: a legal path 55 | target = site/docs 56 | 57 | ;; Which files should be parsed out as special documentation files, such as README, 58 | ;; INSTALL and CHANGELOG? This overrides the default files found in 59 | ;; phpDocumentor.ini (this file is not a user .ini file, but the global file) 60 | readmeinstallchangelog = README, INSTALL, CHANGELOG, NEWS, FAQ, LICENSE 61 | 62 | ;; limit output to the specified packages, even if others are parsed 63 | ;; legal values: package names separated by commas 64 | ;packageoutput = package1,package2 65 | 66 | ;; comma-separated list of files to parse 67 | ;; legal values: paths separated by commas 68 | filename = Beautifier.php 69 | 70 | ;; comma-separated list of directories to parse 71 | ;; legal values: directory paths separated by commas 72 | ;directory = /path1,/path2,.,..,subdirectory 73 | ;directory = /home/jeichorn/cvs/pear 74 | directory =Beautifier,tutorials 75 | 76 | ;; template base directory (the equivalent directory of /phpDocumentor) 77 | ;templatebase = /path/to/my/templates 78 | 79 | ;; directory to find any example files in through @example and {@example} tags 80 | ;examplesdir = /path/to/my/templates 81 | 82 | ;; comma-separated list of files, directories or wildcards ? and * (any wildcard) to ignore 83 | ;; legal values: any wildcard strings separated by commas 84 | ;ignore = /path/to/ignore*,*list.php,myfile.php,subdirectory/ 85 | ignore = *example*.php 86 | 87 | ;; comma-separated list of Converters to use in outputformat:Convertername:templatedirectory format 88 | ;; legal values: HTML:frames:default,HTML:frames:l0l33t,HTML:frames:phpdoc.de,HTML:frames:phphtmllib, 89 | ;; HTML:frames:earthli, 90 | ;; HTML:frames:DOM/default,HTML:frames:DOM/l0l33t,HTML:frames:DOM/phpdoc.de, 91 | ;; HTML:frames:DOM/phphtmllib,HTML:frames:DOM/earthli 92 | ;; HTML:Smarty:default,HTML:Smarty:PHP,HTML:Smarty:HandS 93 | ;; PDF:default:default,CHM:default:default,XML:DocBook/peardoc2:default 94 | ;output=HTML:frames:earthli 95 | output=HTML:frames:earthli 96 | ;; turn this option on if you want highlighted source code for every file 97 | ;; legal values: on/off 98 | sourcecode = off 99 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | = What is PHP_Beautifier? 2 | 3 | PHP_Beautifier is a Open Source PHP aplication, distributed under the terms of PHP Licence 3.0. This program tries to reformat and beautify PHP 4 and PHP 5 code automatically. 4 | Who needs it? 5 | 6 | * developers who get PHP code from other coders and are slightly confused 7 | * developers who can't read their own PHP code anymore 8 | * developers who want to share their PHP code 9 | 10 | == Little history background 11 | 12 | The first version of the program, PhpBeautify, was developed on Php 4 by Jens Bierkandt. In 2003 reached the 'stable' state and is the recomended version for the Php 4 users. This version works almost flawlessy, but was difficult to enhance, and have some problem with strange structures, like pascal-like control instructions and 'switch' structures 13 | 14 | With the stabilization of tokenizer and incoming of PHP 5, the need of a new version of the program arise. So, the code for the new version was developed from scratch by Claudio Bustos in 2004, based on the Php Tokenizer and the use of a Plug-in architecture. 15 | Where I can get PHP_Beautifier? 16 | 17 | PHP_Beautifier resources are distributed on three sites: 18 | 19 | * PEAR: Download, Change Log and bug report 20 | * Github: Sourcecode (GIT), wiki and forum 21 | 22 | == Features of PHP_Beautifier 23 | 24 | * Version independent: Needs PHP5 to work, but can handle PHP 4 and PHP 5 scripts. Should beautify PHP 3, too (if anyone test it, please send a report) 25 | * Plataform-independent: Should work on all the plataforms that supports PHP 5. Tested on Windows 98,2000,XP and Linux Gentoo 1.4.6 26 | * Automatic indentation of PHP source code according to given number of spaces 27 | * Automatic newlines, if required 28 | * You can use the web frontend, command line or, if you prefer, could use the class directly 29 | * Plug-in architecture, by the use of Filters. The control of beautify proccess is delegated on the Filters. 30 | * The code to beautify can make callbacks to the base class and the filters. So, you can set the options for the beautify inside the same file. See Callbacks 31 | * Batch processing. You can beautify multiple files inside directories (recursively, if you want to) and save they in another directory. 32 | * Parse only Php Code. All other tokens (HTML,Comments) are bypassed to the output 33 | * HEREDOC parsed without any indentation 34 | * Use of braces for indexing a string (ex. $this->myString{1}) doesn't produce strange indentation 35 | * Switch statements are indented as spected 36 | 37 | == Works with PHP 4 scripts? Will be a PHP 4 version? 38 | 39 | This package needs PHP 5 to run, but can handle any PHP file, including PHP 4 and PHP 5 scripts. 40 | 41 | In the near future, no. The use of exceptions, overloading & tokenizer - both experimental on PHP 4 - and passing by reference by default for objects could be simulated, but I prefer to focus my effort on PHP 5. But this only affect the installation of the package; you can beautify script written for PHP 4 and PHP 5, without any problem. 42 | 43 | == Is secure to use? 44 | 45 | The source code of the package beautify itself without any problem. I work with an application with more than 40.000 lines of PHP 4 source code and I did't have any broken file since 0.0.6 version. 46 | 47 | The package have a test suite to verify all the important functions. Any bug have a test to verify the fix. 48 | 49 | So, IMHO, you can use this application with confidence. Anyway, you always should make regular backups of your files and use some control version system, like CVS or Subversion. -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rake' 2 | require 'fileutils' 3 | task :test do 4 | Dir.chdir(File.dirname(__FILE__)+'/tests') 5 | system "phpunit ." 6 | Dir.chdir(File.dirname(__FILE__)) 7 | system "pear package-validate package2.xml" 8 | end 9 | 10 | task :coverage do 11 | Dir.chdir('tests') 12 | system "phpunit --coverage-html ../site/coverage ." 13 | end 14 | 15 | task :install do 16 | system "pear install package2.xml" 17 | end 18 | 19 | task :uninstall do 20 | system "pear uninstall PHP_Beautifier" 21 | end 22 | 23 | task :reinstall => [:uninstall, :install] do 24 | end 25 | 26 | task :doc do 27 | system "phpdoc -c Doc_PHP_Beautifier.ini" 28 | end 29 | 30 | task :package do 31 | FileUtils.mkdir_p "pkg" 32 | system "pear package package2.xml" 33 | system "mv PHP_Beautifier*.tgz pkg" 34 | end 35 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "clbustos/beautifier", 3 | "description": "PHP_Beautifier is a Open Source PHP aplication, distributed under the terms of PHP Licence 3.0. This program tries to reformat and beautify PHP 4 and PHP 5 code automatically.", 4 | "homepage": "https://github.com/clbustos/PHP_Beautifier", 5 | "version": "0.1.15", 6 | "minimum-stability": "dev", 7 | "authors": [ 8 | { 9 | "name": "Claudio Bustos", 10 | "email": "clbustos@gmail.com" 11 | }, 12 | { 13 | "name": "Jesús Espino", 14 | "email": "jespinog@gmail.com" 15 | } 16 | ], 17 | "license": "PHP-3.0", 18 | "repositories": [ 19 | { 20 | "type": "pear", 21 | "url": "http://pear.php.net" 22 | } 23 | ], 24 | "require": { 25 | "php": ">=5", 26 | "pear-pear.php.net/PEAR": "*", 27 | "pear-pear.php.net/Log": "*" 28 | }, 29 | "require-dev": { 30 | "phpunit/phpunit": "3.*", 31 | "fabpot/php-cs-fixer": "0.5.7" 32 | }, 33 | "bin": [ 34 | "scripts/beautifier" 35 | ], 36 | "config": { 37 | "bin-dir": "bin/" 38 | }, 39 | "preferred-install": "dist", 40 | "autoload": { 41 | "classmap": [ 42 | "Beautifier.php", 43 | "Beautifier/Batch.php", 44 | "Beautifier/Batch/Output.php", 45 | "Beautifier/Batch/Output/Directory.php", 46 | "Beautifier/Batch/Output/DirectoryBz2.php", 47 | "Beautifier/Batch/Output/DirectoryGz.php", 48 | "Beautifier/Batch/Output/DirectoryTar.php", 49 | "Beautifier/Batch/Output/Files.php", 50 | "Beautifier/Batch/Output/FilesBz2.php", 51 | "Beautifier/Batch/Output/FilesGz.php", 52 | "Beautifier/Batch/Output/FilesTar.php", 53 | "Beautifier/Common.php", 54 | "Beautifier/Decorator.php", 55 | "Beautifier/Filter.php", 56 | "Beautifier/Filter/ArrayNested.filter.php", 57 | "Beautifier/Filter/Default.filter.php", 58 | "Beautifier/Filter/DocBlock.filter.php", 59 | "Beautifier/Filter/EqualsAlign.filter.php", 60 | "Beautifier/Filter/IndentStyles.filter.php", 61 | "Beautifier/Filter/ListClassFunction.filter.php", 62 | "Beautifier/Filter/Lowercase.filter.php", 63 | "Beautifier/Filter/NewLines.filter.php", 64 | "Beautifier/Filter/Pear.filter.php", 65 | "Beautifier/Filter/phpBB.filter.php", 66 | "Beautifier/Common.php", 67 | "Beautifier/StreamWrapper.php", 68 | "Beautifier/StreamWrapper/Tarz.php", 69 | "Beautifier/Tokenizer.php" 70 | ] 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /crear_phps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find ./ -iname "*.php" -exec php_beautifier -l "ArrayNested() Pear()" {} ./site/phps/{}s \; 3 | -------------------------------------------------------------------------------- /examples/README: -------------------------------------------------------------------------------- 1 | Run the file run_me.php within the command-line or copy the files on your server directory. 2 | -------------------------------------------------------------------------------- /examples/example.js: -------------------------------------------------------------------------------- 1 | var x= { 2 | a:1, 3 | b: function() {alert('hola')} 4 | } 5 | 6 | function test(a) { 7 | return a 8 | } 9 | -------------------------------------------------------------------------------- /examples/example_array.php: -------------------------------------------------------------------------------- 1 | 1, 'el'=>2 ) ) ) ); 4 | $a=array('1','2',array( ),array( ),array( )); 5 | for($x;$x<10;$x++) {} 6 | ?> -------------------------------------------------------------------------------- /examples/example_comments.php: -------------------------------------------------------------------------------- 1 | | 17 | // | Jens Bierkandt | 18 | // +----------------------------------------------------------------------+ 19 | // 20 | // $Id: 21 | // Single line comment 22 | // Single line comment 2 23 | /* Multiline-Comment 24 | 1.- 25 | 2.- 26 | */ 27 | $sText = << 104 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /site/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clbustos/PHP_Beautifier/7505f713d7c503cc712c92af2267352598714d4c/site/style.css -------------------------------------------------------------------------------- /site/uml/PackageOverviewbatch.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clbustos/PHP_Beautifier/7505f713d7c503cc712c92af2267352598714d4c/site/uml/PackageOverviewbatch.jpg -------------------------------------------------------------------------------- /site/uml/PackageOverviewbeautifier.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clbustos/PHP_Beautifier/7505f713d7c503cc712c92af2267352598714d4c/site/uml/PackageOverviewbeautifier.jpg -------------------------------------------------------------------------------- /site/uml/PackageOverviewpear.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clbustos/PHP_Beautifier/7505f713d7c503cc712c92af2267352598714d4c/site/uml/PackageOverviewpear.jpg -------------------------------------------------------------------------------- /site/uml/PackageOverviewstreamwrapper.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clbustos/PHP_Beautifier/7505f713d7c503cc712c92af2267352598714d4c/site/uml/PackageOverviewstreamwrapper.jpg -------------------------------------------------------------------------------- /site/uml/PackageOverwievphp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clbustos/PHP_Beautifier/7505f713d7c503cc712c92af2267352598714d4c/site/uml/PackageOverwievphp.jpg -------------------------------------------------------------------------------- /site/uml/PackagePHP_Beautifier.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clbustos/PHP_Beautifier/7505f713d7c503cc712c92af2267352598714d4c/site/uml/PackagePHP_Beautifier.jpg -------------------------------------------------------------------------------- /site/view_source.php: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /tests/Beautifier/Beautifier.tar.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clbustos/PHP_Beautifier/7505f713d7c503cc712c92af2267352598714d4c/tests/Beautifier/Beautifier.tar.bz2 -------------------------------------------------------------------------------- /tests/Beautifier/Beautifier.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clbustos/PHP_Beautifier/7505f713d7c503cc712c92af2267352598714d4c/tests/Beautifier/Beautifier.tar.gz -------------------------------------------------------------------------------- /tests/Beautifier/Filter/ArrayNestedTest.php: -------------------------------------------------------------------------------- 1 | | 17 | // | Jens Bierkandt | 18 | // +----------------------------------------------------------------------+ 19 | // 20 | // $Id: 21 | 22 | require_once(dirname(__FILE__).'/../../Helpers.php'); 23 | 24 | class ArrayNestedTest extends PHPUnit_Framework_TestCase 25 | { 26 | function setUp() 27 | { 28 | error_reporting (E_ALL & ~(E_DEPRECATED | E_STRICT)); 29 | $this->oBeaut = new PHP_Beautifier(); 30 | } 31 | /** 32 | * Almost identical to original. The space after o before comment 33 | * is arbitrary, so I can't predict when I have to put a new line 34 | * 35 | */ 36 | function testArrayNestedSample() 37 | { 38 | $sSample = dirname(__FILE__) . '/arraynested_sample_file.phps'; 39 | $sContent = file_get_contents($sSample); 40 | $this->oBeaut->setInputFile($sSample); 41 | $this->oBeaut->addFilter("ArrayNested"); 42 | $this->oBeaut->process(); 43 | $sTextActual = $this->oBeaut->get(); 44 | $sTextActual = str_replace(PHP_EOL, "\n", $sTextActual); 45 | $this->assertEquals($sContent, $sTextActual); 46 | } 47 | } 48 | 49 | ?> 50 | -------------------------------------------------------------------------------- /tests/Beautifier/Filter/DocBlockTest.php: -------------------------------------------------------------------------------- 1 | | 17 | // | Jens Bierkandt | 18 | // +----------------------------------------------------------------------+ 19 | // 20 | // $Id: 21 | 22 | require_once(dirname(__FILE__).'/../../Helpers.php'); 23 | 24 | class DocBlockTest extends PHPUnit_Framework_TestCase 25 | { 26 | function setUp() 27 | { 28 | error_reporting (E_ALL & ~(E_DEPRECATED | E_STRICT)); 29 | $this->oBeaut = new PHP_Beautifier(); 30 | } 31 | /** 32 | * Almost identical to original. The space after o before comment 33 | * is arbitrary, so I can't predict when I have to put a new line 34 | * 35 | */ 36 | function testDocBlockSample() 37 | { 38 | $this->markTestSkipped( 39 | "PHP_DocBlockGenerator has changed its alignment algorithm.\n" . 40 | "See http://pear.php.net/bugs/bug.php?id=16193" 41 | ); 42 | $sSample = dirname(__FILE__) . '/docblock_sample_file.phps'; 43 | $sContent = file_get_contents($sSample); 44 | $this->oBeaut->setInputFile($sSample); 45 | $this->oBeaut->addFilter("DocBlock"); 46 | $this->oBeaut->process(); 47 | $this->assertEquals($sContent, $this->oBeaut->get()); 48 | } 49 | } 50 | 51 | ?> 52 | -------------------------------------------------------------------------------- /tests/Beautifier/Filter/IndentStylesTest.php: -------------------------------------------------------------------------------- 1 | | 17 | // | Jens Bierkandt | 18 | // +----------------------------------------------------------------------+ 19 | // 20 | // $Id: 21 | 22 | require_once(dirname(__FILE__).'/../../Helpers.php'); 23 | 24 | class IndentStylesTest extends PHPUnit_Framework_TestCase 25 | { 26 | function setUp() 27 | { 28 | error_reporting (E_ALL & ~(E_DEPRECATED | E_STRICT)); 29 | $this->oBeaut = new PHP_Beautifier(); 30 | } 31 | /** 32 | * Almost identical to original. The space after o before comment 33 | * is arbitrary, so I can't predict when I have to put a new line 34 | * 35 | */ 36 | function testIndentStylesBSDSample() 37 | { 38 | $sSample = dirname(__FILE__) . '/indentstyles_bsd_sample_file.phps'; 39 | $sContent = file_get_contents($sSample); 40 | $this->oBeaut->setInputFile($sSample); 41 | $this->oBeaut->addFilter("IndentStyles",array("style"=>"bsd")); 42 | $this->oBeaut->process(); 43 | $sTextActual = $this->oBeaut->get(); 44 | $sTextActual = str_replace(PHP_EOL, "\n", $sTextActual); 45 | $this->assertEquals($sContent, $sTextActual); 46 | } 47 | 48 | function testIndentStylesGNUSample() 49 | { 50 | $sSample = dirname(__FILE__) . '/indentstyles_gnu_sample_file.phps'; 51 | $sContent = file_get_contents($sSample); 52 | $this->oBeaut->setInputFile($sSample); 53 | $this->oBeaut->addFilter("IndentStyles",array("style"=>"gnu")); 54 | $this->oBeaut->process(); 55 | $sTextActual = $this->oBeaut->get(); 56 | $sTextActual = str_replace(PHP_EOL, "\n", $sTextActual); 57 | $this->assertEquals($sContent, $sTextActual); 58 | } 59 | 60 | function testIndentStylesWSSample() 61 | { 62 | $sSample = dirname(__FILE__) . '/indentstyles_ws_sample_file.phps'; 63 | $sContent = file_get_contents($sSample); 64 | $this->oBeaut->setInputFile($sSample); 65 | $this->oBeaut->addFilter("IndentStyles",array("style"=>"ws")); 66 | $this->oBeaut->process(); 67 | $sTextActual = $this->oBeaut->get(); 68 | $sTextActual = str_replace(PHP_EOL, "\n", $sTextActual); 69 | $this->assertEquals($sContent, $sTextActual); 70 | } 71 | 72 | function testIndentStylesKRSample() 73 | { 74 | $sSample = dirname(__FILE__) . '/indentstyles_kr_sample_file.phps'; 75 | $sContent = file_get_contents($sSample); 76 | $this->oBeaut->setInputFile($sSample); 77 | $this->oBeaut->addFilter("IndentStyles"); 78 | $this->oBeaut->process(); 79 | $sTextActual = $this->oBeaut->get(); 80 | $sTextActual = str_replace(PHP_EOL, "\n", $sTextActual); 81 | $this->assertEquals($sContent, $sTextActual); 82 | } 83 | 84 | function testIndentStylesBadSample() 85 | { 86 | $sSample = dirname(__FILE__) . '/indentstyles_kr_sample_file.phps'; 87 | $sContent = file_get_contents($sSample); 88 | $this->oBeaut->setInputFile($sSample); 89 | try { 90 | $this->oBeaut->addFilter("IndentStyles",array("style"=>"bad")); 91 | $this->oBeaut->process(); 92 | } catch(Exception $e) { 93 | $this->assertEquals($e->getMessage(),"Style bad doesn't exists"); 94 | } 95 | } 96 | } 97 | 98 | ?> 99 | -------------------------------------------------------------------------------- /tests/Beautifier/Filter/PearTest.php: -------------------------------------------------------------------------------- 1 | | 17 | // | Jens Bierkandt | 18 | // +----------------------------------------------------------------------+ 19 | // 20 | // $Id: 21 | 22 | require_once(dirname(__FILE__).'/../../Helpers.php'); 23 | 24 | class PearTest extends PHPUnit_Framework_TestCase 25 | { 26 | function setUp() 27 | { 28 | error_reporting (E_ALL & ~(E_DEPRECATED | E_STRICT)); 29 | $this->oBeaut = new PHP_Beautifier(); 30 | } 31 | /** 32 | * Almost identical to original. The space after o before comment 33 | * is arbitrary, so I can't predict when I have to put a new line 34 | * 35 | */ 36 | function testPearSample() 37 | { 38 | $sSample = dirname(__FILE__) . '/pear_sample_file.phps'; 39 | $sContent = file_get_contents($sSample); 40 | $this->oBeaut->setInputFile($sSample); 41 | $this->oBeaut->addFilter("Pear"); 42 | $this->oBeaut->process(); 43 | $sTextActual = $this->oBeaut->get(); 44 | $sTextActual = str_replace(PHP_EOL, "\n", $sTextActual); 45 | $this->markTestSkipped("Not yet finished."); 46 | $this->assertEquals($sContent, $sTextActual); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/Beautifier/Filter/arraynested_sample_file.phps: -------------------------------------------------------------------------------- 1 | sprintf("Function result", "Function result") , 11 | 'example_array' => array( 12 | 1, 13 | 2, 14 | 3 15 | ) , 16 | 'example' => null, 17 | ); 18 | ?> 19 | -------------------------------------------------------------------------------- /tests/Beautifier/Filter/docblock_sample_file.phps: -------------------------------------------------------------------------------- 1 | 19 | * @author Another Author 20 | * @copyright 1997-2005 The PHP Group 21 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 22 | * @version CVS: $Id:$ 23 | * @link http://pear.php.net/package/PackageName 24 | * @see NetOther, Net_Sample::Net_Sample() 25 | * @since File available since Release 1.2.0 26 | * @deprecated File deprecated in Release 2.0.0 27 | */ 28 | /** 29 | * This is a "Docblock Comment," also known as a "docblock." The class' 30 | * docblock, below, contains a complete description of how to write these. 31 | */ 32 | require_once 'PEAR.php'; 33 | // {{{ constants 34 | 35 | /** 36 | * Methods return this if they succeed 37 | */ 38 | define('NET_SAMPLE_OK', 1); 39 | // }}} 40 | // {{{ GLOBALS 41 | 42 | /** 43 | * The number of objects created 44 | * @global int $GLOBALS['NET_SAMPLE_Count'] 45 | */ 46 | $GLOBALS['NET_SAMPLE_Count'] = 0; 47 | // }}} 48 | // {{{ Net_Sample 49 | 50 | /** 51 | * An example of how to write code to PEAR's standards 52 | * 53 | * Docblock comments start with "/**" at the top. Notice how the "/" 54 | * lines up with the normal indenting and the asterisks on subsequent rows 55 | * are in line with the first asterisk. The last line of comment text 56 | * should be immediately followed on the next line by the closing asterisk 57 | * and slash and then the item you are commenting on should be on the next 58 | * line below that. Don't add extra lines. Please put a blank line 59 | * between paragraphs as well as between the end of the description and 60 | * the start of the @tags. Wrap comments before 80 columns in order to 61 | * ease readability for a wide variety of users. 62 | * 63 | * Docblocks can only be used for programming constructs which allow them 64 | * (classes, properties, methods, defines, includes, globals). See the 65 | * phpDocumentor documentation for more information. 66 | * http://phpdoc.org/docs/HTMLSmartyConverter/default/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html 67 | * 68 | * The Javadoc Style Guide is an excellent resource for figuring out 69 | * how to say what needs to be said in docblock comments. Much of what is 70 | * written here is a summary of what is found there, though there are some 71 | * cases where what's said here overrides what is said there. 72 | * http://java.sun.com/j2se/javadoc/writingdoccomments/index.html#styleguide 73 | * 74 | * The first line of any docblock is the summary. Make them one short 75 | * sentence, without a period at the end. Summaries for classes, properties 76 | * and constants should omit the subject and simply state the object, 77 | * because they are describing things rather than actions or behaviors. 78 | * 79 | * Below are the tags commonly used for classes. @category through @access 80 | * are required. The remainder should only be used when necessary. 81 | * Please use them in the order they appear here. phpDocumentor has 82 | * several other tags available, feel free to use them. 83 | * 84 | * @category CategoryName 85 | * @package PackageName 86 | * @author Original Author 87 | * @author Another Author 88 | * @copyright 1997-2005 The PHP Group 89 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 90 | * @version Release: @package_version@ 91 | * @link http://pear.php.net/package/PackageName 92 | * @see NetOther, Net_Sample::Net_Sample() 93 | * @since Class available since Release 1.2.0 94 | * @deprecated Class deprecated in Release 2.0.0 95 | */ 96 | class Net_Sample { 97 | // {{{ properties 98 | 99 | /** 100 | * The status of foo's universe 101 | * 102 | * Potential values are 'good', 'fair', 'poor' and 'unknown'. 103 | * 104 | * @var string 105 | */ 106 | var $foo = 'unknown'; 107 | /** 108 | * The status of life 109 | * 110 | * Note that names of private properties or methods must be 111 | * preceeded by an underscore. 112 | * 113 | * @var bool 114 | * @access private 115 | */ 116 | var $_good = true; 117 | // }}} 118 | // {{{ setFoo() 119 | 120 | /** 121 | * Registers the status of foo's universe 122 | * 123 | * Summaries for methods should use 3rd person declarative rather 124 | * than 2nd person imperative, begining with a verb phrase. 125 | * 126 | * Summaries should add description beyond the method's name. The 127 | * best method names are "self-documenting", meaning they tell you 128 | * basically what the method does. If the summary merely repeats 129 | * the method name in sentence form, it is not providing more 130 | * information. 131 | * 132 | * Summary Examples: 133 | * + Sets the label (preferred) 134 | * + Set the label (avoid) 135 | * + This method sets the label (avoid) 136 | * 137 | * Below are the tags commonly used for methods. A @param tag is 138 | * required for each parameter the method has. The @return and @access 139 | * tags are mandatory. The @throws tag is required if the 140 | * method uses exceptions. @static is required if the method can 141 | * be called statically. The remainder should only be used when 142 | * necessary. Please use them in the order they appear here. 143 | * phpDocumentor has several other tags available, feel free to use 144 | * them. 145 | * 146 | * The @param tag contains the data type, then the parameter's 147 | * name, followed by a description. By convention, the first noun in 148 | * the description is the data type of the parameter. Articles like 149 | * "a", "an", and "the" can precede the noun. The descriptions 150 | * should start with a phrase. If further description is necessary, 151 | * follow with sentences. Having two spaces between the name and the 152 | * description aids readability. 153 | * 154 | * When writing a phrase, do not capitalize and do not end with a 155 | * period: 156 | * + the string to be tested 157 | * 158 | * When writing a phrase followed by a sentence, do not capitalize the 159 | * phrase, but end it with a period to distinguish it from the start 160 | * of the next sentence: 161 | * + the string to be tested. Must use UTF-8 encoding. 162 | * 163 | * Return tags should contain the data type then a description of 164 | * the data returned. The data type can be any of PHP's data types 165 | * (int, float, bool, string, array, object, resource, mixed) 166 | * and should contain the type primarily returned. For example, if 167 | * a method returns an object when things work correctly but false 168 | * when an error happens, say 'object' rather than 'mixed.' Use 169 | * 'void' if nothing is returned. 170 | * 171 | * Here's an example of how to format examples: 172 | * 173 | * require_once 'Net/Sample.php'; 174 | * 175 | * $s = new Net_Sample(); 176 | * if (PEAR::isError($s)) { 177 | * echo $s->getMessage() . "\n"; 178 | * } 179 | * 180 | * 181 | * Here is an example for non-php example or sample: 182 | * 183 | * pear install net_sample 184 | * 185 | * 186 | * @param string $arg1 the string to quote 187 | * @param int $arg2 an integer of how many problems happened. 188 | * Indent to the description's starting point 189 | * for long ones. 190 | * 191 | * @return int the integer of the set mode used. FALSE if foo 192 | * foo could not be set. 193 | * @throws exceptionclass [description] 194 | * 195 | * @access public 196 | * @static 197 | * @see Net_Sample::$foo, Net_Other::someMethod() 198 | * @since Method available since Release 1.2.0 199 | * @deprecated Method deprecated in Release 2.0.0 200 | */ 201 | function setFoo($arg1, $arg2 = 0) { 202 | /* 203 | * This is a "Block Comment." The format is the same as 204 | * Docblock Comments except there is only one asterisk at the 205 | * top. phpDocumentor doesn't parse these. 206 | */ 207 | if ($arg1 == 'good' || $arg1 == 'fair') { 208 | $this->foo = $arg1; 209 | return 1; 210 | } elseif ($arg1 == 'poor' && $arg2 > 1) { 211 | $this->foo = 'poor'; 212 | return 2; 213 | } else { 214 | return false; 215 | } 216 | } 217 | // }}} 218 | 219 | } 220 | // }}} 221 | /* 222 | * Local variables: 223 | * tab-width: 4 224 | * c-basic-offset: 4 225 | * c-hanging-comment-ender-p: nil 226 | * End: 227 | */ 228 | ?> 229 | -------------------------------------------------------------------------------- /tests/Beautifier/Filter/indentstyles_bsd_sample_file.phps: -------------------------------------------------------------------------------- 1 | {$property}; 13 | } 14 | if ($x == 1) $x = 2; 15 | else $x = 3; 16 | while ($i++ < 4) 17 | { 18 | $obj->{'set' . $prop}($i); 19 | } 20 | ?> 21 | -------------------------------------------------------------------------------- /tests/Beautifier/Filter/indentstyles_gnu_sample_file.phps: -------------------------------------------------------------------------------- 1 | {$property}; 13 | } 14 | if ($x == 1) $x = 2; 15 | else $x = 3; 16 | while ($i++ < 4) 17 | { 18 | $obj->{'set' . $prop}($i); 19 | } 20 | ?> 21 | -------------------------------------------------------------------------------- /tests/Beautifier/Filter/indentstyles_kr_sample_file.phps: -------------------------------------------------------------------------------- 1 | {$property}; 10 | } 11 | if ($x == 1) $x = 2; 12 | else $x = 3; 13 | while ($i++ < 4) { 14 | $obj->{'set' . $prop}($i); 15 | } 16 | ?> 17 | -------------------------------------------------------------------------------- /tests/Beautifier/Filter/indentstyles_ws_sample_file.phps: -------------------------------------------------------------------------------- 1 | {$property}; 13 | } 14 | if ($x == 1) $x = 2; 15 | else $x = 3; 16 | while ($i++ < 4) 17 | { 18 | $obj->{'set' . $prop}($i); 19 | } 20 | ?> 21 | -------------------------------------------------------------------------------- /tests/Beautifier/Filter/pear_sample_file.phps: -------------------------------------------------------------------------------- 1 | 21 | * @author Another Author 22 | * @copyright 1997-2005 The PHP Group 23 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 24 | * @version CVS: $Id:$ 25 | * @link http://pear.php.net/package/PackageName 26 | * @see NetOther, Net_Sample::Net_Sample() 27 | * @since File available since Release 1.2.0 28 | * @deprecated File deprecated in Release 2.0.0 29 | */ 30 | 31 | /** 32 | * This is a "Docblock Comment," also known as a "docblock." The class' 33 | * docblock, below, contains a complete description of how to write these. 34 | */ 35 | require_once 'PEAR.php'; 36 | 37 | // {{{ constants 38 | 39 | /** 40 | * Methods return this if they succeed 41 | */ 42 | define('NET_SAMPLE_OK', 1); 43 | 44 | // }}} 45 | // {{{ GLOBALS 46 | 47 | /** 48 | * The number of objects created 49 | * @global int $GLOBALS['NET_SAMPLE_Count'] 50 | */ 51 | $GLOBALS['NET_SAMPLE_Count'] = 0; 52 | 53 | // }}} 54 | // {{{ Net_Sample 55 | 56 | /** 57 | * An example of how to write code to PEAR's standards 58 | * 59 | * Docblock comments start with "/**" at the top. Notice how the "/" 60 | * lines up with the normal indenting and the asterisks on subsequent rows 61 | * are in line with the first asterisk. The last line of comment text 62 | * should be immediately followed on the next line by the closing asterisk 63 | * and slash and then the item you are commenting on should be on the next 64 | * line below that. Don't add extra lines. Please put a blank line 65 | * between paragraphs as well as between the end of the description and 66 | * the start of the @tags. Wrap comments before 80 columns in order to 67 | * ease readability for a wide variety of users. 68 | * 69 | * Docblocks can only be used for programming constructs which allow them 70 | * (classes, properties, methods, defines, includes, globals). See the 71 | * phpDocumentor documentation for more information. 72 | * http://phpdoc.org/docs/HTMLSmartyConverter/default/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html 73 | * 74 | * The Javadoc Style Guide is an excellent resource for figuring out 75 | * how to say what needs to be said in docblock comments. Much of what is 76 | * written here is a summary of what is found there, though there are some 77 | * cases where what's said here overrides what is said there. 78 | * http://java.sun.com/j2se/javadoc/writingdoccomments/index.html#styleguide 79 | * 80 | * The first line of any docblock is the summary. Make them one short 81 | * sentence, without a period at the end. Summaries for classes, properties 82 | * and constants should omit the subject and simply state the object, 83 | * because they are describing things rather than actions or behaviors. 84 | * 85 | * Below are the tags commonly used for classes. @category through @access 86 | * are required. The remainder should only be used when necessary. 87 | * Please use them in the order they appear here. phpDocumentor has 88 | * several other tags available, feel free to use them. 89 | * 90 | * @category CategoryName 91 | * @package PackageName 92 | * @author Original Author 93 | * @author Another Author 94 | * @copyright 1997-2005 The PHP Group 95 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 96 | * @version Release: @package_version@ 97 | * @link http://pear.php.net/package/PackageName 98 | * @see NetOther, Net_Sample::Net_Sample() 99 | * @since Class available since Release 1.2.0 100 | * @deprecated Class deprecated in Release 2.0.0 101 | */ 102 | class Net_Sample 103 | { 104 | // {{{ properties 105 | 106 | /** 107 | * The status of foo's universe 108 | * 109 | * Potential values are 'good', 'fair', 'poor' and 'unknown'. 110 | * 111 | * @var string 112 | */ 113 | var $foo = 'unknown'; 114 | 115 | /** 116 | * The status of life 117 | * 118 | * Note that names of private properties or methods must be 119 | * preceeded by an underscore. 120 | * 121 | * @var bool 122 | * @access private 123 | */ 124 | var $_good = true; 125 | 126 | // }}} 127 | // {{{ setFoo() 128 | 129 | /** 130 | * Registers the status of foo's universe 131 | * 132 | * Summaries for methods should use 3rd person declarative rather 133 | * than 2nd person imperative, begining with a verb phrase. 134 | * 135 | * Summaries should add description beyond the method's name. The 136 | * best method names are "self-documenting", meaning they tell you 137 | * basically what the method does. If the summary merely repeats 138 | * the method name in sentence form, it is not providing more 139 | * information. 140 | * 141 | * Summary Examples: 142 | * + Sets the label (preferred) 143 | * + Set the label (avoid) 144 | * + This method sets the label (avoid) 145 | * 146 | * Below are the tags commonly used for methods. A @param tag is 147 | * required for each parameter the method has. The @return and 148 | * @access tags are mandatory. The @throws tag is required if the 149 | * method uses exceptions. @static is required if the method can 150 | * be called statically. The remainder should only be used when 151 | * necessary. Please use them in the order they appear here. 152 | * phpDocumentor has several other tags available, feel free to use 153 | * them. 154 | * 155 | * The @param tag contains the data type, then the parameter's 156 | * name, followed by a description. By convention, the first noun in 157 | * the description is the data type of the parameter. Articles like 158 | * "a", "an", and "the" can precede the noun. The descriptions 159 | * should start with a phrase. If further description is necessary, 160 | * follow with sentences. Having two spaces between the name and the 161 | * description aids readability. 162 | * 163 | * When writing a phrase, do not capitalize and do not end with a 164 | * period: 165 | * + the string to be tested 166 | * 167 | * When writing a phrase followed by a sentence, do not capitalize the 168 | * phrase, but end it with a period to distinguish it from the start 169 | * of the next sentence: 170 | * + the string to be tested. Must use UTF-8 encoding. 171 | * 172 | * Return tags should contain the data type then a description of 173 | * the data returned. The data type can be any of PHP's data types 174 | * (int, float, bool, string, array, object, resource, mixed) 175 | * and should contain the type primarily returned. For example, if 176 | * a method returns an object when things work correctly but false 177 | * when an error happens, say 'object' rather than 'mixed.' Use 178 | * 'void' if nothing is returned. 179 | * 180 | * Here's an example of how to format examples: 181 | * 182 | * require_once 'Net/Sample.php'; 183 | * 184 | * $s = new Net_Sample(); 185 | * if (PEAR::isError($s)) { 186 | * echo $s->getMessage() . "\n"; 187 | * } 188 | * 189 | * 190 | * Here is an example for non-php example or sample: 191 | * 192 | * pear install net_sample 193 | * 194 | * 195 | * @param string $arg1 the string to quote 196 | * @param int $arg2 an integer of how many problems happened. 197 | * Indent to the description's starting point 198 | * for long ones. 199 | * 200 | * @return int the integer of the set mode used. FALSE if foo 201 | * foo could not be set. 202 | * @throws exceptionclass [description] 203 | * 204 | * @access public 205 | * @static 206 | * @see Net_Sample::$foo, Net_Other::someMethod() 207 | * @since Method available since Release 1.2.0 208 | * @deprecated Method deprecated in Release 2.0.0 209 | */ 210 | function setFoo($arg1, $arg2 = 0) 211 | { 212 | /* 213 | * This is a "Block Comment." The format is the same as 214 | * Docblock Comments except there is only one asterisk at the 215 | * top. phpDocumentor doesn't parse these. 216 | */ 217 | if ($arg1 == 'good' || $arg1 == 'fair') { 218 | $this->foo = $arg1; 219 | return 1; 220 | } elseif ($arg1 == 'poor' && $arg2 > 1) { 221 | $this->foo = 'poor'; 222 | return 2; 223 | } else { 224 | return false; 225 | } 226 | } 227 | 228 | // }}} 229 | } 230 | 231 | // }}} 232 | 233 | /* 234 | * Local variables: 235 | * tab-width: 4 236 | * c-basic-offset: 4 237 | * c-hanging-comment-ender-p: nil 238 | * End: 239 | */ 240 | 241 | ?> 242 | -------------------------------------------------------------------------------- /tests/Beautifier/StreamWrapperTest.php: -------------------------------------------------------------------------------- 1 | | 17 | // | Jens Bierkandt | 18 | // +----------------------------------------------------------------------+ 19 | // 20 | // $Id: 21 | require_once(dirname(__FILE__).'/../Helpers.php'); 22 | 23 | 24 | class StreamWrapperTarzTest extends PHPUnit_Framework_TestCase { 25 | var $sFile; 26 | var $sFileBz2; 27 | function setUp() { 28 | $this->sFile = dirname(__FILE__) ."/Beautifier.tar.gz"; 29 | $this->sFileBz2 = dirname(__FILE__) ."/Beautifier.tar.bz2"; 30 | } 31 | function testopen() { 32 | $this->assertTrue((boolean)@fopen('tarz://'.$this->sFile."#Beautifier.php", 'r')); 33 | $this->assertfalse(@fopen('tarz://'.$this->sFile."#package2.xml", 'r')); 34 | } 35 | function testclose() { 36 | $fp = @fopen('tarz://'.$this->sFile."#Beautifier.php", 'r'); 37 | $this->assertTrue(fclose($fp)); 38 | } 39 | /** 40 | * In PHP5RcX, stream_feof was broken. 41 | * So, this function test use of feof, do loop (fread doc), 42 | * file_get_contents and file 43 | */ 44 | function testread() { 45 | $oTar = new Archive_Tar($this->sFile, 'gz'); 46 | $sExpected = $oTar->extractInString('Beautifier.php'); 47 | unset($oTar); 48 | $sActual = ''; 49 | $fp = @fopen('tarz://'.$this->sFile."#Beautifier.php", 'rb'); 50 | $this->assertTrue((boolean)$fp); 51 | if ($fp) { 52 | while (!feof($fp)) { 53 | $sBuffer = fread($fp, 8192); 54 | $sActual.= $sBuffer; 55 | } 56 | } 57 | $this->assertTrue($sExpected == $sActual, 'fread'); 58 | $sActual = ''; 59 | rewind($fp); 60 | do { 61 | $data = fread($fp, 8192); 62 | if (strlen($data) == 0) { 63 | break; 64 | } 65 | $sActual.= $data; 66 | } 67 | while (true); 68 | fclose($fp); 69 | $this->assertTrue($sExpected == $sActual, 'do'); 70 | $sActual = file_get_contents('tarz://'.$this->sFile."#Beautifier.php"); 71 | $this->assertTrue($sExpected == $sActual, 'file_get_contents'); 72 | $sActual = implode("", file('tarz://'.$this->sFile."#Beautifier.php")); 73 | $this->assertTrue($sExpected == $sActual, 'file'); 74 | } 75 | function testBz2() { 76 | $oTar = new Archive_Tar($this->sFileBz2, 'bz2'); 77 | $sExpected = $oTar->extractInString('Beautifier.php'); 78 | unset($oTar); 79 | $sActual = file_get_contents('tarz://'.$this->sFileBz2."#Beautifier.php"); 80 | $this->assertTrue($sExpected == $sActual, 'file_get_contents'); 81 | } 82 | function testOpenDir() { 83 | $oDir = opendir('tarz://'.$this->sFile); 84 | $this->assertTrue((boolean)$oDir); 85 | } 86 | function testReadDir() { 87 | if ($dh = opendir('tarz://'.$this->sFile)) { 88 | while (($file = readdir($dh)) !== false) { 89 | $fp = fopen('tarz://'.$this->sFile.'#'.$file, 'r'); 90 | $this->assertTrue((boolean)$fp); 91 | $this->assertTrue(fclose($fp)); 92 | } 93 | closedir($dh); 94 | } 95 | } 96 | } 97 | 98 | ?> 99 | -------------------------------------------------------------------------------- /tests/BeautifierCommonTest.php: -------------------------------------------------------------------------------- 1 | | 17 | // | Jens Bierkandt | 18 | // +----------------------------------------------------------------------+ 19 | // 20 | // $Id: 21 | require_once('Helpers.php'); 22 | 23 | class BeautifierCommonTest extends PHPUnit_Framework_TestCase { 24 | 25 | function testnormalizeDir() 26 | { 27 | $sDir = str_replace(DIRECTORY_SEPARATOR, '/', dirname(__FILE__)) .'/'; 28 | $this->assertEquals($sDir, PHP_Beautifier_Common::normalizeDir(dirname(__FILE__))); 29 | } 30 | function testgetFilesByPattern() 31 | { 32 | $sDir = PHP_Beautifier_Common::normalizeDir(dirname(__FILE__)); 33 | $aExpected = array( 34 | $sDir.'BeautifierTest.php' 35 | ); 36 | $this->assertEquals($aExpected, PHP_Beautifier_Common::getFilesByPattern($sDir, 'BeautifierTest\....', false)); 37 | } 38 | function testgetFilesByGlob() 39 | { 40 | $sDir = PHP_Beautifier_Common::normalizeDir(dirname(__FILE__)); 41 | $aExpected = array( 42 | $sDir.'BeautifierCommonTest.php' 43 | ); 44 | $this->assertEquals($aExpected, PHP_Beautifier_Common::getFilesByGlob($sDir.basename(__FILE__, '.php') .'.???', false)); 45 | } 46 | function testWsToString() { 47 | $this->assertEquals(' \t\r\n',PHP_Beautifier_Common::wsToString(" \t\r\n")); 48 | } 49 | 50 | } 51 | 52 | ?> -------------------------------------------------------------------------------- /tests/BeautifierInternalTest.php: -------------------------------------------------------------------------------- 1 | | 17 | // | Jens Bierkandt | 18 | // +----------------------------------------------------------------------+ 19 | // 20 | // $Id: 21 | require_once('Helpers.php'); 22 | 23 | class BeautifierInternalTest extends PHPUnit_Framework_TestCase { 24 | public $oBeaut; 25 | public $oFilter; 26 | function setUp() 27 | { 28 | $this->oBeaut = new PHP_Beautifier(); 29 | $this->oFilter = new Test_Filter($this->oBeaut); 30 | $this->oBeaut->addFilter($this->oFilter); 31 | } 32 | function setText($sText) 33 | { 34 | $this->oBeaut->setInputString($sText); 35 | $this->oBeaut->process(); 36 | } 37 | function testSetBeautify() 38 | { 39 | $sText = <<