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

Class: PHP_Beautifier

Source Location: /PHP_Beautifier-0.1.15/Beautifier.php

Class Overview


PHP_Beautifier


Author(s):

Version:

  • Release: 0.1.15

Copyright:

  • 2004-2010 Claudio Bustos

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 82]
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 ]


Class Variables

$aAssocs = array()

[line 186]

Association $aTokens=>$aOut
  • Access: public

Type:   array


[ Top ]

$aCurrentToken = array()

[line 191]

Current token. Could be changed by a filter (See Lowercase)
  • Access: public

Type:   array


[ Top ]

$aModes = array()

[line 113]

Contains the assigment of modes

Type:   array


[ Top ]

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

[line 118]

List of availables modes
  • Access: public

Type:   array


[ Top ]

$aOut = array()

[line 105]

Stores the output
  • Access: public

Type:   array


[ Top ]

$aSettings = array()

[line 126]

Settings for the class
  • Access: public

Type:   array


[ Top ]

$aTokenFunctions = array()

[line 95]

Tokens codes assigned to method on Filter
  • Access: public

Type:   array


[ Top ]

$aTokenNames = array()

[line 100]

Token Names
  • Access: public

Type:   array


[ Top ]

$aTokens = array()

[line 90]

Tokens created by the tokenizer
  • Access: public

Type:   array


[ Top ]

$currentWhitespace =  ''

[line 181]

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

Type:   string


[ Top ]

$iArray =  0

[line 141]

Level of array nesting
  • Access: public

Type:   int


[ Top ]

$iCount =  0

[line 131]

Index of current token
  • Access: public

Type:   int


[ Top ]

$iIndentNumber =  4

[line 136]

Chars for indentation
  • Access: public

Type:   int


[ Top ]

$iParenthesis =  0

[line 151]

Level of parenthesis nesting
  • Access: public

Type:   int


[ Top ]

$iTernary =  0

[line 146]

Level of ternary operator nesting
  • Access: public

Type:   int


[ Top ]

$iVerbose =  false

[line 156]

Level of verbosity (debug)
  • Access: public

Type:   int


[ Top ]

$sIndentChar =  ' '

[line 176]

Type of whitespace to use for indent
  • Access: public

Type:   string


[ Top ]

$sInputFile =  ''

[line 161]

Name of input file
  • Access: public

Type:   string


[ Top ]

$sNewLine =  PHP_EOL

[line 171]

Type of newline
  • Access: public

Type:   string


[ Top ]

$sOutputFile =  ''

[line 166]

Name of output file
  • Access: public

Type:   string


[ Top ]



Method Detail

__construct (Constructor)   [line 249]

PHP_Beautifier __construct( )

Constructor.

Assing values to $aControlStructures,$aControlStructuresEnd, $aTokenFunctions

  • Access: public

[ Top ]

add   [line 1161]

void add( string $token)

Add a string to the output
  • Access: public

Parameters:

string   $token   — 

[ Top ]

addFilter   [line 441]

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

Parameters:

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

[ Top ]

addFilterDirectory   [line 410]

void addFilterDirectory( string $sDir)

Add a filter directory
  • Throws: Exception
  • Access: public

Parameters:

string   $sDir   —  path to directory

[ Top ]

addFilterObject   [line 427]

void addFilterObject( PHP_Beautifier_Filter $oFilter)

  • Access: public

Parameters:

PHP_Beautifier_Filter   $oFilter   — 

[ Top ]

addIndent   [line 1183]

void addIndent( )

Add Indent to the output

[ Top ]

addNewLine   [line 1200]

void addNewLine( )

Add a new line to the output

[ Top ]

addNewLineIndent   [line 1215]

void addNewLineIndent( )

Add a new line and a indent to output

[ Top ]

decIndent   [line 1240]

void decIndent( )

Decrements the indent.
  • Access: public

[ Top ]

get   [line 1087]

string get( )

Returns the beautified code

[ Top ]

