summaryrefslogtreecommitdiff
path: root/tools/phpbuilder/build.php
blob: 24626b851d1f0cac69bc954bd659b31e43868733 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/php
<?php
/**
 * Prado build file.
 *
 * This script compresses a list of Prado PHP script files
 * and merges them into one for performance redistribution.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.pradosoft.com/
 * @copyright Copyright &copy; 2005 PradoSoft
 * @license http://www.pradosoft.com/license/
 * @version $Revision: $  $Date: $
 * @package Tools
 */

/**
 * The merged file name
 */
define('OUTPUT_FILE','pradolite.php');
/**
 * The framework directory
 */
define('FRAMEWORK_DIR',realpath(dirname(__FILE__).'/../../framework'));
/**
 * The file containing script list to be built
 */
define('SCRIPT_FILES',dirname(__FILE__).'/files.txt');

if(FRAMEWORK_DIR===false)
	die('Unable to determine the installation directory of Prado Framework.');
if(!is_file(SCRIPT_FILES))
	die('Unable to read '.SCRIPT_FILES.'.');

$output='';

$lines=file(SCRIPT_FILES);
foreach($lines as $line)
{
	$line=trim($line);
	if($line==='')
		continue;
	echo 'adding '.FRAMEWORK_DIR.'/'.$line."\n";
	$input=file_get_contents(FRAMEWORK_DIR.'/'.$line);
	$input = strip_comments($input);
	$input=strtr($input,"\r",' ');
	$input=preg_replace("/\s*(\n+\s*){2,}\s*/m","\n",$input);
	$input=preg_replace('/^Prado::using\([^\*]*?\);/mu','',$input);
	$input=preg_replace('/^(require|require_once)\s*\(.*?;/mu','',$input);
	$input=preg_replace('/^(include|include_once)\s*\(.*?;/mu','',$input);

	//remove internal logging
	$input=preg_replace('/^\s*Prado::coreLog.*\s*;\s*$/mu','',$input);

	$output.=$input;
}

file_put_contents(FRAMEWORK_DIR.'/'.OUTPUT_FILE,$output);

function strip_comments($source)
{
  $tokens = token_get_all($source);
  /* T_ML_COMMENT does not exist in PHP 5.
   * The following three lines define it in order to
   * preserve backwards compatibility.
   *
   * The next two lines define the PHP 5-only T_DOC_COMMENT,
   * which we will mask as T_ML_COMMENT for PHP 4.
   */
  if (!defined('T_ML_COMMENT')) {
    @define('T_ML_COMMENT', T_COMMENT);
  } else {
    @define('T_DOC_COMMENT', T_ML_COMMENT);
  }
  $output = '';
  foreach ($tokens as $token) {
    if (is_string($token)) {
      // simple 1-character token
      $output .= $token;
    } else {
      // token array
      list($id, $text) = $token;
      switch ($id) { 
        case T_COMMENT: 
        case T_ML_COMMENT: // we've defined this
        case T_DOC_COMMENT: // and this
          // no action on comments
          break;
        default:
          // anything else -> output "as is"
          $output .= $text;
          break;
      }
    }
  }
  return $output;
}

?>