First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,312 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Definition of PHP_Beautifier_Batch
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Batch
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Require PHP_Beautifier_Decorator
*/
require_once 'Decorator.php';
/**
* Require PHP_Beautifier_Batch_Output
*/
require_once 'Batch/Output.php';
// ArrayNested->off();
// ArrayNested->on();
/**
* Adds functionality to handle multiple files.
* - STDIN : As normal
* - STDOUT : Send all the scripts, prepended with the name of the original route
* - One in, one out: as normal
* - Multiple In, one out: determine the type of out.
* - Without '/' at the end, same as STDOUT.
* - With '/' at the end, copy the base structure and copy all the scripts
*
* You must define an input file. By default, the output is "./", so the saving
* of files will be done on the directory of your command prompt.
*
* If the file out end in .tgz, the output will be a tar archive. The same action
* will be obtained with {@link setCompress()} to true
* Use:
* <code>
* require "PHP/Beautifier.php";
* require "PHP/Beautifier/Batch.php";
* $oBeaut= new PHP_Beautifier();
* $oBatch= new PHP_Beautifier_Batch($oBeaut); // Decorator
* $oBatch->setInputFile(__FILE__);
* $oBatch->setOutputFile(dirname(__FILE__)."/beautified/");
* $oBatch->process();
* $oBatch->save();
* </code>
*
* @category PHP
* @package PHP_Beautifier
* @subpackage Batch
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
class PHP_Beautifier_Batch extends PHP_Beautifier_Decorator {
/**
* Compression method (for now, false, 'gz' and 'bz2')
* @var string
*/
private $sCompress = false;
/**
* Array or STDIN of paths to parse
* @var array
*/
private $mPreInputFiles = array();
/**
* Path to the output
*/
private $sPreOutputFile = './';
/**
* @var PHP_Beautifier_Batch_Output
*/
private $oBatchOutput;
/**
* @var array PHP_Beautifier_Batch_Input
*/
private $aBatchInputs;
public $mInputFiles;
/**
* Output mode. Could be {@link PHP_Beautifier_Batch::FILES} or
* {@link PHP_Beautifier_Batch::DIRECTORY}
*/
private $sOutputMode;
const FILES = 'Files';
const DIRECTORY = 'Directory';
/**
* Recursive search on dirs
* @var bool
*/
public $bRecursive = false;
// public methods, overloaded from PHP_Beautifier
/**
* Set recursive search for files in dirs on
* @param bool
*/
public function setRecursive($bRecursive = true)
{
$this->bRecursive = $bRecursive;
}
/**
* Set compression on/off
* @param mixed bool(false, true for gzip) or string ('gz' or 'gz2')
*/
public function setCompress($mCompress = true)
{
if ($mCompress === true) {
$mCompress = 'gz';
} elseif (!$mCompress) {
$mCompress = false;
} elseif (!is_string($mCompress)) {
throw (new Exception('You have to define a mode for compress'));
}
$this->sCompress = $mCompress;
}
/**
* Set the input(s) files
* Could be STDIN or a name, with special chars (?,*)
* @param mixed STDIN or string(path)
* @return bool
*/
public function setInputFile($mFiles)
{
$bCli = (php_sapi_name() == 'cli');
if ($bCli and $this->mPreInputFiles == STDIN and $mFiles != STDIN) {
throw (new Exception("Hey, you already defined STDIN,dude"));
} elseif ($bCli and $mFiles == STDIN) {
$this->mPreInputFiles = STDIN;
} else {
// ArrayNested->off()
if (is_string($mFiles)) {
$mFiles = array($mFiles);
}
// ArrayNested->on()
$this->mPreInputFiles = array_merge($this->mPreInputFiles, $mFiles);
}
return true;
}
/**
* Set the output file
* Could be STDOUT or a path to a file or dir (with '/' at the end)
* @param mixed STDOUT or string (path)
* @return true
*/
public function setOutputFile($sFile)
{
if (!is_string($sFile) and !(php_sapi_name() == 'cli' and $sFile == STDOUT)) {
throw (new Exception("Accept only string or STDOUT"));
}
$this->sPreOutputFile = $sFile;
return true;
}
private function setInputFilePost()
{
$bCli = php_sapi_name() == 'cli';
// ArrayNested->off()
if ($bCli and $this->mPreInputFiles == STDIN) {
$mInputFiles = array(STDIN);
} else {
$mInputFiles = array();
foreach($this->mPreInputFiles as $sPath) {
$mInputFiles = array_merge($mInputFiles, PHP_Beautifier_Common::getFilesByGlob($sPath, $this->bRecursive));
}
}
// now, we create stream references for compressed files....
foreach($mInputFiles as $sFile) {
// First, tar files
if (!($bCli and $sFile == STDIN) and preg_match("/(.tgz|\.tar\.gz|\.tar\.bz2|\.tar)$/", $sFile, $aMatch)) {
if (strpos($aMatch[1], 'gz') !== FALSE) {
$sCompress = 'gz';
} elseif (strpos($aMatch[1], 'bz2') !== FALSE) {
$sCompress = 'bz2';
} elseif (strpos($aMatch[1], 'tar') !== FALSE) {
$sCompress = false;
}
$oTar = new Archive_Tar($sFile, $sCompress);
foreach($oTar->listContent() as $aInput) {
if (empty($aInput['typeflag'])) {
$this->mInputFiles[] = 'tarz://'.$sFile.'#'.$aInput['filename'];
}
}
} else {
$this->mInputFiles[] = $sFile;
}
}
if (!$this->mInputFiles) {
throw (new Exception("Can't match any file"));
}
return true;
// ArrayNested->on()
}
private function setOutputFilePost()
{
if (php_sapi_name() == 'cli' and $this->sPreOutputFile == STDOUT) {
$this->sOutputMode = PHP_Beautifier_Batch::FILES;
} else {
$sPath = str_replace(DIRECTORY_SEPARATOR, '/', $this->sPreOutputFile);
if (!$sPath) {
$sPath = "./";
}
// determine file or dir
if (substr($sPath, -1) != '/' and !is_dir($sPath)) {
$this->sOutputMode = PHP_Beautifier_Batch::FILES;
// Define compression mode
if (preg_match("/\.(gz|bz2|tar)$/", $sPath, $aMatch)) {
$this->sCompress = $aMatch[1];
}
} else {
$this->sOutputMode = PHP_Beautifier_Batch::DIRECTORY;
}
}
return true;
}
/**
* Create the real references to files
* @return bool
* @throws Exception
*/
public function process()
{
if (!$this->mPreInputFiles) {
throw (new Exception('Input file not defined'));
} else {
$this->setInputFilePost();
$this->setOutputFilePost();
}
if (!$this->mInputFiles) {
throw (new Exception(implode(',', $this->mPreInputFiles) ." doesn't match any files"));
} else {
return true;
}
}
private function getBatchEngine()
{
$sCompress = ($this->sCompress) ? ucfirst($this->sCompress) : '';
$sClass = $this->sOutputMode.$sCompress;
$sClassEngine = 'PHP_Beautifier_Batch_Output_'.$sClass;
$sClassFile = PHP_Beautifier_Common::normalizeDir(dirname(__FILE__)) .'Batch/Output/'.$sClass.'.php';
if (!file_exists($sClassFile)) {
throw (new Exception("Doesn't exists file definition for $sClass ($sClassFile)"));
} else {
include_once ($sClassFile);
if (!class_exists($sClassEngine)) {
throw (new Exception("$sClassFile exists, but $sClassEngine isn't defined"));
} else {
return new $sClassEngine($this);
}
}
}
/**
* Save the beautified sources to file(s)
* @return bool
* @throws Exception
*/
public function save($sFile = null)
{
$oBatchEngine = $this->getBatchEngine();
return $oBatchEngine->save();
}
/**
* Return a string with the content of the file(s)
* @return string
*/
public function get()
{
$oBatchEngine = $this->getBatchEngine();
return $oBatchEngine->get();
}
public function show()
{
echo $this->get();
}
/**
* Allows subclass of {@link PHP_Beautifier_Batch_Engine} call methods of {@link $oBeaut}
* @param PHP_Beautifier_Batch_Engine
* @param string method to call
* @param array array of args
* @return mixed
*/
public function callBeautifier(PHP_Beautifier_Batch_Output $oEngine, $sMethod, $aArgs = array())
{
return @call_user_func_array(array(
$this->oBeaut,
$sMethod
) , $aArgs);
}
public function getInputFiles()
{
return $this->mInputFiles;
}
public function getOutputPath()
{
return $this->sPreOutputFile;
}
}
?>

View file

@ -0,0 +1,69 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Abstract class to superclass all batch class
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Batch
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Abstract class to superclass all batch class
*
* @category PHP
* @package PHP_Beautifier
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
abstract class PHP_Beautifier_Batch_Output
{
protected $oBatch;
public function __construct(PHP_Beautifier_Batch $oBatch)
{
$this->oBatch = $oBatch;
}
protected function beautifierSetInputFile($sFile)
{
return $this->oBatch->callBeautifier($this, 'setInputFile', array(
$sFile
));
}
protected function beautifierProcess()
{
return $this->oBatch->callBeautifier($this, 'process');
}
protected function beautifierGet()
{
return $this->oBatch->callBeautifier($this, 'get');
}
protected function beautifierSave($sFile)
{
return $this->oBatch->callBeautifier($this, 'save', array(
$sFile
));
}
public function get()
{
}
public function save()
{
}
}
?>