getControlParenthesis   [line 1119]

mixed getControlParenthesis( [int $iRet = 0])

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

Parameters:

int   $iRet   —  current token -'x'

[ Top ]

getControlSeq   [line 1109]

void getControlSeq( [int $iRet = 0])

Get the token constant for the current control construct
  • Access: public

Parameters:

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

[ Top ]

getFilterDescription   [line 482]

mixed getFilterDescription( string $sFilter)

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

Parameters:

string   $sFilter   —  name of the filter

[ Top ]

getFilterDirectories   [line 423]

array getFilterDirectories( )

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

[ Top ]

getFilterList   [line 525]

array getFilterList( )

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

[ Top ]

getFilterListTotal   [line 536]

array getFilterListTotal( )

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

[ Top ]

getIndent   [line 567]

void getIndent( )

  • Access: public

[ Top ]

getIndentChar   [line 559]

void getIndentChar( )

  • Access: public

[ Top ]

getIndentNumber   [line 563]

void getIndentNumber( )

  • Access: public

[ Top ]

getMode   [line 1149]

bool getMode( string $sKey)

Get the state of a mode
  • Access: public

Parameters:

string   $sKey   —  name of the mode

[ Top ]

getNewLine   [line 571]

void getNewLine( )

  • Access: public

[ Top ]

getNextTokenConstant   [line 1381]

int getNextTokenConstant( [int $iPrev = 1])

Get the 'x' significant (non whitespace) next token constant
  • Access: public

Parameters:

int   $iPrev   —  current+x token

[ Top ]

getNextTokenContent   [line 1391]

int getNextTokenContent( [int $iNext = 1])

Get the 'x' significant (non whitespace) next token text
  • Access: public

Parameters:

int   $iNext   —  current+x token

[ Top ]

getNextTokenNonCommentConstant   [line 1367]

void getNextTokenNonCommentConstant( [ $iPrev = 1])

  • Access: public

Parameters:

   $iPrev   — 

[ Top ]

getPreviousTokenConstant   [line 1352]

int getPreviousTokenConstant( [int $iPrev = 1])

Get the 'x' significant (non whitespace) previous token constant
  • Access: public

Parameters:

int   $iPrev   —  current-x token

[ Top ]

getPreviousTokenContent   [line 1362]

string getPreviousTokenContent( [int $iPrev = 1])

Get the 'x' significant (non whitespace) previous token text
  • Access: public

Parameters:

int   $iPrev   —  current-x token

[ Top ]

getPreviousWhitespace   [line 1404]

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.
  • Access: public

[ Top ]

getSetting   [line 1100]

mixed getSetting( string $sKey)

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

Parameters:

string   $sKey   —  Name of the setting

[ Top ]

getToken   [line 1468]

array &getToken( int $iIndex)

Get a token by number
  • Access: public

Parameters:

int   $iIndex   —  number of the token

[ Top ]

getTokenAssoc   [line 795]

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
  • Access: public

Parameters:

int   $iIndex   —  token number

[ Top ]

getTokenAssocText   [line 804]

mixed getTokenAssocText( int $iIndex)

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

Parameters:

int   $iIndex   —  token number

[ Top ]

getTokenFunction   [line 833]

mixed getTokenFunction( mixed $sTokenType)

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

Parameters:

mixed   $sTokenType   —  token constant or string

[ Top ]

getTokenName   [line 387]

void getTokenName( $iToken)

  • Access: public

Parameters:

   $iToken   — 

[ Top ]

incIndent   [line 1229]

void incIndent( [int $iIncr = false])

Increments the indent in X chars.

If param omitted, used iIndentNumber

  • Access: public

Parameters:

int   $iIncr   —  increment indent in x chars

[ Top ]

isNextTokenConstant   [line 1322]

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

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

Parameters:

mixed   $mValue   —  int (constant) or array of constants
   $iPrev   — 

[ Top ]

isNextTokenContent   [line 1337]

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

