Hello
Can anyone list the steps to integrate PHP_Beautifier in phped.
Hello
Can anyone list the steps to integrate PHP_Beautifier in phped.
You should try the steps located here. These are general steps for integrating any script which returns code back to the editor.
Note in Step 5:
<?php
$f = fopen("php://stdin", "r");
$s = fread($f, 100000); // should be big enough
fclose($f);
echo "\"" . $s . "\"";
?>
This should be ignored and is pretty sloppy. It'd be something like the format from other PHPed scripts posted here.
Now to see how to actually use PHP_beautifier, refer to the documentation.
To quote the documentation:
// Create the instance
$oBeautifier = new PHP_Beautifier();
/* snip optional stuff*/
// Define the input file
$oBeautifier->setInputFile(__FILE__);
// Define an output file.
// $oBeautifier->setOutputFile(__FILE__.'.beautified.php'); No need for this
// Process the file. DON'T FORGET TO USE IT
$oBeautifier->process();
// Show the file (echo to screen)
$oBeautifier->show();
// Save the file
//$oBeautifier->save(); No Need for this.
OK so we need to give it a file instead, but I've looked in the main Beautifier.php file and it seems to accept STDIN in some manner. So let's make the script:
<?php
class BeautifyCode
{
public function run()
{
require_once('path/to/Beautifier.php'); // It's the main file in the PEAR package
// Create the instance
$oBeautifier = new PHP_Beautifier();
// Define the input file
// I believe you leave blank for STDIN, looking through the code **
$oBeautifier->setInputFile();
// If that doesn't work try:
// $oBeautifier->setInputFile('php://stdin');
$oBeautifier->process();
$oBeautifier->show();
// If that doesn't work, try this:
// echo utf8_decode($oBeautifier->get());
}
}
$bc = new BeautifyCode;
$bc->run();
?>
So save this anywhere as a PHP file, and then call it according to Step 3 of the first link. I would be safe and use @php5@
, as PHP_beautifier probably requires it.
I apologize in advance, I'm not exactly certain how PHP_beautifier handles the STDIN input. I looked through the code but could not tell for certain. Another option is to always save the PHP file you're cleaning first, and then look through the phpED documentation for how to get the path to the PHP file you have open and are cleaning.
If I had more to time to look through the PHP_beautifier package I could give a more definite answer.
You can use STDIN and STDOUT as input or output
// Create the instance
$oBeautifier = new PHP_Beautifier();
// Define the input file
// I believe you leave blank for STDIN, looking through the code **
$oBeautifier->setInputFile(STDIN);
$oBeautifier->setOutputFile(STDOUT);
$oBeaut->process();
$oBeaut->save();