View file

@ -0,0 +1,74 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* PHP_Beautifier_Batch_Files
* Handle the batch process for multiple php files to one directory
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Batch
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* PHP_Beautifier_Batch_Files
* Handle the batch process for multiple php files to one directory
*
* @category PHP
* @package PHP_Beautifier
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
class PHP_Beautifier_Batch_Output_Directory extends PHP_Beautifier_Batch_Output {
public function save()
{
$aInputFiles = $this->oBatch->getInputFiles();
$sOutputPath = $this->oBatch->getOutputPath();
$aOutputFiles = PHP_Beautifier_Common::getSavePath($aInputFiles, $sOutputPath);
$oLog = PHP_Beautifier_Common::getLog();
for ($x = 0;$x<count($aInputFiles);$x++) {
try {
$this->beautifierSetInputFile($aInputFiles[$x]);
$this->beautifierProcess();
PHP_Beautifier_Common::createDir($aOutputFiles[$x]);
$this->beautifierSave($aOutputFiles[$x]);
}
catch(Exception $oExp) {
$oLog->log($oExp->getMessage() , PEAR_LOG_ERR);
}
}
return true;
}
/**
* Send the output of the files, one after another
* With a little header
* @return string
*/
public function get()
{
$aInputFiles = $this->oBatch->getInputFiles();
$sText = '';
foreach($aInputFiles as $sFile) {
$this->beautifierSetInputFile($sFile);
$this->beautifierProcess();
$sText.= $this->beautifierGet()."\n";
}
return $sText;
}
}
?>

View file

@ -0,0 +1,48 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Compress all the files to one bz2 file
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Batch
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Include PHP_Beautifier_Batch_DirectoryTar
*/
require_once ('DirectoryTar.php');
/**
* PHP_Beautifier_Batch_FilesGz
*
* Compress all the files to one bz2 file
*
* @category PHP
* @package PHP_Beautifier
* @subpackage Batch
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
class PHP_Beautifier_Batch_Output_DirectoryBz2 extends PHP_Beautifier_Batch_DirectoryTar {
protected function getTar($sFileName)
{
return new Archive_Tar($sFileName.'.tar.bz2', 'bz2');
}
}
?>

View file

@ -0,0 +1,48 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Compress all the files to one tgz file
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Batch
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Include PHP_Beautifier_Batch_DirectoryTar
*/
require_once ('DirectoryTar.php');
/**
* PHP_Beautifier_Batch_FilesGz
*
* Compress all the files to one tgz file
*
* @category PHP
* @package PHP_Beautifier
* @subpackage Batch
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
class PHP_Beautifier_Batch_Output_DirectoryGz extends PHP_Beautifier_Batch_Output_DirectoryTar {
protected function getTar($sFileName)
{
return new Archive_Tar($sFileName.'.tgz', 'gz');
}
}
?>

View file

@ -0,0 +1,65 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Manage compression of many files to one compressed file (gz or bz2)
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Batch
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Include Archive_Tar
*/
include_once 'Archive/Tar.php';
/**
* PHP_Beautifier_Batch_FilesGz
*
* Manage compression of many files to one compressed file (gz or bz2)
*
* @category PHP
* @package PHP_Beautifier
* @subpackage Batch
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
abstract class PHP_Beautifier_Batch_Output_DirectoryTar extends PHP_Beautifier_Batch_Output {
public function save()
{
$aInputFiles = $this->oBatch->getInputFiles();
$sOutputPath = $this->oBatch->getOutputPath();
$aOutputFiles = PHP_Beautifier_Common::getSavePath($aInputFiles, $sOutputPath);
for ($x = 0;$x<count($aInputFiles);$x++) {
unset($oTar);
$oTar = $this->getTar($aOutputFiles[$x]);
$this->beautifierSetInputFile($aInputFiles[$x]);
$this->beautifierProcess();
PHP_Beautifier_Common::createDir($aOutputFiles[$x]);
$oTar->addString(basename($aOutputFiles[$x]) , $this->beautifierGet());
}
return true;
}
/**
* @todo implements this
*/
protected function getTar($sFileName)
{
}
}
?>

View file

@ -0,0 +1,86 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* PHP_Beautifier_Batch_Files
* Handle the batch process for one/multiple php files to one out
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Batch
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* PHP_Beautifier_Batch_Files
* Handle the batch process for one/multiple php files to one out
*
* @category PHP
* @package PHP_Beautifier
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
class PHP_Beautifier_Batch_Output_Files extends PHP_Beautifier_Batch_Output {
public function get()
{
$aInputFiles = $this->oBatch->getInputFiles();
if (count($aInputFiles) == 1) {
$this->beautifierSetInputFile(reset($aInputFiles));
$this->beautifierProcess();
return $this->beautifierGet();
} else {
$sText = '';
foreach($aInputFiles as $sFile) {
$this->beautifierSetInputFile($sFile);
$this->beautifierProcess();
$sText.= $this->getWithHeader($sFile);
}
return $sText;
}
}
private function getWithHeader($sFile)
{
$sNewLine = $this->oBatch->callBeautifier($this, 'getNewLine');
$sHeader = '- BEGIN OF '.$sFile.' -'.$sNewLine;
$sLine = str_repeat('-', strlen($sHeader) -1) .$sNewLine;
$sEnd = '- END OF '.$sFile.str_repeat(' ', strlen($sHeader) -strlen($sFile) -12) .' -'.$sNewLine;
$sText = $sLine.$sHeader.$sLine.$sNewLine;
$sText.= $this->beautifierGet();
$sText.= $sNewLine.$sLine.$sEnd.$sLine.$sNewLine;
return $sText;
}
public function save()
{
$bCli = php_sapi_name() == 'cli';
$sFile = $this->oBatch->getOutputPath();
if ($bCli and $sFile == STDOUT) {
$fp = STDOUT;
} else {
$fp = fopen($this->oBatch->getOutputPath() , "w");
}
if (!$fp) {
throw (new Exception("Can't save file $sFile"));
}
$sText = $this->get();
fputs($fp, $sText, strlen($sText));
if (!($bCli and $fp == STDOUT)) {
fclose($fp);
}
return true;
}
}
?>

View file

