PHP_Beautifier
[ class tree: PHP_Beautifier ] [ index: PHP_Beautifier ] [ all elements ]

Class: PHP_Beautifier

Source Location: /PHP_Beautifier-0.1.2/Beautifier.php

Class Overview


PHP_Beautifier


Author(s):

Version:

  • Release: @package_version@

Copyright:

  • 2004-2005 Claudio Bustos

Methods


Inherited Variables

Inherited Methods


Class Details

[line 81]
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();



[ Top ]


Method Detail

add   [line 1079]

void add( string $token)

Add a string to the output

Parameters:

string   $token     

[ Top ]

addFilter   [line 386]

bool addFilter( string $mFilter, [array $aSettings = array()])

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
  • Throws: Exception
  • Tutorial: Filter2.pkg

Parameters:

string   $mFilter     name of the Filter
array   $aSettings     settings for the Filter

[ Top ]

addFilterDirectory   [line 355]

void addFilterDirectory( string $sDir)

Add a filter directory
  • Throws: Exception

Parameters:

string   $sDir     path to directory

[ Top ]

addFilterFile   [line 447]

bool addFilterFile( string $sFilter)

Add a new filter to the processor.

The system will process the filter in LIFO order


Parameters:

string   $sFilter     name of filter

[ Top ]

addFilterObject   [line 372]

void addFilterObject( mixed PHP_Beautifier_Filter$oFilter)


[ Top ]

addIndent   [line 1101]

void addIndent( )

Add Indent to the output
  • See: $iIndent
  • See: $iIndentNumber
  • See: $sIndentChar

[ Top ]

addNewLine   [line 1118]

void addNewLine( )

Add a new line to the output
  • See: $sNewLine

[ Top ]

addNewLineIndent   [line 1133]

void addNewLineIndent( )

Add a new line and a indent to output
  • See: $sNewLine
  • See: $iIndent
  • See: $iIndentNumber
  • See: $sIndentChar

[ Top ]

controlToken   [line 795]

void controlToken( array $aCurrentToken)

Assign value for some variables with the information of the token

Parameters:

array   $aCurrentToken     current token

[ Top ]

controlTokenPost   [line 878]

void controlTokenPost( array $aCurrentToken)

Assign value for some variables with the information of the token, after processing

Parameters:

array   $aCurrentToken     current token

[ Top ]

decIndent   [line 1158]

void decIndent( )

Decrements the indent.

[ Top ]

get   [line 1005]

string get( )

Returns the beautified code

[ Top ]

getControlParenthesis   [line 1037]

mixed getControlParenthesis( [int $iRet = 0])

Get the token constant for the current Parenthesis
  • Return: token constant or false

Parameters:

int   $iRet     current token -'x'

[ Top ]

getControlSeq   [line 1027]

void getControlSeq( [int $iRet = 0])

Get the token constant for the current control construct

Parameters:

int   $iRet     current token -'x' @ return mixed token constant or false

[ Top ]

getFilterDescription   [line 427]

mixed getFilterDescription( string $sFilter)

Return the Filter Description
  • Return: string or false
  • See: PHP_Beautifier_Filter::__toString();

Parameters:

string   $sFilter     name of the filter

[ Top ]

getFilterDirectories   [line 368]

array getFilterDirectories( )

Return an array with all the Filter Dirs
  • Return: List of Filter Directories

[ Top ]

getFilterList   [line 470]

array getFilterList( )

Get the names of the loaded filters
  • Return: list of Filters

[ Top ]

getFilterListTotal   [line 481]

array getFilterListTotal( )

Get the list of all available Filters in all the include Dirs
  • Return: list of Filters

[ Top ]

getFilterList_FilterName   [line 498]

void getFilterList_FilterName( mixed &$sFile)

Receive a path to a filter and replace it with the name of filter

[ Top ]

getIndentChar   [line 503]

void getIndentChar( )


[ Top ]

getIndentNumber   [line 507]

void getIndentNumber( )


