#!/usr/bin/php <?php require_once 'PHP/Beautifier.php'; // Create the instance $oBeautifier = new PHP_Beautifier(); echo "Filter Directory: " . dirname(__FILE__) . '/beautifier_filters' . "\n"; $oBeautifier->addFilterDirectory(dirname(__FILE__) . '/beautifier_filters'); // Add a filter, without any parameter $oBeautifier->addFilter('TTDefault'); // Set the indent char, number of chars to indent and newline char $oBeautifier->setIndentChar(' '); $oBeautifier->setIndentNumber(4); $oBeautifier->setNewLine("\n"); // Define the input file $oBeautifier->setInputFile($argv[1]); // Define an output file. //$oBeautifier->setOutputFile( $argv[1] .'.beautified.php'); $oBeautifier->setOutputFile($argv[1]); // Process the file. DONT FORGET TO USE IT $oBeautifier->process(); // Show the file (echo to screen) //$oBeautifier->show(); // Save the file $oBeautifier->save();
private function ___beautify___($ugly_source, $params = array()) { require_once 'PHP/Beautifier.php'; $oBeautifier = new PHP_Beautifier(); $default_params = array_merge(array('indent_char' => ' ', 'indent_number' => 4, 'new_line' => PHP_EOL, 'style' => 'allman'), $params); // add some filters if not exist already $oBeautifier->addFilterDirectory(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Filter'); // Add filters for array and code indentation style $oBeautifier->addFilter('ArrayNested'); $oBeautifier->addFilter('IndentStyles', array('style' => $default_params['style'])); // Set the indent char, number of chars to indent and newline char $oBeautifier->setIndentChar($default_params['indent_char']); $oBeautifier->setIndentNumber($default_params['indent_number']); $oBeautifier->setNewLine($default_params['new_line']); // Define the input file $oBeautifier->setInputString($ugly_source); // Process the file. DON'T FORGET TO USE IT $oBeautifier->process(); // return beautiful source return $oBeautifier->get(); }