Class PHP_Beautifier

Description

Implements interfaces:

PHP_Beautifier

Class to beautify php code How to use:

  • Create a instance of the object
  • Define the input and output files
  • Optional: Set one or more Filter. They are processed in LIFO order (last in, first out)
  • Process the file
  • Get it, save it or show it.
  1.  $oToken new PHP_Beautifier()// create a instance
  2.  $oToken->addFilter('ArraySimple');
  3.  $oToken->addFilter('ListClassFunction')// add one or more filters
  4.  $oToken->setInputFile(__FILE__)// nice... process the same file
  5.  $oToken->process()// required
  6.  $oToken->show();

Located in /Beautifier.php (line 82)


	
			
Variable Summary
Method Summary
 PHP_Beautifier __construct ()
 void add (string $token)
 bool addFilter (string $mFilter, [array $aSettings = array()])
 void addFilterDirectory (string $sDir)
 void addIndent ()
 void addNewLine ()
 void decIndent ()
 string get ()
 mixed getControlParenthesis ([int $iRet = 0])
 void getControlSeq ([int $iRet = 0])
 mixed getFilterDescription (string $sFilter)
 array getFilterList ()
 void getIndent ()
 void getIndentChar ()
 void getIndentNumber ()
 bool getMode (string $sKey)
 void getNewLine ()
 int getNextTokenConstant ([int $iPrev = 1])
 int getNextTokenContent ([int $iNext = 1])
 void getNextTokenNonCommentConstant ([ $iPrev = 1])
 int getPreviousTokenConstant ([int $iPrev = 1])
 string getPreviousTokenContent ([int $iPrev = 1])
 mixed getSetting (string $sKey)
 array &getToken (int $iIndex)
 mixed getTokenAssoc (int $iIndex)
 mixed getTokenAssocText (int $iIndex)
 mixed getTokenFunction (mixed $sTokenType)
 void getTokenName ( $iToken)
 void incIndent ([int $iIncr = false])
 bool isNextTokenConstant (mixed $mValue, [ $iPrev = 1])
 bool isNextTokenContent (mixed $mValue, [ $iPrev = 1])
 bool isPreviousTokenConstant (mixed $mValue, [ $iPrev = 1])
 bool isPreviousTokenContent (mixed $mValue, [ $iPrev = 1])
 void pop ([int $iReps = 1])
 bool process ()
 bool removeFilter (string $sFilter)
 bool replaceTokenAssoc (int $iIndex, string $sText)
 void save ([string $sFile = null])
 void setBeautify (bool $sFlag)
 void setBeforeNewLine ( $sText)
 void setFileType (string $sType)
 void setIndentChar (string $sChar)
 void setIndentNumber (int $iIndentNumber)
 void setInputFile (string $sFile)
 void setInputString (string $sText)
 void setMode (string $sKey)
 void setNewLine (string $sNewLine)
 void setNoDeletePreviousSpaceHack ([ $bFlag = true])
 void setOutputFile (string $sFile)
 void show ()
 void startLog ([string $sFile = 'php_beautifier.log'], [int $iLevel = PEAR_LOG_DEBUG])
 void unsetMode (string $sKey)
Variables
array $aAssocs = array() (line 186)

Association $aTokens=>$aOut

  • access: public
array $aCurrentToken = array() (line 191)

Current token. Could be changed by a filter (See Lowercase)

  • access: public
array $aModes = array() (line 113)

Contains the assigment of modes

array $aModesAvailable = array(
'ternary_operator',
'double_quote'
)
(line 118)

List of availables modes

  • access: public
array $aOut = array() (line 105)

Stores the output

  • access: public
array $aSettings = array() (line 126)

Settings for the class

  • access: public
array $aTokenFunctions = array() (line 95)

Tokens codes assigned to method on Filter

  • access: public
array $aTokenNames = array() (line 100)

Token Names

  • access: public
array $aTokens = array() (line 90)

Tokens created by the tokenizer

  • access: public
string $currentWhitespace = '' (line 181)