@ -0,0 +1,44 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Handle the batch process for one/multiple php files to one tar bzip2 file
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Batch
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Include PHP_Beautifier_Batch_FilesGz
*/
require_once 'FilesTar.php';
/**
* Handle the batch process for one/multiple php files to one tar bzip2 file
*
* @category PHP
* @package PHP_Beautifier
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
class PHP_Beautifier_Batch_Output_FilesBz2 extends PHP_Beautifier_Batch_Output_FilesTar {
protected $sCompress = 'bz2';
protected $sExt = 'tar.bz2';
}
?>

View file

@ -0,0 +1,43 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Handle the batch process for one/multiple php files to one tar gzip file
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Batch
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Include PHP_Beautifier_Batch_FilesGz
*/
require_once 'FilesTar.php';
/**
* Handle the batch process for one/multiple php files to one tar gzip file
*
* @category PHP
* @package PHP_Beautifier
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
class PHP_Beautifier_Batch_Output_FilesGz extends PHP_Beautifier_Batch_Output_FilesTar {
protected $sCompress = 'gz';
protected $sExt = 'tgz';
}
?>

View file

@ -0,0 +1,65 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Handle the batch process for one/multiple php files to one tar compressed file
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Batch
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Require Archive_Tar
*/
include_once 'Archive/Tar.php';
/**
* Handle the batch process for one/multiple php files to one tar compressed file
* @category PHP
* @package PHP_Beautifier
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
class PHP_Beautifier_Batch_Output_FilesTar extends PHP_Beautifier_Batch_Output {
protected $oTar;
protected $sCompress=false;
protected $sExt="tar";
public function __construct(PHP_Beautifier_Batch $oBatch)
{
parent::__construct($oBatch);
$sOutput = $this->oBatch->getOutputPath();
$sOutput = preg_replace("/(\.tar|\.tar\.gz|\.tgz|\.gz|\.tar\.bz2)$/", '', $sOutput) .".".$this->sExt;
PHP_Beautifier_Common::createDir($sOutput);
$this->oTar = new Archive_Tar($sOutput, $this->sCompress);
}
public function get()
{
throw (new Exception("TODO"));
}
public function save()
{
$aInputFiles = $this->oBatch->getInputFiles();
$aOutputFiles = PHP_Beautifier_Common::getSavePath($aInputFiles);
for ($x = 0;$x<count($aInputFiles);$x++) {
$this->beautifierSetInputFile($aInputFiles[$x]);
$this->beautifierProcess();
$this->oTar->addString($aOutputFiles[$x], $this->beautifierGet());
}
}
}
?>

View file

@ -0,0 +1,238 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* PHP_Beautifier_Common and PHP_Beautifier_Interface
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Wraps commons method por PHP_Beautifier
*
* Common methods for PHP_Beautifier, almost file management.
* All the methods are static
*
* @category PHP
* @package PHP_Beautifier
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
class PHP_Beautifier_Common {
/**
* Normalize reference to directories
* @param string path to directory
* @return string normalized path to directory
*/
public static function normalizeDir($sDir)
{
$sDir = str_replace(DIRECTORY_SEPARATOR, '/', $sDir);
if (substr($sDir, -1) != '/') {
$sDir.= '/';
}
return $sDir;
}
/**
* Search, inside a dir, for a file pattern, using regular expresion
* Example:
*
* <code>PHP_Beautifier_Common::getFilesByPattern('.','*.php',true);</code>
* Search recursively for all the files with php extensions
* in the current dir
* @param string path to a dir
* @param string file pattern
* @param bool recursive?
* @return array path to files
*/
public static function getFilesByPattern($sDir, $sFilePattern, $bRecursive = false)
{
if (substr($sDir, -1) == '/') {
$sDir = substr($sDir, 0, -1);
}
$dh = @opendir($sDir);
if (!$dh) {
throw (new Exception("Cannot open directory '$sDir'"));
}
$matches = array();
while ($entry = @readdir($dh)) {
if ($entry == '.' or $entry == '..') {
continue;
} elseif (is_dir($sDir.'/'.$entry) and $bRecursive) {
$matches = array_merge($matches, PHP_Beautifier_Common::getFilesByPattern($sDir.'/'.$entry, $sFilePattern, $bRecursive));
} elseif (preg_match("/".$sFilePattern."$/", $entry)) {
$matches[] = $sDir."/".$entry;
}
}
if (!$matches) {
PHP_Beautifier_Common::getLog()->log("$sDir/$sFilePattern pattern don't match any file", PEAR_LOG_DEBUG);
}
return $matches;
}
/**
* Create a dir for a file path
* @param string file path
* @return bool
* @throws Exception
*/
public static function createDir($sFile)
{
$sDir = dirname($sFile);
if (file_exists($sDir)) {
return true;
} else {
$aPaths = explode('/', $sDir);
$sCurrentPath = '';
foreach($aPaths as $sPartialPath) {
$sCurrentPath.= $sPartialPath.'/';
if (file_exists($sCurrentPath)) {
continue;
} else {
if (!@mkdir($sCurrentPath)) {
throw (new Exception("Can't create directory '$sCurrentPath'"));
}
}
}
}
return true;
}
/**
* Return an array with the paths to save for an array of files
* @param array Array of files (input)
* @param string Init path
* @return array Array of files (output)
*/
public static function getSavePath($aFiles, $sPath = './')
{
$sPath = PHP_Beautifier_Common::normalizeDir($sPath);
// get the lowest denominator..
$sPrevious = '';
$iCut = 0;
foreach($aFiles as $i=>$sFile) {
$sFile = preg_replace("/^.*?#/", '', $sFile);
$aFiles[$i] = $sFile;
if (!$sPrevious) {
$sPrevious = dirname($sFile);
continue;
}
$aPreviousParts=explode("/",$sPrevious);
$aCurrentParts=explode("/",dirname($sFile));
for($x=0;$x<count($aPreviousParts);$x++) {
if($aPreviousParts[$x]!=$aCurrentParts[$x]) {
$sPrevious=implode("/",array_slice($aPreviousParts,0,$x));
}
}
}
$iCut = strlen($sPrevious);
$aPathsOut = array();
foreach($aFiles as $sFile) {
$sFileOut = preg_replace("/^(\w:\/|\.\/|\/)/", "", substr($sFile, $iCut));
$aPathsOut[] = $sPath.$sFileOut;
}
return $aPathsOut;
}
/**
* Search, inside a dir, for a file pattern using glob(* and ?)
* @param string path
* @param bool recursive
* @return array path to files
*/
public static function getFilesByGlob($sPath, $bRecursive = false)
{
if (!$bRecursive) {
return glob($sPath);
} else {
$sDir = (dirname($sPath)) ? realpath(dirname($sPath)) : realpath('./');
$sDir = PHP_Beautifier_Common::normalizeDir($sDir);
$sDir = substr($sDir, 0, -1); // strip last slash
$sGlob = basename($sPath);
$dh = @opendir($sDir);
if (!$dh) {
throw (new Exception("Cannot open directory '$sPath'"));
}
$aMatches = glob($sDir.'/'.$sGlob);
while ($entry = @readdir($dh)) {
if ($entry == '.' or $entry == '..') {
continue;
} elseif (is_dir($sDir.'/'.$entry)) {
$aMatches = array_merge($aMatches, PHP_Beautifier_Common::getFilesByGlob($sDir.'/'.$entry.'/'.$sGlob, true));
}
}
return $aMatches;
}
}
/**
* Get a {@link Log_composite} object for PHP_Beautifier
* Always return the same object (Singleton pattern)
* @return Log_composite
*/
public static function getLog()
{
return Log::singleton('composite', 'PHP_Beautifier');
}
/**
* Transform whitespaces into its representation
* So, tabs becomes \t, newline \n and feed \r
* Useful for log
* @param string
* @return string
*/
public static function wsToString($sText)
{
// ArrayNested->off();
return str_replace(array("\r", "\n", "\t"), array('\r', '\n', '\t'), $sText);
// ArrayNested->on();
}
}
// Interfaces
/**
* Interface for PHP_Beautifier and subclasses.
* Created to made a 'legal' Decorator implementation
*
* @category PHP
* @package PHP_Beautifier
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
interface PHP_Beautifier_Interface {
/**
* Process the file(s) or string
*/
public function process();
/**
* Show on screen the output
*/
public function show();
/**
* Get the output on a string
* @return string
*/
public function get();
/**
* Save the output to a file
* @param string path to file
*/
public function save($sFile = null);
}
?>

View file

@ -0,0 +1,51 @@
<?php
/**
* Pattern: Decorator
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Implements the Decorator Pattern
*
* @category PHP
* @package PHP_Beautifier
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
abstract class PHP_Beautifier_Decorator implements PHP_Beautifier_Interface {
protected $oBeaut;
function __construct(PHP_Beautifier_Interface $oBeaut)
{
$this->oBeaut = $oBeaut;
}
function __call($sMethod, $aArgs)
{
if (!method_exists($this->oBeaut, $sMethod)) {
throw (new Exception("Method '$sMethod' doesn't exists"));
} else {
return call_user_func_array(array(
$this->oBeaut,
$sMethod
) , $aArgs);
}
}
}
?>

View file

@ -0,0 +1,36 @@
<?php
/**
* Exception.php
* Definition for Exceptions
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Exception for Filters
*
* @category PHP
* @package PHP_Beautifier
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
class Exception_PHP_Beautifier_Filter extends PEAR_Exception
{
}
?>

View file

@ -0,0 +1,257 @@
<?php
/**
* Definition of class PHP_Beautifier_Filter
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* PHP_Beautifier_Filter
*
* Definition for creation of Filters
* For concrete details, please see {@link PHP_Beautifier_Filter_Default}
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @tutorial PHP_Beautifier/Filter/Filter.create.pkg
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
abstract class PHP_Beautifier_Filter
{
/**
* Stores a reference to main PHP_Beautifier
* @var PHP_Beautifier
*/
protected $oBeaut;
/**
* Associative array of functions to use when some token are found
* @var array
*/
protected $aFilterTokenFunctions = array();
/**
* Settings for the Filter
* @var array
*/
protected $aSettings = array();
/**
* Definition of the settings
* Should be an associative array. The keys are the names of settings
* and the values are an array with the keys 'type' and '
* @var array
*/
protected $aSettingsDefinition = array();
/**
* Description of the Filter
* @var string
*/
protected $sDescription = 'Filter for PHP_Beautifier';
/**
* If a method for parse Tokens of a Filter returns this, the control of the process
* is handle by the next Filter
*/
const BYPASS = 'BYPASS';
/**
* Switch to 'turn' on and off the filter
* @var bool
*/
protected $bOn = true;
/**
* Current token
*/
protected $aToken = false;
/**
* Constructor
* If you need to overload this (for example, to create a
* definition for setting with {@link addSettingDefinition()}
* remember call the parent constructor.
* <code>
* parent::__construct($oBeaut, $aSettings)
* </code>
* @param PHP_Beautifier
* @param array settings for the Filter
*/
public function __construct(PHP_Beautifier $oBeaut, $aSettings = array())
{
$this->oBeaut = $oBeaut;
if ($aSettings) {
$this->aSettings = $aSettings;
}
}
/**
* Add a setting definition
* @param string
*/
protected function addSettingDefinition($sSetting, $sType, $sDescription)
{
$this->aSettingsDefinition[$sSetting] = array(
'type' => $sType,
'description' => $sDescription
);
}
/**
* return @string
*/
public function getName()
{
return str_ireplace('PHP_Beautifier_Filter_', '', get_class($this));
}
/**
* Turn on the Filter
* Use inside the code to beautify
* Ex.
* <code>
* ...some code...
* // ArrayNested->on()
* ...other code ...
* </code>
*/
final public function on()
{
$this->bOn = true;
}
/**
* Turn off the Filter
* Use inside the code to beautify
* Ex.
* <code>
* ...some code...
* // ArrayNested->off()
* ...other code ...
* </code>
*/
public function off()
{
$this->bOn = false;
}
/**
* Get a setting of the Filter
* @param string name of setting
* @return mixed value of setting or false
*/
final public function getSetting($sSetting)
{
return (array_key_exists($sSetting, $this->aSettings)) ? $this->aSettings[$sSetting] : false;
}
/**
* Set a value of a Setting
* @param string name of setting
* @param mixed value of setting
*/
final public function setSetting($sSetting, $sValue)
{
if (array_key_exists($sSetting, $this->aSettings)) {
$this->aSettings[$sSetting] = $sValue;
}
}
/**
* Function called from {@link PHP_Beautifier::process()} to process the tokens.
*
* If the received token is one of the keys of {@link $aFilterTokenFunctions}
* a function with the same name of the value of that key is called.
* If the method doesn't exists, {@link __call()} is called, and return
* {@link PHP_Beautifier_Filter::BYPASS}. PHP_Beautifier, now, call the next Filter is its list.
* If the method exists, it can return true or {@link PHP_Beautifier_Filter::BYPASS}.
* @param array token
* @return bool true if the token is processed, false bypass to the next Filter
* @see PHP_Beautifier::process()
*/
public function handleToken($token)
{
$this->aToken = $token;
if (!$this->bOn) {
return false;
}
$sMethod = $sValue = false;
if (array_key_exists($token[0], $this->aFilterTokenFunctions)) {
$sMethod = $this->aFilterTokenFunctions[$token[0]];
$sValue = $token[1];
} elseif ($this->oBeaut->getTokenFunction($token[0])) {
$sMethod = $this->oBeaut->getTokenFunction($token[0]);
}
$sValue = $token[1];
if ($sMethod) {
if ($this->oBeaut->iVerbose > 5) {
echo $sMethod . ":" . trim($sValue) . "\n";
}
// return false if PHP_Beautifier_Filter::BYPASS
return ($this->$sMethod($sValue) !== PHP_Beautifier_Filter::BYPASS);
} else { // WEIRD!!! -> Add the same received
$this->oBeaut->add($token[1]);
PHP_Beautifier_Common::getLog()->log("Add same received:" . trim($token[1]) , PEAR_LOG_DEBUG);
return true;
}
// never go here
return false;
}
/**
* @param string metodo
* @param array arguments
* @return mixed null or {@link PHP_Beautifier_Filter::BYPASS}
*/
public function __call($sMethod, $aArgs)
{
return PHP_Beautifier_Filter::BYPASS;
}
/**
* Called from {@link PHP_Beautifier::process()} at the beginning
* of the processing
* @return void
*/
public function preProcess()
{
}
/**
* Called from {@link PHP_Beautifier::process()} at the end of processing
* The post-process must be made in {@link PHP_Beautifier::$aOut}
* @return void
*/
public function postProcess()
{
}
public function __sleep()
{
return array(
'aSettings'
);
}
public function getDescription()
{
return $this->sDescription;
}
public function __toString()
{
// php_beautifier->setBeautify(false);
$sOut='Filter: '.$this->getName()."\n".
"Description: ".$this->getDescription()."\n";
if (!$this->aSettingsDefinition) {
$sOut.= "Settings: No declared settings";
} else {
$sOut.="Settings:\n";
foreach($this->aSettingsDefinition as $sSetting=>$aSettings) {
$sOut.=sprintf("- %s : %s (type %s)\n",$sSetting, $aSettings['description'], $aSettings['type']);
}
}
// php_beautifier->setBeautify(true);
return $sOut;
}
}
?>

