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 //usr/share/php/PHP/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 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
string $aAssocs = array() (line 186)

Association $aTokens=>$aOut

  • 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 241)

Constructor.

Assing values to $aControlStructures,$aControlStructuresEnd, $aTokenFunctions

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

Add a string to the output

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

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
  • access: public
  • throws: Exception
  • tutorial: Filter architecture
bool addFilter (string $mFilter, [array $aSettings = array()])
  • string $mFilter: name of the Filter
  • array $aSettings: settings for the Filter
addFilterDirectory (line 398)

Add a filter directory

  • access: public
  • throws: Exception
void addFilterDirectory (string $sDir)
  • string $sDir: path to directory
addIndent (line 1134)

Add Indent to the output

void addIndent ()
addNewLine (line 1151)

Add a new line to the output

void addNewLine ()
addNewLineIndent (line 1166)

Add a new line and a indent to output

void addNewLineIndent ()
decIndent (line 1191)

Decrements the indent.

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

Returns the beautified code

string get ()

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

Get the token constant for the current Parenthesis

  • return: token constant or false
  • access: public
mixed getControlParenthesis (int $iRet)
  • int $iRet: current token -'x'
getControlSeq (line 1060)

Get the token constant for the current control construct

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

Return the Filter Description

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

Return an array with all the Filter Dirs

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

Get the names of the loaded filters

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

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

  • return: list of Filters
  • access: public
array getFilterListTotal ()
getIndentChar (line 546)
  • access: public
void getIndentChar ()
getIndentNumber (line 550)
  • access: public
void getIndentNumber ()
getMode (line 1100)

Get the state of a mode

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

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

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

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

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

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

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

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

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

Return the whitespace previous to current token

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

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

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 1417)

Get a token by number

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

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 786)

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 815)

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 375)
  • access: public
void getTokenName ( $iToken)
  • $iToken
incIndent (line 1180)

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 1273)

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 1288)

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 1243)

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 1258)

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 1425)
  • access: public
void openBraceDontProcess ()
pop (line 1121)

Delete the last added output(s)

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

Process the string or file to beautify

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

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

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 1386)

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 799)

Replace the output for specified token

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

Save the beautified code to output file

  • access: public
  • throws: Exception
  • see: setOutputFile();
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 1009)

Set the Beautifier on or off

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

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 1001)

Set the filetype

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

Character used for indentation

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

Number of characters for indentation

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

Set the file for beautify

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

Set a string for beautify

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

Set a mode to true

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

Character used as a new line

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

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 /)

    in get(), this text will be erased.

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

    Set the output file for beautify

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

    Show the beautified code

    • access: public
    void show ()

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

    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 1091)

    Set a mode to false

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

    Documentation generated on Sun, 22 Jun 2008 18:59:38 -0400 by phpDocumentor 1.3.1