Exemplo n.º 1
0
#!/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();
Exemplo n.º 2
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";
     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);
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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();
 }
Exemplo n.º 5
0
    if ($locale != 'en_US') {
        $filename .= ".{$locale}";
    }
    $filename .= '.mysql';
    $fd = fopen($sqlCodePath . $filename, "w");
    fputs($fd, $data);
    fclose($fd);
}
echo "\ncivicrm_domain.version := {$db_version}\n\n";
$tsLocale = 'en_US';
$sample = $smarty->fetch('civicrm_sample.tpl');
$sample .= $smarty->fetch('civicrm_acl.tpl');
file_put_contents($sqlCodePath . 'civicrm_sample.mysql', $sample);
$beautifier = new PHP_Beautifier();
// create a instance
$beautifier->addFilter('ArrayNested');
$beautifier->addFilter('Pear');
// add one or more filters
$beautifier->addFilter('NewLines', array('after' => 'class, public, require, comment'));
// add one or more filters
$beautifier->setIndentChar(' ');
$beautifier->setIndentNumber(4);
$beautifier->setNewLine("\n");
foreach (array_keys($tables) as $name) {
    $smarty->clear_all_cache();
    echo "Generating {$name} as " . $tables[$name]['fileName'] . "\n";
    $smarty->clear_all_assign();
    $smarty->assign_by_ref('table', $tables[$name]);
    $php = $smarty->fetch('dao.tpl');
    $beautifier->setInputString($php);
    if (empty($tables[$name]['base'])) {
Exemplo n.º 6
0
 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;
     }
 }
    $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();
    }
}
Exemplo n.º 8
0
 * PHP version 5
 *
 * @category   Coda Plugins
 * @package    Pear PHP
 * @subpackage PHP_Beautifier
 * @author     Sofia Cardita <*****@*****.**> 
 *
 */
chdir('/Applications/MAMP/bin/php/php5.3.6/share/pear/');
error_reporting(E_ALL);
$path = 'PHP/Beautifier.php';
if (!file_exists($path)) {
    echo 'File not found: ' . $path . '. Pear must be in your path. If not 
            you need to set the correct path to Pear\'s Beautifier.php. ' . 'Included paths: ' . get_include_path() . '. Change it in this file: ' . __FILE__;
    die;
}
require $path;
$source = '';
while ($inp = fread(STDIN, 8192)) {
    $source .= $inp;
}
$oToken = new PHP_Beautifier();
$oToken->addFilter('Pear');
$oToken->addFilter('DocBlock');
$oToken->addFilter('ArrayNested');
$oToken->addFilter('EqualsAlign');
//add other filters here
$oToken->setInputString($source);
$oToken->process();
// required
echo $oToken->show();
#!/usr/bin/env php
<?php

require 'PHP/Beautifier.php';
error_reporting(1);

$source = file_get_contents($argv[1]);
$oToken = new PHP_Beautifier();
$oToken->addFilter('Pear');
$oToken->addFilter('DocBlock');
$oToken->addFilter('ArrayNested');
$oToken->setInputString($source);
$oToken->process(); // required
$oToken->show();