View file

@ -0,0 +1,84 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Filter Array Nested: Indent the array structures
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Filter Array Nested: Indent the array structures
* Ex.
* <CODE>
* $aMyArray = array(
* array(
* array(
* array(
* 'el'=>1,
* 'el'=>2
* )
* )
* )
* );
* </CODE>
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
class PHP_Beautifier_Filter_ArrayNested extends PHP_Beautifier_Filter
{
public function t_parenthesis_open($sTag)
{
$this->oBeaut->add($sTag);
if ($this->oBeaut->getControlParenthesis() == T_ARRAY) {
$this->oBeaut->addNewLine();
$this->oBeaut->incIndent();
$this->oBeaut->addIndent();
}
}
public function t_parenthesis_close($sTag)
{
$this->oBeaut->removeWhitespace();
if ($this->oBeaut->getControlParenthesis() == T_ARRAY) {
$this->oBeaut->decIndent();
if ($this->oBeaut->getPreviousTokenContent() != '(') {
$this->oBeaut->addNewLine();
$this->oBeaut->addIndent();
}
$this->oBeaut->add($sTag . ' ');
} else {
$this->oBeaut->add($sTag . ' ');
}
}
public function t_comma($sTag)
{
if ($this->oBeaut->getControlParenthesis() != T_ARRAY) {
$this->oBeaut->add($sTag . ' ');
} else {
$this->oBeaut->add($sTag);
$this->oBeaut->addNewLine();
$this->oBeaut->addIndent();
}
}
}
?>

View file

