|
|
|
|
Introduction to PHP_Beautifier
|
Introduction to PHP_Beautifier
|
How to use PHP_Beautifier
|
Callbacks
Callbacks
Describe how the file to beautify can alter the beautify process
Claudio
Bustos
cdx@users.sourceforge.com
Jens
Bierkandt
scortch@users.sourceforge.com
Table of Contents
Introduction
One of the nicest features of Php_Beautifier is the use of callbacks inside the code to beautify. This callbacks call a method on the base class or in a filter.
Usage
To execute a callback, you should insert a short comment, with this structure
Php_Beautifier or the name of the filter (case insensitive)
->
Method name and params inside parenthesis. Php_Beautifier evaluates all after '->', so the code must be valid PHP code
// php_beautifier->setBeautify(true);
echo "This line will be beautified";
// ArrayNested->on()
echo "Array Nested!";
Common methods
Base class
You can use only the public method that starts with 'add' and 'set', except PHP_Beautifier::setInputFile() and PHP_Beautifier::setOutputFile()
Filters
Demostration
With this code to beautify
<?php
$a=array('1',array('1.1','1.2','1.3'));
// php_beautifier->addFilter('ArrayNested');
$a=array('1',array('1.1','1.2','1.3'));
// php_beautifier->setIndentNumber(2);
echo 'Indent: 2 spaces';
// php_beautifier->setIndentNumber(10);
echo 'Indent: 10 spaces';
// php_beautifier->setBeautify(false);
echo "The following lines won't be beautified";
$a=array('1',array('1.1','1.2','1.3'));
if ($b) {$c;} else {$d;}
// php_beautifier->setBeautify(true);
// php_beautifier->setIndentNumber(4);
echo 'Beautify, again';
// now, turn out the Filter
// ArrayNested->off()
$a=array('1',array('1.1','1.2','1.3'));
// ArrayNested->on()
$a=array('1',array('1.1','1.2','1.3'));
?>
With the defaults settings we obtain
<?php
$a = array('1', array('1.1', '1.2', '1.3'));
// php_beautifier->addFilter('ArrayNested');
$a = array(
'1',
array(
'1.1',
'1.2',
'1.3'
)
);
// php_beautifier->setIndentNumber(2);
echo 'Indent: 2 spaces';
// php_beautifier->setIndentNumber(10);
echo 'Indent: 10 spaces';
// php_beautifier->setBeautify(false);
echo "The following lines won't be beautified";
$a=array('1',array('1.1','1.2','1.3'));
if ($b) {$c;} else {$d;}
// php_beautifier->setBeautify(true);
// php_beautifier->setIndentNumber(4);
echo 'Beautify, again';
// now, turn out the Filter
// ArrayNested->off()
$a = array('1', array('1.1', '1.2', '1.3'));
// ArrayNested->on()
$a = array(
'1',
array(
'1.1',
'1.2',
'1.3'
)
);
?>
More information
See PHP_Beautifier::controlToken()
|
|
|
|
Introduction to PHP_Beautifier
|
Introduction to PHP_Beautifier
|
How to use PHP_Beautifier
|
Documentation generated on Sun, 22 Jun 2008 18:59:29 -0400 by phpDocumentor 1.3.1