Return true if any of the content defined is param 1 is the next 'x' content
  • Access: public

Parameters:

mixed   $mValue   —  string (content) or array of contents
   $iPrev   — 

[ Top ]

isPreviousTokenConstant   [line 1292]

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

Return true if any of the constant defined is param 1 is the previous 'x' constant
  • Access: public

Parameters:

mixed   $mValue   —  int (constant) or array of constants
   $iPrev   — 

[ Top ]

isPreviousTokenContent   [line 1307]

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

Return true if any of the content defined is param 1 is the previous 'x' content
  • Access: public

Parameters:

mixed   $mValue   —  string (content) or array of contents
   $iPrev   — 

[ Top ]

openBraceDontProcess   [line 1476]

void openBraceDontProcess( )

  • Access: public

[ Top ]

pop   [line 1170]

void pop( [int $iReps = 1])

Delete the last added output(s)
  • Deprecated:
  • Access: public

Parameters:

int   $iReps   —  number of outputs to drop

[ Top ]

process   [line 703]

bool process( )

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

[ Top ]

removeFilter   [line 465]

bool removeFilter( string $sFilter)

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

Parameters:

string   $sFilter   —  name of the filter

[ Top ]

removeWhitespace   [line 1437]

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.
  • Access: public

[ Top ]

replaceTokenAssoc   [line 817]

bool replaceTokenAssoc( int $iIndex, string $sText)

Replace the output for specified token
  • Access: public

Parameters:

int   $iIndex   —  token number
string   $sText   —  replace text

[ Top ]

save   [line 640]

void save( [string $sFile = null])

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

Parameters:

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

[ Top ]

setBeautify   [line 1058]

void setBeautify( bool $sFlag)

Set the Beautifier on or off
  • Access: public

Parameters:

bool   $sFlag   — 

[ Top ]

setBeforeNewLine   [line 1192]

void setBeforeNewLine( $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

  • Access: public

Parameters:

   $sText   — 

[ Top ]

setFileType   [line 1050]

void setFileType( string $sType)

Set the filetype
  • Access: public

Parameters:

string   $sType   — 

[ Top ]

setIndentChar   [line 579]

void setIndentChar( string $sChar)

Character used for indentation
  • Access: public

Parameters:

string   $sChar   —  usually ' ' or "\t"

[ Top ]

setIndentNumber   [line 587]

void setIndentNumber( int $iIndentNumber)

Number of characters for indentation
  • Access: public

Parameters:

int   $iIndentNumber   —  ussualy 4 for space or 1 for tabs

[ Top ]

setInputFile   [line 604]

void setInputFile( string $sFile)

Set the file for beautify
  • Throws: Exception
  • Access: public

Parameters:

string   $sFile   —  path to file

[ Top ]

setInputString   [line 666]

void setInputString( string $sText)

Set a string for beautify
  • Access: public

Parameters:

string   $sText   —  Must be preceded by open tag

[ Top ]

setMode   [line 1132]

void setMode( string $sKey)

Set a mode to true
  • Access: public

Parameters:

string   $sKey   —  name of the mode

[ Top ]

setNewLine   [line 595]

void setNewLine( string $sNewLine)

Character used as a new line
  • Access: public

Parameters:

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

[ Top ]

setNoDeletePreviousSpaceHack   [line 1078]

void setNoDeletePreviousSpaceHack( [ $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 /)

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


Parameters:

   $bFlag   — 

[ Top ]

setOutputFile   [line 630]

void setOutputFile( string $sFile)

Set the output file for beautify
  • Access: public

Parameters:

string   $sFile   —  path to file

[ Top ]

show   [line 1065]

void show( )

Show the beautified code
  • Access: public

[ Top ]

startLog   [line 399]

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

Start the log for debug
  • Access: public

Parameters:

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

[ Top ]

unsetMode   [line 1140]

void unsetMode( string $sKey)

Set a mode to false
  • Access: public

Parameters:

string   $sKey   —  name of the mode

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:37:31 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.