@ -0,0 +1,438 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Default Filter: Handle all the tokens. Uses K & R style
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Default Filter: Handle all the tokens. Uses K & R style
*
* This filters is loaded by default in {@link PHP_Beautifier}. Can handle all the tokens.
* If one of the tokens doesn't have a function, is added wihout modification (See {@link __call()})
* The most important modifications are:
* - All the statements inside control structures, functions and class are indented with K&R style
* <CODE>
* function myFunction() {
* echo 'hi';
* }
* </CODE>
* - All the comments in new lines are indented. In multi-line comments, all the lines are indented, too.
* This class is final, so don't try to extend it!
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
final class PHP_Beautifier_Filter_Default extends PHP_Beautifier_Filter
{
protected $sDescription = 'Default Filter for PHP_Beautifier';
function __call($sMethod, $aArgs)
{
if (!is_array($aArgs) or count($aArgs) != 1) {
throw (new Exception('Call to Filter::__call with wrong argument'));
}
PHP_Beautifier_Common::getLog()->log('Default Filter:unhandled[' . $aArgs[0] . ']', PEAR_LOG_DEBUG);
$this->oBeaut->add($aArgs[0]);
}
// Bypass the function!
public function off()
{
}
public function t_access($sTag)
{
$this->oBeaut->add($sTag . ' ');
}
public function t_end_heredoc($sTag)
{
$this->oBeaut->add(trim($sTag));
$this->oBeaut->addNewLineIndent();
}
public function t_open_tag($sTag)
{
$this->oBeaut->add(trim($sTag));
preg_match("/([\s\r\n\t]+)$/", $sTag, $aMatch);
$aNextToken = $this->oBeaut->getToken($this->oBeaut->iCount+1);
$sNextWhitespace = ($aNextToken[0] == T_WHITESPACE) ? $aNextToken[1] : '';
$sWhitespace = @$aMatch[1] . $sNextWhitespace;
if (preg_match("/[\r\n]+/", $sWhitespace)) {
$this->oBeaut->addNewLineIndent();
} else {
$this->oBeaut->add(" ");
}
}
function t_close_tag($sTag)
{
$this->oBeaut->removeWhitespace();
if (preg_match("/\r|\n/", $this->oBeaut->getPreviousWhitespace())) {
$this->oBeaut->addNewLine();
$this->oBeaut->add($sTag);
} else {
$this->oBeaut->add(" " . $sTag);
}
}
function t_switch($sTag)
{
$this->t_control($sTag);
}
function t_control($sTag)
{
$this->oBeaut->add($sTag . ' ');
}
function t_case($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->decIndent();
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add($sTag . ' ');
//$this->oBeaut->incIndent();
}
function t_parenthesis_open($sTag)
{
$this->oBeaut->add($sTag);
}
function t_parenthesis_close($sTag)
{
if (!$this->oBeaut->isPreviousTokenConstant(T_COMMENT) and !$this->oBeaut->isPreviousTokenConstant(T_END_HEREDOC)) {
$this->oBeaut->removeWhitespace();
}
$this->oBeaut->add($sTag);
if(!$this->oBeaut->isNextTokenContent(';')) {
$this->oBeaut->add(' ');
}
}
function t_open_brace($sTag)
{
if ($this->oBeaut->openBraceDontProcess()) {
$this->oBeaut->add($sTag);
} else {
if ($this->oBeaut->removeWhiteSpace()) {
$this->oBeaut->add(' ' . $sTag);
} else {
$this->oBeaut->add($sTag);
}
$this->oBeaut->incIndent();
if ($this->oBeaut->getControlSeq() == T_SWITCH) {
$this->oBeaut->incIndent();
}
$this->oBeaut->addNewLineIndent();
}
}
function t_close_brace($sTag)
{
if ($this->oBeaut->getMode('string_index') or $this->oBeaut->getMode('double_quote')) {
$this->oBeaut->add($sTag);
} else {
$this->oBeaut->removeWhitespace();
$this->oBeaut->decIndent();
if ($this->oBeaut->getControlSeq() == T_SWITCH) {
$this->oBeaut->decIndent();
}
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add($sTag);
$this->oBeaut->addNewLineIndent();
}
}
function t_semi_colon($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->add($sTag);
if ($this->oBeaut->getControlParenthesis() != T_FOR) {
$this->oBeaut->addNewLineIndent();
}
}
function t_as($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->add(' ' . $sTag . ' ');
}
function t_new($sTag)
{
$this->oBeaut->add(' ' . $sTag . ' ');
}
function t_whitespace($sTag)
{
}
function t_doc_comment($sTag)
{
$this->oBeaut->removeWhiteSpace();
$this->oBeaut->addNewLineIndent();
// process doc
preg_match("/(\/\*\*[^\r\n]*)(.*?)(\*\/)/sm", $sTag, $aMatch);
$sDoc = $aMatch[2];
// if is a one-line-doc, leave as-is
if (!preg_match("/\r\n|\r|\n/", $sDoc)) {
$this->add($sTag);
$this->oBeaut->addNewLineIndent();
} else { // is a multi line doc...
$aLines = preg_split("/\r\n|\r|\n/", $sDoc);
$this->oBeaut->add($aMatch[1]);
foreach($aLines as $sLine) {
if ($sLine = trim($sLine)) {
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add(" " . $sLine);
}
}
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add(" " . $aMatch[3]);
$this->oBeaut->addNewLineIndent();
}
}
function t_comment($sTag)
{
if ($this->oBeaut->removeWhitespace()) {
if (preg_match("/\r|\n/", $this->oBeaut->getPreviousWhitespace())) {
$this->oBeaut->addNewLineIndent();
} else {
$this->oBeaut->add(' ');
}
}
if (substr($sTag, 0, 2) == '/*') { // Comentario largo
$this->comment_large($sTag);
} else { // comentario corto
$this->comment_short($sTag);
}
}
function comment_short($sTag)
{
$this->oBeaut->add(trim($sTag));
$this->oBeaut->addNewLineIndent();
}
function comment_large($sTag)
{
if ($sTag == '/*{{{*/' or $sTag == '/*}}}*/') { // folding markers
$this->oBeaut->add(' ' . $sTag);
$this->oBeaut->addNewLineIndent();
} else {
$aLines = explode("\n", $sTag);
foreach($aLines as $sLinea) {
$this->oBeaut->add(trim($sLinea));
$this->oBeaut->addNewLineIndent();
}
}
}
/**
* @uses detect_colon_after_parenthesis
*/
function t_else($sTag)
{
if ($this->oBeaut->isPreviousTokenConstant(T_COMMENT)) {
// do nothing!
} elseif ($this->oBeaut->isPreviousTokenContent('}')) {
$this->oBeaut->removeWhitespace();
$this->oBeaut->add(' ');
} else {
$this->oBeaut->removeWhitespace();
if ($this->oBeaut->isNextTokenContent(':') or ($sTag == 'elseif' and $this->detect_colon_after_parenthesis())) {
$this->oBeaut->decIndent();
}
$this->oBeaut->addNewLineIndent();
}
$this->oBeaut->add($sTag . ' ');
}
/**
* Detect structure elseif($something):
*/
private function detect_colon_after_parenthesis()
{
$iPar = 1;
$x = 2;
while ($iPar and $x < 100) {
if ($this->oBeaut->isNextTokenContent('(', $x)) {
$iPar++;
} elseif ($this->oBeaut->isNextTokenContent(')', $x)) {
$iPar--;
}
$x++;
}
if ($x == 100) {
throw new Exception("Elseif doesn't have an ending parenthesis");
}
return $this->oBeaut->isNextTokenContent(':', $x);
}
function t_equal($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->add(' ' . $sTag . ' ');
}
function t_logical($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->add(' ' . $sTag . ' ');
}
function t_for($sTag)
{
$this->oBeaut->add($sTag . ' ');
}
function t_comma($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->add($sTag . ' ');
}
function t_dot($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->add(' ' . $sTag . ' ');
}
function t_include($sTag)
{
$this->oBeaut->add($sTag . ' ');
}
function t_language_construct($sTag)
{
$this->oBeaut->add($sTag . ' ');
}
function t_constant_encapsed_string($sTag)
{
$this->oBeaut->add($sTag);
}
function t_variable($sTag)
{
if ($this->oBeaut->isPreviousTokenConstant(T_STRING) and !$this->oBeaut->getMode("double_quote")) {
$this->oBeaut->add(' ');
}
$this->oBeaut->add($sTag);
}
function t_question($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->add(' ' . $sTag . ' ');
}
function t_colon($sTag)
{
$this->oBeaut->removeWhitespace();
if ($this->oBeaut->getMode('ternary_operator')) {
$this->oBeaut->add(' ' . $sTag . ' ');
} else {
$this->oBeaut->add($sTag);
$this->oBeaut->incIndent();
$this->oBeaut->addNewLineIndent();
}
}
function t_double_colon($sTag)
{
$this->oBeaut->add($sTag);
}
function t_break($sTag)
{
if ($this->oBeaut->getControlSeq() == T_SWITCH) {
$this->oBeaut->removeWhitespace();
$this->oBeaut->decIndent();
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add($sTag);
$this->oBeaut->incIndent();
} else {
$this->oBeaut->add($sTag);
}
if ($this->oBeaut->isNextTokenConstant(T_LNUMBER)) {
$this->oBeaut->add(" ");
}
}
function t_default($sTag)
{
$this->t_case($sTag);
}
function t_end_suffix($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->decIndent();
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add($sTag);
}
function t_extends($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->add(' ' . $sTag . ' ');
}
function t_implements($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->add(' ' . $sTag . ' ');
}
function t_instanceof($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->add(' ' . $sTag . ' ');
}
function t_equal_sign($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->add(' ' . $sTag . ' ');
}
function t_assigment($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->add(' ' . $sTag . ' ');
}
function t_assigment_pre($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->add($sTag . ' ');
}
function t_clone($sTag) {
$this->oBeaut->add($sTag.' ');
}
function t_array($sTag)
{
$this->oBeaut->add($sTag);
// Check this, please!
if (!$this->oBeaut->isNextTokenContent('(')) {
$this->oBeaut->add(" ");
}
}
function t_object_operator($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->add($sTag);
}
function t_operator($sTag)
{
$this->oBeaut->removeWhitespace();
// binary operators should have a space before and after them. unary ones should just have a space before them.
switch ($this->oBeaut->getTokenFunction($this->oBeaut->getPreviousTokenConstant())) {
case 't_question':
case 't_colon':
case 't_comma':
case 't_dot':
case 't_case':
case 't_echo':
case 't_language_construct': // print, echo, return, etc.
case 't_operator':
$this->oBeaut->add(' ' . $sTag);
break;
case 't_parenthesis_open':
case 't_open_square_brace':
case 't_open_brace':
$this->oBeaut->add($sTag);
break;
default:
$this->oBeaut->add(' ' . $sTag . ' ');
}
}
}
?>

View file

