コード例 #1
0
ファイル: beautifier.php プロジェクト: alachaum/timetrex
#!/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();
コード例 #2
0
ファイル: i18n.php プロジェクト: rjmackay/kohana-i18n-manager
 private function __write_php_file($lang, $file, $content)
 {
     $content = (string) $content;
     require_once 'PHP/Beautifier.php';
     $oBeautifier = new PHP_Beautifier();
     $oBeautifier->addFilter('ArrayNested');
     $oBeautifier->setIndentChar("\t");
     $oBeautifier->setIndentNumber(1);
     $oBeautifier->setNewLine("\n");
     $oBeautifier->setInputString($content);
     $oBeautifier->process();
     // required
     $content = $oBeautifier->get();
     $content = mb_convert_encoding((string) $content, 'UTF-8');
     $dir = APPPATH . "i18n/{$lang}/";
     if (!is_dir($dir)) {
         mkdir($dir, 0777, TRUE);
     }
     // Write the contents to the file
     $file = "{$dir}{$file}.php";
     if (file_exists($file)) {
         // Load old file and compare
         $old_contents = file_get_contents($file);
         // If array text is identical, don't change the file
         if (substr($old_contents, strpos($old_contents, '$lang')) == substr($content, strpos($content, '$lang'))) {
             echo ".. unchanged, skipping\n";
             return;
         }
     }
     file_put_contents($file, $content);
     //chmod($file, 0755);
 }
コード例 #3
0
 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();
 }
コード例 #4
0
 private function __write_php_file($lang, $file, $content)
 {
     $content = (string) $content;
     require_once 'PHP/Beautifier.php';
     $oBeautifier = new PHP_Beautifier();
     $oBeautifier->addFilter('ArrayNested');
     $oBeautifier->setIndentChar("\t");
     $oBeautifier->setIndentNumber(1);
     $oBeautifier->setNewLine("\n");
     $oBeautifier->setInputString($content);
     $oBeautifier->process();
     // required
     $content = $oBeautifier->get();
     $content = mb_convert_encoding((string) $content, 'UTF-8');
     $dir = APPPATH . "i18n/{$lang}/";
     if (!is_dir($dir)) {
         mkdir($dir, 0777, TRUE);
     }
     // Write the contents to the file
     $file = "{$dir}{$file}.php";
     file_put_contents($file, $content);
     //chmod($file, 0755);
 }
コード例 #5
0
ファイル: Generator.php プロジェクト: sebcode/proust
 public function beautifyString($str)
 {
     if ($this->beautify) {
         if (!@(include_once 'PHP/Beautifier.php')) {
             return $str;
         }
         $o_b = new \PHP_Beautifier();
         $o_b->setBeautify(true);
         $o_b->addFilter('ListClassFunction');
         $o_b->setIndentChar(' ');
         $o_b->setIndentNumber(2);
         $o_b->setNewLine("\n");
         $o_b->setInputString("<? {$str} ?>");
         $o_b->process();
         $res = $o_b->get();
         $res = preg_replace('/^\\<\\?\\s+/', '', $res);
         $res = preg_replace('/\\s+\\?\\>$/', '', $res);
         return $res;
     } else {
         return $str;
     }
 }
コード例 #6
0
    $constructorcode .= "    \$directory = dirname(__FILE__).DIRECTORY_SEPARATOR;\n";
    $constructorcode .= "    foreach(\$options['classmap'] as \$key => \$value) if(file_exists('{\$directory}../structures/{\$value}.php')) include_once('{\$directory}../structures/{\$value}.php');\n";
    $constructorcode .= "    parent::__construct(\$wsdl, \$options);";
    $aliascode = <<<EOD
class_alias("{$serviceName}", "{$oldServiceName}");
?>

EOD;
    $file = str_replace($oldServiceName, $serviceName, $file);
    $file = str_replace("parent::__construct(\$wsdl, \$options);", $constructorcode, $file);
    $file = str_replace("?>", $aliascode, $file);
    file_put_contents($serviceFile, $file);
    rename($serviceFile, "splitteroutput/services/{$serviceName}.php");
    file_put_contents("splitteroutput/services/{$oldServiceName}.php", "<?php include_once(\"{$serviceName}.php\"); ?>\n");
}
foreach (glob("splitteroutput/*.php") as $structureFile) {
    rename($structureFile, "splitteroutput/structures/" . basename($structureFile));
}
include_once "PHP/Beautifier.php";
if (class_exists('PHP_Beautifier')) {
    $beautifier = new PHP_Beautifier();
    $beautifier->addFilter('ArrayNested');
    $beautifier->setIndentChar("\t");
    $beautifier->setIndentNumber(1);
    foreach (glob("splitteroutput/*/*.php") as $file) {
        $beautifier->setInputFile($file);
        $beautifier->setOutputFile($file);
        $beautifier->process();
        $beautifier->save();
    }
}
コード例 #7
0
 /**
  * Beautifies PHP code with the PHP_Beautify library.
  * 
  * @since       1.2.0
  * @see         http://beautifyphp.sourceforge.net/docs/
  * @see         http://beautifyphp.sourceforge.net/docs/PHP_Beautifier/tutorial_PHP_Beautifier.howtouse.script.pkg.html
  */
 private function _getBeautifiedPHPCode($sCode)
 {
     // Create the instance
     $_oBeautifier = new PHP_Beautifier();
     // Set the indent char, number of chars to indent and newline char
     $_oBeautifier->setIndentChar(' ');
     $_oBeautifier->setIndentNumber(4);
     $_oBeautifier->setNewLine("\n");
     // Set the code
     $_oBeautifier->setInputString($sCode);
     // Process the file. DON'T FORGET TO USE IT
     $_oBeautifier->process();
     return $_oBeautifier->get();
 }