Save the last whitespace used. Use only for Filter! (i miss friends of C++ :( )

  • access: public
int $iArray = 0 (line 141)

Level of array nesting

  • access: public
int $iCount = 0 (line 131)

Index of current token

  • access: public
int $iIndentNumber = 4 (line 136)

Chars for indentation

  • access: public
int $iParenthesis = 0 (line 151)

Level of parenthesis nesting

  • access: public
int $iTernary = 0 (line 146)

Level of ternary operator nesting

  • access: public
int $iVerbose = false (line 156)

Level of verbosity (debug)

  • access: public
string $sIndentChar = ' ' (line 176)

Type of whitespace to use for indent

  • access: public
string $sInputFile = '' (line 161)

Name of input file

  • access: public
string $sNewLine = PHP_EOL (line 171)

Type of newline

  • access: public
string $sOutputFile = '' (line 166)

Name of output file

  • access: public
Methods
Constructor __construct (line 249)

Constructor.

Assing values to $aControlStructures,$aControlStructuresEnd, $aTokenFunctions

  • access: public
PHP_Beautifier __construct ()
add (line 1161)

Add a string to the output

  • access: public
void add (string $token)
  • string $token
addFilter (line 441)

Add a Filter to the Beautifier The first argument is the name of the file of the Filter.

  • return: true if Filter is loaded, false if the same filter was loaded previously
  • tutorial: Filter architecture
  • throws: Exception
  • access: public
bool addFilter (string $mFilter, [array $aSettings = array()])
  • string $mFilter: name of the Filter
  • array $aSettings: settings for the Filter
addFilterDirectory (line 410)

Add a filter directory

  • throws: Exception
  • access: public
void addFilterDirectory (string $sDir)
  • string $sDir: path to directory
addFilterObject (line 427)
  • access: public
void addFilterObject (PHP_Beautifier_Filter $oFilter)
addIndent (line 1183)

Add Indent to the output

void addIndent ()
addNewLine (line 1200)

Add a new line to the output

void addNewLine ()
addNewLineIndent (line 1215)

Add a new line and a indent to output

void addNewLineIndent ()
decIndent (line 1240)

Decrements the indent.

  • access: public
void decIndent ()
get (line 1087)

Returns the beautified code

string get ()

Implementation of:
PHP_Beautifier_Interface::get()
Get the output on a string
getControlParenthesis (line 1119)

Get the token constant for the current Parenthesis

  • return: token constant or false
  • access: public
mixed getControlParenthesis ([int $iRet = 0])
  • int $iRet: current token -'x'
getControlSeq (line 1109)

Get the token constant for the current control construct

  • access: public
void getControlSeq ([int $iRet = 0])
  • int $iRet: current token -'x' @ return mixed token constant or false
getFilterDescription (line 482)

Return the Filter Description

  • return: string or false
  • see: PHP_Beautifier_Filter::__toString();
  • access: public
mixed getFilterDescription (string $sFilter)
  • string $sFilter: name of the filter
getFilterDirectories (line 423)

Return an array with all the Filter Dirs

  • return: List of Filter Directories
  • access: public
array getFilterDirectories ()
getFilterList (line 525)

Get the names of the loaded filters

  • return: list of Filters
  • access: public
array getFilterList ()
getFilterListTotal (line 536)

Get the list of all available Filters in all the include Dirs

  • return: list of Filters
  • access: public
array getFilterListTotal ()
getIndent (line 567)
  • access: public
void getIndent ()
getIndentChar (line 559)
  • access: public
void getIndentChar ()
getIndentNumber (line 563)
  • access: public
void getIndentNumber ()
getMode (line 1149)

Get the state of a mode

  • access: public
bool getMode (string $sKey)
  • string $sKey: name of the mode
getNewLine (line 571)
  • access: public
void getNewLine ()
getNextTokenConstant (line 1381)

Get the 'x' significant (non whitespace) next token constant

  • access: public
int getNextTokenConstant ([int $iPrev = 1])
  • int $iPrev: current+x token
getNextTokenContent (line 1391)

Get the 'x' significant (non whitespace) next token text

  • access: public
int getNextTokenContent ([int $iNext = 1])
  • int $iNext: current+x token
getNextTokenNonCommentConstant (line 1367)
  • access: public
void getNextTokenNonCommentConstant ([ $iPrev = 1])
  • $iPrev
getPreviousTokenConstant (line 1352)

Get the 'x' significant (non whitespace) previous token constant

  • access: public
int getPreviousTokenConstant ([int $iPrev = 1])
  • int $iPrev: current-x token
getPreviousTokenContent (line 1362)

Get the 'x' significant (non whitespace) previous token text

  • access: public
string getPreviousTokenContent ([int $iPrev = 1])
  • int $iPrev: current-x token
getPreviousWhitespace (line 1404)

Return the whitespace previous to current token

Ex.: You have ' if($a)' if you call this funcion on 'if', you get ' '

  • return: previous whitespace
  • todo: implements a more economic way to handle this.
  • access: public
string getPreviousWhitespace ()
getSetting (line 1100)

Returns the value of a settings

  • return: Value of the settings or false
  • access: public
mixed getSetting (string $sKey)
  • string $sKey: Name of the setting
getToken (line 1468)

Get a token by number

  • access: public
array &getToken (int $iIndex)
  • int $iIndex: number of the token
getTokenAssoc (line 795)

Get the reference to $aOut, based on the number of the token

  • return: false array or false if token doesn't exists
  • access: public
mixed getTokenAssoc (int $iIndex)
  • int $iIndex: token number
getTokenAssocText (line 804)

Get the output for the specified token

  • return: string or false if token doesn't exists
  • access: public
mixed getTokenAssocText (int $iIndex)
  • int $iIndex: token number
getTokenFunction (line 833)

Return the function for a token constant or string.

  • return: name of function or false
  • access: public
mixed getTokenFunction (mixed $sTokenType)
  • mixed $sTokenType: token constant or string
getTokenName (line 387)
  • access: public
void getTokenName ( $iToken)
  • $iToken
incIndent (line 1229)

Increments the indent in X chars.

If param omitted, used iIndentNumber

  • access: public
void incIndent ([int $iIncr = false])
  • int $iIncr: increment indent in x chars
isNextTokenConstant (line 1322)

Return true if any of the constant defined in param 1 is the next 'x' content

  • access: public
bool isNextTokenConstant (mixed $mValue, [ $iPrev = 1])
  • mixed $mValue: int (constant) or array of constants
  • $iPrev
isNextTokenContent (line 1337)

Return true if any of the content defined is param 1 is the next 'x' content

  • access: public
bool isNextTokenContent (mixed $mValue, [ $iPrev = 1])
  • mixed $mValue: string (content) or array of contents
  • $iPrev
isPreviousTokenConstant (line 1292)

Return true if any of the constant defined is param 1 is the previous 'x' constant

  • access: public
bool isPreviousTokenConstant (mixed $mValue, [ $iPrev = 1])
  • mixed $mValue: int (constant) or array of constants
  • $iPrev
isPreviousTokenContent (line 1307)

Return true if any of the content defined is param 1 is the previous 'x' content

  • access: public
bool isPreviousTokenContent (mixed $mValue, [ $iPrev = 1])
  • mixed $mValue: string (content) or array of contents
  • $iPrev
openBraceDontProcess (line 1476)
  • access: public
void openBraceDontProcess ()
pop (line 1170)

Delete the last added output(s)

  • deprecated:
  • access: public
void pop ([int $iReps = 1])
  • int $iReps: number of outputs to drop
process (line 703)

Process the string or file to beautify

  • return: true on success
  • throws: Exception
  • access: public
bool process ()

Implementation of:
PHP_Beautifier_Interface::process()
Process the file(s) or string
removeFilter (line 465)

Removes a Filter

  • return: true if Filter is removed, false otherwise
  • access: public
bool removeFilter (string $sFilter)
  • string $sFilter: name of the filter
removeWhitespace (line 1437)

Remove all whitespace from the previous tag

  • return: false if previous token was short comment or heredoc (don't remove ws) true anything else.
  • access: public
bool removeWhitespace ()
replaceTokenAssoc (line 817)

Replace the output for specified token

  • access: public
bool replaceTokenAssoc (int $iIndex, string $sText)
  • int $iIndex: token number
  • string $sText: replace text
save (line 640)

Save the beautified code to output file

  • see: setOutputFile();
  • throws: Exception
  • access: public
void save ([string $sFile = null])
  • string $sFile: path to file. If null, $sOutputFile if exists, throw exception otherwise

Implementation of:
PHP_Beautifier_Interface::save()
Save the output to a file
setBeautify (line 1058)

Set the Beautifier on or off

  • access: public
void setBeautify (bool $sFlag)
  • bool $sFlag
setBeforeNewLine (line 1192)

Set a string to put before a new line

You could use this to put a standard comment after some sentences or to add extra newlines

  • access: public
void setBeforeNewLine ( $sText)
  • $sText
setFileType (line 1050)

Set the filetype

  • access: public
void setFileType (string $sType)
  • string $sType
setIndentChar (line 579)

Character used for indentation

  • access: public
void setIndentChar (string $sChar)
  • string $sChar: usually ' ' or "\t"
setIndentNumber (line 587)

Number of characters for indentation

  • access: public
void setIndentNumber (int $iIndentNumber)
  • int $iIndentNumber: ussualy 4 for space or 1 for tabs
setInputFile (line 604)

Set the file for beautify

  • throws: Exception
  • access: public
void setInputFile (string $sFile)
  • string $sFile: path to file
setInputString (line 666)

Set a string for beautify

  • access: public
void setInputString (string $sText)
  • string $sText: Must be preceded by open tag
setMode (line 1132)

Set a mode to true

  • access: public
void setMode (string $sKey)
  • string $sKey: name of the mode
setNewLine (line 595)

Character used as a new line

  • access: public
void setNewLine (string $sNewLine)
  • string $sNewLine: ussualy "\n", "\r\n" or "\r"
setNoDeletePreviousSpaceHack (line 1078)

Activate or deactivate this ominous hack

If you need to maintain some special whitespace you can activate this hack and use (delete the space between * and /)

  1. /**ndps** /
in get(), this text will be erased.

void setNoDeletePreviousSpaceHack ([ $bFlag = true])
  • $bFlag
setOutputFile (line 630)

Set the output file for beautify

  • access: public
void setOutputFile (string $sFile)
  • string $sFile: path to file
show (line 1065)

Show the beautified code

  • access: public
void show ()

Implementation of:
PHP_Beautifier_Interface::show()
Show on screen the output
startLog (line 399)

Start the log for debug

  • access: public
void startLog ([string $sFile = 'php_beautifier.log'], [int $iLevel = PEAR_LOG_DEBUG])
  • string $sFile: filename
  • int $iLevel: debug level. See Log
unsetMode (line 1140)

Set a mode to false

  • access: public
void unsetMode (string $sKey)
  • string $sKey: name of the mode

Documentation generated on Mon, 31 May 2010 16:16:04 -0400 by phpDocumentor 1.4.3