@ -0,0 +1,227 @@
<?php
/**
* Filter Indent Styles: Indent the code in k&r, allman, gnu or whitesmiths
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Filter Indent Styles: Indent the code in k&r, allman, gnu or whitesmiths
*
* Use 'style' setting to select the style. You can change the style inside
* the file, using the callbacks features.
* The following is a description taken from {@link http://catb.org/~esr/jargon/html/I/indent-style.html }
*
* K&R style <b>['k&r']</b> Named after Kernighan & Ritchie, because the examples in K&R are formatted this way. Also called kernel style because the Unix kernel is written in it, and the "One True Brace Style" (abbrev. 1TBS) by its partisans. In C code, the body is typically indented by eight spaces (or one tab) per level, as shown here. Four spaces are occasionally seen in C, but in C++ and Java four tends to be the rule rather than the exception.
*
*<CODE>
*if (<cond>) {
* <body>
* }
*</CODE>
*
* Allman style <b>['allman' or 'bsd']</b> Named for Eric Allman, a Berkeley hacker who wrote a lot of the BSD utilities in it (it is sometimes called BSD style). Resembles normal indent style in Pascal and Algol. It is the only style other than K&R in widespread use among Java programmers. Basic indent per level shown here is eight spaces, but four (or sometimes three) spaces are generally preferred by C++ and Java programmers.
*
*<CODE>
* if (<cond>)
* {
* <body>
* }
* </CODE>
*
*
* Whitesmiths style <b>['whitesmiths']</b>? popularized by the examples that came with Whitesmiths C, an early commercial C compiler. Basic indent per level shown here is eight spaces, but four spaces are occasionally seen.
*
* <CODE>
* if (<cond>)
* {
* <body>
* }
* </CODE>
*
* GNU style <b>['gnu']</b> Used throughout GNU EMACS and the Free Software Foundation code, and just about nowhere else. Indents are always four spaces per level, with { and } halfway between the outer and inner indent levels.
*
*<CODE>
* if (<cond>)
* {
* <body>
* }
* </CODE>
*
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
class PHP_Beautifier_Filter_IndentStyles extends PHP_Beautifier_Filter
{
protected $aSettings = array(
'style' => 'K&R'
);
public $aAllowedStyles = array(
"k&r" => "kr",
"allman" => "bsd",
"bsd" => "bsd",
"gnu" => "gnu",
"whitesmiths" => "ws",
"ws" => "ws"
);
protected $sDescription = 'Filter the code in 4 different indent styles: K&R, Allman, Whitesmiths and GNU';
public function __construct(PHP_Beautifier $oBeaut, $aSettings = array())
{
parent::__construct($oBeaut, $aSettings);
$this->addSettingDefinition('style', 'text', 'Style for indent: K&R, Allman, Whitesmiths, GNU');
}
public function __call($sMethod, $aArgs)
{
if (strtolower($this->getSetting('style')) == 'k&r') {
return PHP_Beautifier_Filter::BYPASS;
}
$sNewMethod = $this->_getFunctionForStyle($sMethod);
if (method_exists($this, $sNewMethod)) {
call_user_func_array(array(
$this,
$sNewMethod
) , $aArgs);
} else {
return PHP_Beautifier_Filter::BYPASS;
}
}
/**
* Open braces in BSD style
* @param string '{'
*/
function t_open_brace_bsd($sTag)
{
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add($sTag);
$this->oBeaut->incIndent();
$this->oBeaut->addNewLineIndent();
}
/**
* Close braces in BSD style
* @param string '}'
*/
function t_close_brace_bsd($sTag)
{
if ($this->oBeaut->getMode('string_index') or $this->oBeaut->getMode('double_quote')) {
$this->oBeaut->add($sTag);
} else {
$this->oBeaut->removeWhitespace();
$this->oBeaut->decIndent();
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add($sTag);
$this->oBeaut->addNewLineIndent();
}
}
/**
* Open braces in Whitesmiths style
* @param string '{'
*/
function t_open_brace_ws($sTag)
{
$this->oBeaut->addNewLine();
$this->oBeaut->incIndent();
$this->oBeaut->addIndent();
$this->oBeaut->add($sTag);
$this->oBeaut->addNewLineIndent();
}
/**
* Close braces in Whitesmiths style
* @param string '}'
*/
function t_close_brace_ws($sTag)
{
if ($this->oBeaut->getMode('string_index') or $this->oBeaut->getMode('double_quote')) {
$this->oBeaut->add($sTag);
} else {
$this->oBeaut->removeWhitespace();
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add($sTag);
$this->oBeaut->decIndent();
$this->oBeaut->addNewLineIndent();
}
}
/**
* Close braces in GNU style
* @param string '}'
*/
function t_close_brace_gnu($sTag)
{
if ($this->oBeaut->getMode('string_index') or $this->oBeaut->getMode('double_quote')) {
$this->oBeaut->add($sTag);
} else {
$iHalfSpace = floor($this->oBeaut->iIndentNumber/2);
$this->oBeaut->removeWhitespace();
$this->oBeaut->decIndent();
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add(str_repeat($this->oBeaut->sIndentChar, $iHalfSpace));
$this->oBeaut->add($sTag);
$this->oBeaut->addNewLineIndent();
}
}
/**
* Open braces in GNU style
* @param string '{'
*/
function t_open_brace_gnu($sTag)
{
$iHalfSpace = floor($this->oBeaut->iIndentNumber/2);
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add(str_repeat($this->oBeaut->sIndentChar, $iHalfSpace));
$this->oBeaut->add($sTag);
$this->oBeaut->incIndent();
$this->oBeaut->addNewLineIndent();
}
/**
* Else for bds, gnu & ws
* @param string else or elseif
* @return void|PHP_Beautifier_Filter::BYPASS
*/
function t_else($sTag)
{
if ($this->oBeaut->getPreviousTokenContent() == '}') {
$this->oBeaut->removeWhitespace();
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add(trim($sTag));
if (!$this->oBeaut->isNextTokenContent('{')) {
$this->oBeaut->add(' ');
}
} else {
return PHP_Beautifier_Filter::BYPASS;
}
}
/**
* Return the method for the defined style
* @param string method to search
* @return string method renamed for the defined style
*/
private function _getFunctionForStyle($sMethod)
{
$sStyle = strtolower($this->getSetting('style'));
if (!array_key_exists($sStyle, $this->aAllowedStyles)) {
throw (new Exception("Style " . $sStyle . "doesn't exists"));
}
return $sMethod . "_" . $this->aAllowedStyles[$sStyle];
}
}
?>

View file

@ -0,0 +1,150 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Create a list of functions and classes in the script
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Create a list of functions and classes in the script
* By default, this Filter puts the list at the beggining of the script.
* If you want it in another position, put a comment like that
* <pre>
* // Class and Function List
* </pre>
* The script lookup for the string 'Class and Function List' in a comment and replace the entire comment with the list
* The settings are
* - list_functions: List functions (0 or 1). Default:1
* - list_classes: List classes (0 or 1). Default:1
* @todo List functions inside classes as methods
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
class PHP_Beautifier_Filter_ListClassFunction extends PHP_Beautifier_Filter
{
protected $aFilterTokenFunctions = array(
T_CLASS => 't_class',
T_FUNCTION => 't_function',
T_COMMENT => 't_comment',
T_OPEN_TAG => 't_open_tag'
);
private $aFunctions = array();
private $aClasses = array();
private $iComment;
private $iOpenTag = null;
protected $aSettings = array(
'list_functions' => true,
'list_classes' => true
);
protected $sDescription = 'Create a list of functions and classes in the script';
private $aInclude = array(
'functions' => true,
'classes' => true
);
public function __construct(PHP_Beautifier $oBeaut, $aSettings = array())
{
parent::__construct($oBeaut, $aSettings);
$this->addSettingDefinition('list_functions', 'bool', 'List Functions inside the file');
$this->addSettingDefinition('list_classes', 'bool', 'List Classes inside the file');
}
function t_function($sTag)
{
if ($this->aInclude['functions']) {
$sNext = $this->oBeaut->getNextTokenContent(1);
if ($sNext == '&') {
$sNext.= $this->oBeaut->getNextTokenContent(2);
}
array_push($this->aFunctions, $sNext);
}
return PHP_Beautifier_Filter::BYPASS;
}
function includeInList($sTag, $sValue)
{
$this->aInclude[$sTag] = $sValue;
}
function t_class($sTag)
{
if ($this->aInclude['classes']) {
$sClassName = $this->oBeaut->getNextTokenContent(1);
if ($this->oBeaut->isNextTokenConstant(T_EXTENDS, 2)) {
$sClassName.= ' extends ' . $this->oBeaut->getNextTokenContent(3);
}
array_push($this->aClasses, $sClassName);
}
return PHP_Beautifier_Filter::BYPASS;
}
function t_doc_comment($sTag)
{
if (strpos($sTag, 'Class and Function List') !== FALSE) {
$this->iComment = $this->oBeaut->iCount;
}
return PHP_Beautifier_Filter::BYPASS;
}
function t_open_tag($sTag)
{
if (is_null($this->iOpenTag)) {
$this->iOpenTag = $this->oBeaut->iCount;
}
return PHP_Beautifier_Filter::BYPASS;
}
function postProcess()
{
$sNL = $this->oBeaut->sNewLine;
$aOut = array(
"/**",
"* Class and Function List:"
);
if ($this->getSetting('list_functions')) {
$aOut[] = "* Function list:";
foreach($this->aFunctions as $sFunction) {
$aOut[] = "* - " . $sFunction . "()";
}
}
if ($this->getSetting('list_classes')) {
$aOut[] = "* Classes list:";
foreach($this->aClasses as $sClass) {
$aOut[] = "* - " . $sClass;
}
}
$aOut[] = "*/";
if ($this->iComment) {
// Determine the previous Indent
$sComment = $this->oBeaut->getTokenAssocText($this->iComment);
if (preg_match("/" . addcslashes($sNL, "\r\n") . "([ \t]+)/ms", $sComment, $aMatch)) {
$sPrevio = $sNL . $aMatch[1];
} else {
$sPrevio = $sNL;
}
$sText = implode($sPrevio, $aOut) . $sNL;
$this->oBeaut->replaceTokenAssoc($this->iComment, $sText);
} else {
$sPrevio = $sNL /*.str_repeat($this->oBeaut->sIndentChar, $this->oBeaut->iIndentNumber)*/;
$sTag = trim($this->oBeaut->getTokenAssocText($this->iOpenTag)) . "\n";
$sText = $sPrevio . implode($sPrevio, $aOut);
$this->oBeaut->replaceTokenAssoc($this->iOpenTag, rtrim($sTag) . $sText . $sPrevio);
}
}
}
?>

View file