[ Top ]

getMode   [line 1067]

bool getMode( string $sKey)

Get the state of a mode

Parameters:

string   $sKey     name of the mode

[ Top ]

getNewLine   [line 511]

void getNewLine( )


[ Top ]

getNextToken   [line 1193]

array getNextToken( [int $iNext = 1])

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

Parameters:

int   $iNext     current+x token

[ Top ]

getNextTokenConstant   [line 1290]

int getNextTokenConstant( [int $iPrev = 1])

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

Parameters:

int   $iPrev     current+x token

[ Top ]

getNextTokenContent   [line 1300]

int getNextTokenContent( [int $iNext = 1])

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

Parameters:

int   $iNext     current+x token

[ Top ]

getPreviousToken   [line 1176]

mixed getPreviousToken( [int $iPrev = 1])

Get the 'x' significant (non whitespace)previous token
  • Return: array or false

Parameters:

int   $iPrev     current-x token

[ Top ]

getPreviousTokenConstant   [line 1270]

int getPreviousTokenConstant( [int $iPrev = 1])

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

Parameters:

int   $iPrev     current-x token

[ Top ]

getPreviousTokenContent   [line 1280]

string getPreviousTokenContent( [int $iPrev = 1])

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

Parameters:

int   $iPrev     current-x token

[ Top ]

getPreviousWhitespace   [line 1313]

string getPreviousWhitespace( )

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.

[ Top ]

getSetting   [line 1018]

mixed getSetting( string $sKey)

Returns the value of a settings
  • Return: Value of the settings or false

Parameters:

string   $sKey     Name of the setting

[ Top ]

getToken   [line 1374]

array &getToken( int $iIndex)

Get a token by number

Parameters:

int   $iIndex     number of the token

[ Top ]

getTokenAssoc   [line 726]

mixed getTokenAssoc( int $iIndex)

Get the reference to $aOut, based on the number of the token
  • Return: false array or false if token doesn't exists

Parameters:

int   $iIndex     token number

[ Top ]

getTokenAssocText   [line 735]

mixed getTokenAssocText( int $iIndex)

Get the output for the specified token
  • Return: string or false if token doesn't exists

Parameters:

int   $iIndex     token number

[ Top ]

getTokenFunction   [line 764]

mixed getTokenFunction( mixed $sTokenType)

Return the function for a token constant or string.
  • Return: name of function or false

Parameters:

mixed   $sTokenType     token constant or string

[ Top ]

incIndent   [line 1147]

void incIndent( [int $iIncr = false])

Increments the indent in X chars.

If param omitted, used iIndentNumber


Parameters:

int   $iIncr     increment indent in x chars

[ Top ]

isNextTokenConstant   [line 1240]

bool isNextTokenConstant( mixed $mValue, [mixed $iPrev = 1])

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

Parameters:

mixed   $mValue     int (constant) or array of constants

[ Top ]

isNextTokenContent   [line 1255]

bool isNextTokenContent( mixed $mValue, [mixed $iPrev = 1])

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

Parameters:

mixed   $mValue     string (content) or array of contents

[ Top ]

isPreviousTokenConstant   [line 1210]

bool isPreviousTokenConstant( mixed $mValue, [mixed $iPrev = 1])

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

Parameters:

mixed   $mValue     int (constant) or array of constants

[ Top ]

isPreviousTokenContent   [line 1225]

bool isPreviousTokenContent( mixed $mValue, [mixed $iPrev = 1])

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

Parameters:

mixed   $mValue     string (content) or array of contents

[ Top ]

pop   [line 1088]

void pop( [int $iReps = 1])

Delete the last added output(s)
  • Deprecated:

Parameters:

int   $iReps     number of outputs to drop

[ Top ]

popControlParenthesis   [line 956]

int popControlParenthesis( )

Pop the last Control instruction for parenthesis from the stack
  • Return: constant

[ Top ]

popControlSeq   [line 933]

int popControlSeq( )

Pop a control construct from the stack
  • Return: token constant