@ -0,0 +1,122 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* New Lines: Add extra new lines after o before specific contents
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://php.apsique.com/PHP_Beautifier
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @since File available since Release 0.1.9
* @version CVS: $Id:$
*/
/**
* Lowercase: lowercase all control structures.
* You should filter the code with this filter, and later parse
* again the file with the others filters
* Command line example:
*
* <code>php_beautifier --filters "Lowercase()"</code>
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
* @since Class available since Release 0.1.9
*/
class PHP_Beautifier_Filter_Lowercase extends PHP_Beautifier_Filter
{
protected $sDescription = 'Lowercase all control structures. Parse the output with another Filters';
private $aControlSeq = array(
T_IF,
T_ELSE,
T_ELSEIF,
T_WHILE,
T_DO,
T_FOR,
T_FOREACH,
T_SWITCH,
T_DECLARE,
T_CASE,
T_DEFAULT,
T_TRY,
T_CATCH,
T_ENDWHILE,
T_ENDFOREACH,
T_ENDFOR,
T_ENDDECLARE,
T_ENDSWITCH,
T_ENDIF,
T_INCLUDE,
T_INCLUDE_ONCE,
T_REQUIRE,
T_REQUIRE_ONCE,
T_FUNCTION,
T_PRINT,
T_RETURN,
T_ECHO,
T_NEW,
T_CLASS,
T_VAR,
T_GLOBAL,
T_THROW,
/* CONTROL */
T_IF,
T_DO,
T_WHILE,
T_SWITCH,
T_CASE,
/* ELSE */
T_ELSEIF,
T_ELSE,
T_BREAK,
/* ACCESS PHP 5 */
T_INTERFACE,
T_FINAL,
T_ABSTRACT,
T_PRIVATE,
T_PUBLIC,
T_PROTECTED,
T_CONST,
T_STATIC,
/* LOGICAL */
T_LOGICAL_OR,
T_LOGICAL_XOR,
T_LOGICAL_AND,
T_BOOLEAN_OR,
T_BOOLEAN_AND,
);
private $oLog;
public function __construct(PHP_Beautifier $oBeaut, $aSettings = array())
{
parent::__construct($oBeaut, $aSettings);
$this->oLog = PHP_Beautifier_Common::getLog();
}
public function __call($sMethod, $aArgs)
{
$iToken = $this->aToken[0];
$sContent = $this->aToken[1];
if (in_array($iToken, $this->aControlSeq)) {
$this->oLog->log("Lowercase:" . $sContent, PEAR_LOG_DEBUG);
$this->oBeaut->add(" " . strtolower($sContent) . " ");
} else {
return PHP_Beautifier_Filter::BYPASS;
}
}
}
?>

View file

@ -0,0 +1,94 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* New Lines: Add extra new lines after o before specific contents
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @since File available since Release 0.1.2
* @version CVS: $Id:$
*/
/**
* New Lines: Add new lines after o before specific contents
* The settings are 'before' and 'after'. As value, use a colon separated
* list of contents or tokens
*
* Command line example:
*
* <code>php_beautifier --filters "NewLines(before=if:switch:T_CLASS,after=T_COMMENT:function)"</code>
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
* @since Class available since Release 0.1.2
*/
class PHP_Beautifier_Filter_NewLines extends PHP_Beautifier_Filter
{
protected $aSettings = array(
'before' => false,
'after' => false
);
protected $sDescription = 'Add new lines after or before specific contents';
private $aBeforeToken = array();
private $aBeforeContent = array();
private $aAfterToken = array();
private $aAfterContent = array();
public function __construct(PHP_Beautifier $oBeaut, $aSettings = array())
{
parent::__construct($oBeaut, $aSettings);
$this->addSettingDefinition('before', 'text', 'List of contents to put new lines before, separated by colons');
$this->addSettingDefinition('after', 'text', 'List of contents to put new lines after, separated by colons');
if (!empty($this->aSettings['before'])) {
$aBefore = explode(':', str_replace(' ', '', $this->aSettings['before']));
foreach($aBefore as $sBefore) {
if (defined($sBefore)) {
$this->aBeforeToken[] = constant($sBefore);
} else {
$this->aBeforeContent[] = $sBefore;
}
}
}
if (!empty($this->aSettings['after'])) {
$aAfter = explode(':', str_replace(' ', '', $this->aSettings['after']));
foreach($aAfter as $sAfter) {
if (defined($sAfter)) {
$this->aAfterToken[] = constant($sAfter);
} else {
$this->aAfterContent[] = $sAfter;
}
}
}
$this->oBeaut->setNoDeletePreviousSpaceHack();
}
public function __call($sMethod, $aArgs)
{
$iToken = $this->aToken[0];
$sContent = $this->aToken[1];
if (in_array($sContent, $this->aBeforeContent) or in_array($iToken, $this->aBeforeToken)) {
$this->oBeaut->addNewLineIndent();
}
if (in_array($sContent, $this->aAfterContent) or in_array($iToken, $this->aAfterToken)) {
$this->oBeaut->setBeforeNewLine($this->oBeaut->sNewLine . '/**ndps**/');
}
return PHP_Beautifier_Filter::BYPASS;
}
}
?>

View file

@ -0,0 +1,200 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Filter the code to make it compatible with PEAR Coding Standards
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Require PEAR_Config
*/
require_once ('PEAR/Config.php');
/**
* Filter the code to make it compatible with PEAR Coding Standards
*
* The default filter, {@link PHP_Beautifier_Filter_Default} have most of the specs
* but adhere more to GNU C.
* So, this filter make the following modifications:
* - Add 2 newlines after Break in switch statements. Break indent is the same of previous line
* - Brace in function definition put on a new line, same indent of 'function' construct
* - Comments started with '#' are replaced with '//'
* - Open tags are replaced with '<?php'
* - T_OPEN_TAG_WITH_ECHO replaced with <?php echo
* - With setting 'add_header', the filter add one of the standard PEAR comment header
* (php, bsd, apache, lgpl, pear) or any file as licence header. Use:
* <code>
* $oBeaut->addFilter('Pear',array('add_header'=>'php'));
* </code>
* Two extra options allows to break the spec about newline before braces
* on function and classes. By default, they are set to true. Use
* <code>
* $oBeaut->addFilter('Pear',array('newline_class'=>false, 'newline_function'=>false));
* </code>
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @link http://pear.php.net/manual/en/standards.php
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
class PHP_Beautifier_Filter_Pear extends PHP_Beautifier_Filter
{
protected $aSettings = array('add_header' => false, 'newline_class' => true, 'newline_function' => true, 'switch_without_indent'=> true);
protected $sDescription = 'Filter the code to make it compatible with PEAR Coding Specs';
private $bOpenTag = false;
function t_open_tag_with_echo($sTag)
{
$this->oBeaut->add("<?php echo ");
}
function t_close_brace($sTag)
{
if($this->oBeaut->getControlSeq() == T_SWITCH and $this->getSetting('switch_without_indent')) {
$this->oBeaut->removeWhitespace();
$this->oBeaut->decIndent();
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add($sTag);
$this->oBeaut->addNewLineIndent();
} else {
return PHP_Beautifier_Filter::BYPASS;
}
}
function t_semi_colon($sTag)
{
// A break statement and the next statement are separated by an empty line
if ($this->oBeaut->isPreviousTokenConstant(T_BREAK)) {
$this->oBeaut->removeWhitespace();
$this->oBeaut->add($sTag); // add the semicolon
$this->oBeaut->addNewLine(); // empty line
$this->oBeaut->addNewLineIndent();
} elseif ($this->oBeaut->getControlParenthesis() == T_FOR) {
// The three terms in the head of a for loop are separated by the string "; "
$this->oBeaut->removeWhitespace();
$this->oBeaut->add($sTag . " "); // Bug 8327
} else {
return PHP_Beautifier_Filter::BYPASS;
}
}
function t_case($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->decIndent();
if ($this->oBeaut->isPreviousTokenConstant(T_BREAK, 2)) {
$this->oBeaut->addNewLine();
}
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add($sTag . ' ');
//$this->oBeaut->incIndent();
}
function t_default($sTag)
{
$this->t_case($sTag);
}
function t_break($sTag)
{
$this->oBeaut->add($sTag);
if ($this->oBeaut->isNextTokenConstant(T_LNUMBER)) {
$this->oBeaut->add(" ");
}
}
function t_open_brace($sTag)
{
if ($this->oBeaut->openBraceDontProcess()) {
$this->oBeaut->add($sTag);
} elseif ($this->oBeaut->getControlSeq() == T_SWITCH and $this->getSetting('switch_without_indent')) {
$this->oBeaut->add($sTag);
$this->oBeaut->incIndent();
} else {
$bypass = true;
if ($this->oBeaut->getControlSeq() == T_CLASS and $this->getSetting('newline_class')) {
$bypass = false;
}
if ($this->oBeaut->getControlSeq() == T_FUNCTION and $this->getSetting('newline_function')) {
$bypass = false;
}
if ($bypass) {
return PHP_Beautifier_Filter::BYPASS;
}
$this->oBeaut->removeWhitespace();
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add($sTag);
$this->oBeaut->incIndent();
$this->oBeaut->addNewLineIndent();
}
}
function t_comment($sTag)
{
if ($sTag{0} != '#') {
return PHP_Beautifier_Filter::BYPASS;
}
$oFilterDefault = new PHP_Beautifier_Filter_Default($this->oBeaut);
$sTag = '//' . substr($sTag, 1);
return $oFilterDefault->t_comment($sTag);
}
function t_open_tag($sTag)
{
// find PEAR header comment
$this->oBeaut->add("<?php");
$this->oBeaut->addNewLineIndent();
if (!$this->bOpenTag) {
$this->bOpenTag = true;
// store the comment and search for word 'license'
$sComment = '';
$x = 1;
while ($this->oBeaut->isNextTokenConstant(T_COMMENT, $x)) {
$sComment.= $this->oBeaut->getNextTokenContent($x);
$x++;
}
if (stripos($sComment, 'license') === FALSE) {
$this->addHeaderComment();
}
}
}
function preProcess()
{
$this->bOpenTag = false;
}
function addHeaderComment()
{
if (!($sLicense = $this->getSetting('add_header'))) {
return;
}
// if Header is a path, try to load the file
if (file_exists($sLicense)) {
$sDataPath = $sLicense;
} else {
$oConfig = PEAR_Config::singleton();
$sDataPath = PHP_Beautifier_Common::normalizeDir($oConfig->get('data_dir')) . 'PHP_Beautifier/licenses/' . $sLicense . '.txt';
}
if (file_exists($sDataPath)) {
$sLicenseText = file_get_contents($sDataPath);
} else {
throw (new Exception("Can't load license '" . $sLicense . "'"));
}
$this->oBeaut->removeWhitespace();
$this->oBeaut->addNewLine();
$this->oBeaut->add($sLicenseText);
$this->oBeaut->addNewLineIndent();
}
}
?>

View file

@ -0,0 +1,99 @@
<?php
/**
* Filter the code to make it compatible with phpBB Coding Standards
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2008 Jim Wigginton
* @link http://pear.php.net/package/PHP_Beautifier
* @license http://www.gnu.org/licenses/lgpl.html LGPL
* @version CVS: $Id:$
*/
/**
* Require PEAR_Config
*/
require_once ('PEAR/Config.php');
/**
* Filter the code to make it compatible with phpBB Coding Standards
*
* Among other differences from the PEAR Coding Standards, the phpBB coding standards use BSD style indenting.
*
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2008 Jim Wigginton
* @link http://pear.php.net/package/PHP_Beautifier
* @license http://www.gnu.org/licenses/lgpl.html LGPL
* @version Release: 0.0.1
*/
class PHP_Beautifier_Filter_phpBB extends PHP_Beautifier_Filter
{
protected $sDescription = 'Filter the code to make it compatible with phpBB Coding Standards';
private $iNestedIfs = 0;
public function __construct(PHP_Beautifier $oBeaut, $aSettings = array())
{
parent::__construct($oBeaut, $aSettings);
$oBeaut->setIndentChar("\t");
$oBeaut->setIndentNumber(1);
$oBeaut->setNewLine(PHP_EOL);
}
function t_open_brace($sTag)
{
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add($sTag);
$this->oBeaut->incIndent();
$this->oBeaut->addNewLineIndent();
}
function t_close_brace($sTag)
{
if ($this->oBeaut->getMode('string_index') or $this->oBeaut->getMode('double_quote')) {
$this->oBeaut->add($sTag);
} else {
$this->oBeaut->removeWhitespace();
$this->oBeaut->decIndent();
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add($sTag);
$this->oBeaut->addNewLineIndent();
}
}
function t_else($sTag)
{
$this->oBeaut->add($sTag);
if (!$this->oBeaut->isNextTokenContent('{')) {
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add('{');
$this->oBeaut->incIndent();
$this->oBeaut->addNewLineIndent();
$this->iNestedIfs++;
}
}
function t_semi_colon($sTag)
{
$this->oBeaut->removeWhitespace();
$this->oBeaut->add($sTag);
if ($this->oBeaut->getControlParenthesis() != T_FOR) {
if ($this->iNestedIfs > 0) {
$this->oBeaut->decIndent();
$this->oBeaut->addNewLineIndent();
$this->oBeaut->add('}');
$this->iNestedIfs--;
}
$this->oBeaut->addNewLineIndent();
}
}
function preProcess()
{
$this->iNestedIfs = 0;
}
}
?>

View file

@ -0,0 +1,53 @@
<?php
/**
* Interface for StreamWrappers
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage StreamWrapper
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Interface for StreamWrapper
* Read the documentation for streams wrappers on php manual.
*
* @category PHP
* @package PHP_Beautifier
* @subpackage StreamWrapper
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
interface PHP_Beautifier_StreamWrapper_Interface {
function stream_open($sPath, $sMode, $iOptions, &$sOpenedPath);
function stream_close();
function stream_read($iCount);
function stream_write($sData);
function stream_eof();
function stream_tell();
function stream_seek($iOffset, $iWhence);
function stream_flush();
function stream_stat();
function unlink($sPath);
function dir_opendir($sPath, $iOptions);
function dir_readdir();
function dir_rewinddir();
function dir_closedir();
}
require_once ('StreamWrapper/Tarz.php');
?>

View file

@ -0,0 +1,196 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Custom stream to handle Tar files (compressed and uncompressed)
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage StreamWrapper
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Require Archive_Tar
*/
require_once 'Archive/Tar.php';
/**
* Custom stream to handle Tar files (compressed and uncompressed)
* Use URL tarz://myfile.tgz#myfile.php
*
* @category PHP
* @package PHP_Beautifier
* @subpackage StreamWrapper
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
class PHP_Beautifier_StreamWrapper_Tarz implements PHP_Beautifier_StreamWrapper_Interface {
public $oTar;
public $sTar;
public $sPath;
public $sText;
public $iSeek = 0;
public $iSeekDir = 0;
public $aContents = array();
function stream_open($sPath, $sMode, $iOptions, &$sOpenedPath)
{
if ($this->getTar($sPath)) {
//ArrayNested->off()
$aContents = $this->oTar->listContent();
if (array_filter($aContents, array($this, 'tarFileExists'))) {
$this->sText = $this->oTar->extractInString($this->sPath);
return true;
}
}
//ArrayNested->on()
return false;
}
function getTar($sPath)
{
if (preg_match("/tarz:\/\/(.*?(\.tgz|\.tar\.gz|\.tar\.bz2|\.tar)+)(?:#\/?(.*))*/", $sPath, $aMatch)) {
$this->sTar = $aMatch[1];
if (strpos($aMatch[2], 'gz') !== FALSE) {
$sCompress = 'gz';
} elseif (strpos($aMatch[2], 'bz2') !== FALSE) {
$sCompress = 'bz2';
} elseif (strpos($aMatch[2], 'tar') !== FALSE) {
$sCompress = false;
} else {
return false;
}
if (isset($aMatch[3])) {
$this->sPath = $aMatch[3];
}
if (file_exists($this->sTar)) {
$this->oTar = new Archive_Tar($this->sTar, $sCompress);
return true;
}
} else {
return false;
}
}
function stream_close()
{
unset($this->oTar, $this->sText, $this->sPath, $this->iSeek);
}
function stream_read($iCount)
{
$sRet = substr($this->sText, $this->iSeek, $iCount);
$this->iSeek+= strlen($sRet);
return $sRet;
}
function stream_write($sData)
{
}
function stream_eof()
{
// BUG in 5.0.0RC1<PHP<5.0.0.0RC4
// DON'T USE EOF. Use ... another option :P
if (version_compare(PHP_VERSION, '5.0.0.RC.1', ">=") and version_compare(PHP_VERSION, '5.0.0.RC.4', "<")) {
return !($this->iSeek >= strlen($this->sText));
} else {
return $this->iSeek >= strlen($this->sText);
}
}
function stream_tell()
{
return $this->iSeek;
}
function stream_seek($iOffset, $iWhence)
{
switch ($iWhence) {
case SEEK_SET:
if ($iOffset<strlen($this->sText) and $iOffset >= 0) {
$this->iSeek = $iOffset;
return true;
} else {
return false;
}
break;
case SEEK_CUR:
if ($iOffset >= 0) {
$this->iSeek+= $iOffset;
return true;
} else {
return false;
}
break;
case SEEK_END:
if (strlen($this->sText) +$iOffset >= 0) {
$this->iSeek = strlen($this->sText) +$iOffset;
return true;
} else {
return false;
}
break;
default:
return false;
}
}
function stream_flush()
{
}
function stream_stat()
{
}
function unlink($sPath)
{
}
function dir_opendir($sPath, $iOptions)
{
if ($this->getTar($sPath)) {
array_walk($this->oTar->listContent() , array(
$this,
'getFileList'
));
return true;
} else {
return false;
}
}
function dir_readdir()
{
if ($this->iSeekDir >= count($this->aContents)) {
return false;
} else {
return $this->aContents[$this->iSeekDir++];
}
}
function dir_rewinddir()
{
$this->iSeekDir = 0;
}
function dir_closedir()
{
//unset($this->oTar, $this->aContents, $this->sPath, $this->iSeekDir);
//return true;
}
function getFileList($aInput)
{
$this->aContents[] = $aInput['filename'];
}
function tarFileExists($aInput)
{
return ($aInput['filename'] == $this->sPath and empty($aInput['typeflag']));
}
}
stream_wrapper_register("tarz", "PHP_Beautifier_StreamWrapper_Tarz");
?>

View file

@ -0,0 +1,42 @@
<?php
/**
* Interface for Tokenizer
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category PHP
* @package PHP_Beautifier
* @subpackage Tokenizer
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
*/
/**
* Interface for Tokenizer
*
* In the constructor, you should send the text of the file / code
* The function getTokens() should send the tokens for the code, like
* token_get_all()
*
* @category PHP
* @package PHP_Beautifier
* @author Claudio Bustos <cdx@users.sourceforge.com>
* @copyright 2004-2006 Claudio Bustos
* @link http://pear.php.net/package/PHP_Beautifier
* @link http://beautifyphp.sourceforge.net
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 0.1.14
*/
interface PHP_Beautifier_Tokeniker_Interface {
public function __construct($sText);
public function getTokens();
}
?>