[ Top ]

process   [line 639]

bool process( )

Process the string or file to beautify
  • Return: true on success
  • Throws: Exception

[ Top ]

processCallback   [line 774]

bool processCallback( array $aMatch)

Process a callback from the code to beautify

Parameters:

array   $aMatch     third parameter from preg_match

[ Top ]

pushControlParenthesis   [line 944]

void pushControlParenthesis( )

Push a new Control Instruction on the stack

[ Top ]

pushControlSeq   [line 922]

void pushControlSeq( array $aToken)

Push a control construct to the stack

Parameters:

array   $aToken     current token

[ Top ]

removeFilter   [line 410]

bool removeFilter( string $sFilter)

Removes a Filter
  • Return: true if Filter is removed, false otherwise

Parameters:

string   $sFilter     name of the filter

[ Top ]

removeWhitespace   [line 1344]

bool removeWhitespace( )

Remove all whitespace from the previous tag
  • Return: false if previous token was short comment or heredoc (don't remove ws) true anything else.

[ Top ]

replaceTokenAssoc   [line 748]

bool replaceTokenAssoc( int $iIndex, string $sText)

Replace the output for specified token

Parameters:

int   $iIndex     token number
string   $sText     replace text

[ Top ]

resetProperties   [line 611]

void resetProperties( )

Reset all properties

[ Top ]

save   [line 579]

void save( [string $sFile = null])

Save the beautified code to output file
  • Throws: Exception
  • See: setOutputFile();

Parameters:

string   $sFile     path to file. If null, $sOutputFile if exists, throw exception otherwise

[ Top ]

setBeautify   [line 976]

void setBeautify( bool $sFlag)

Set the Beautifier on or off

Parameters:

bool   $sFlag     

[ Top ]

setBeforeNewLine   [line 1110]

void setBeforeNewLine( mixed $sText)

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


[ Top ]

setFileType   [line 968]

void setFileType( string $sType)

Set the filetype

Parameters:

string   $sType     

[ Top ]

setIndentChar   [line 519]

void setIndentChar( string $sChar)

Character used for indentation

Parameters:

string   $sChar     usually ' ' or "\t"

[ Top ]

setIndentNumber   [line 527]

void setIndentNumber( int $iIndentNumber)

Number of characters for indentation

Parameters:

int   $iIndentNumber     ussualy 4 for space or 1 for tabs

[ Top ]

setInputFile   [line 544]

void setInputFile( string $sFile)

Set the file for beautify
  • Throws: Exception

Parameters:

string   $sFile     path to file

[ Top ]

setInputString   [line 604]

void setInputString( string $sText)

Set a string for beautify

Parameters:

string   $sText     Must be preceded by open tag

[ Top ]

setMode   [line 1050]

void setMode( string $sKey)

Set a mode to true

Parameters:

string   $sKey     name of the mode

[ Top ]

setNewLine   [line 535]

void setNewLine( string $sNewLine)

Character used as a new line

Parameters:

string   $sNewLine     ussualy "\n", "\r\n" or "\r"

[ Top ]

setNoDeletePreviousSpaceHack   [line 996]

void setNoDeletePreviousSpaceHack( [mixed $bFlag = true])

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.


[ Top ]

setOutputFile   [line 569]

void setOutputFile( string $sFile)

Set the output file for beautify

Parameters:

string   $sFile     path to file

[ Top ]

show   [line 983]

void show( )

Show the beautified code

[ Top ]

startLog   [line 344]

void startLog( [string $sFile = 'php_beautifier.log'], [int $iLevel = PEAR_LOG_DEBUG])

Start the log for debug

Parameters:

string   $sFile     filename
int   $iLevel     debug level. See Log

[ Top ]

unsetMode   [line 1058]

void unsetMode( string $sKey)

Set a mode to false

Parameters:

string   $sKey     name of the mode

[ Top ]


Documentation generated on Fri, 4 Feb 2005 01:30:12 -0500 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.