This is a set of functions designed to compress and compile PHP files for faster loading and smaller through-put. You'd be amazed how much memory this can save!
Definition at line 15 of file PhpCompiler.class.php.
Public Member Functions | |
& | PhpCompiler () |
Constructor should set default modes. | |
ChangeMode ($NewModes=array()) | |
Set engine choices. | |
GetModes () | |
Get the modes for ChangeMode(). | |
GetErrors () | |
Stub function for returning errors. | |
Compile ($Input) | |
Perform actual compile stage. | |
MakeLibrary ($Input) | |
Combine multiple concatenated files into a single logical file by removing opening and closing PHP tags (except for first and last) and removing ALL newlines. | |
NoDebugCode ($Input) | |
Strip out NODEBUG blocks from code. | |
PhpScrub ($Input) | |
Strip out white-space and comments from PHP code. | |
Private Attributes | |
$_UseMakeLibrary | |
Boolean optionally use this component. | |
$_UseNoDebugCode | |
Boolean optionally use this component. | |
$_UsePhpScrub | |
Boolean optionally use this component. |
|
Constructor should set default modes.
Definition at line 53 of file PhpCompiler.class.php. 00054 {
00055 $this->_UseMakeLibrary = FALSE;
00056 $this->_UseNoDebugCode = TRUE;
00057 $this->_UsePhpScrub = TRUE;
00058 return($this);
00059 }
|
|
Set engine choices.
Definition at line 74 of file PhpCompiler.class.php. 00075 { 00076 $name_conversion = array( 00077 "library" => "_UseMakeLibrary", 00078 "nodebug" => "_UseNoDebugCode", 00079 "whitespace" => "_UsePhpScrub", 00080 ); 00081 00082 if(!is_array($NewModes)) 00083 { 00084 return(FALSE); 00085 } 00086 00087 foreach($NewModes as $Name => $Value) 00088 { 00089 if(!isset($name_conversion[$Name])) 00090 { 00091 return(FALSE); 00092 } 00093 00094 if(!is_bool($Value)) 00095 { 00096 return(FALSE); 00097 } 00098 00099 $Name = $name_conversion[$Name]; 00100 $this->$Name = $Value; 00101 } 00102 00103 return(TRUE); 00104 }
|
|
Perform actual compile stage.
Definition at line 167 of file PhpCompiler.class.php. References MakeLibrary(), NoDebugCode(), and PhpScrub(). 00168 { 00169 if(!is_string($Input)) 00170 { 00171 return(""); 00172 } 00173 00174 if($this->_UseNoDebugCode) 00175 { 00176 $Input = $this->NoDebugCode($Input); 00177 } 00178 if($this->_UsePhpScrub) 00179 { 00180 $Input = $this->PhpScrub($Input); 00181 } 00182 if($this->_UseMakeLibrary) 00183 { 00184 $Input = $this->MakeLibrary($Input); 00185 } 00186 00187 return($Input); 00188 }
|
Here is the call graph for this function:
|
Stub function for returning errors.
Definition at line 149 of file PhpCompiler.class.php. 00150 {
00151 return(array());
00152 }
|
|
Get the modes for ChangeMode().
Definition at line 116 of file PhpCompiler.class.php. 00117 { 00118 return(array( 00119 array( 00120 "Name" => "library", 00121 "Default" => FALSE, 00122 "Description" => 00123 "Remove extra newlines and php tags" 00124 ), 00125 array( 00126 "Name" => "nodebug", 00127 "Default" => TRUE, 00128 "Description" => 00129 "Remove /*NODEBUG{*/.../*}NODEBUG*/ blocks" 00130 ), 00131 array( 00132 "Name" => "whitespace", 00133 "Default" => TRUE, 00134 "Description" => 00135 "Pass through 'php -w'" 00136 ), 00137 )); 00138 }
|
|
Combine multiple concatenated files into a single logical file by removing opening and closing PHP tags (except for first and last) and removing ALL newlines. So you have a bunch of PHP files which contain class definitions, and you need them in a library file so that there's only one file to include to get all your class definitions. Easily done! Just concatenate ALL the files together through this, and they'll be smushed down into a single PHP block.
Definition at line 219 of file PhpCompiler.class.php. Referenced by Compile(). 00220 { 00221 $replace = array( 00222 '/\n/s' => '' , # Remove all newlines 00223 '/\<\?'.'php/s' => '' , # Remove all open tags 00224 '/\?\>/s' => '' , # Remove all close tags 00225 '/^/s' => '<?'.'php ' , # Add beginning open tag 00226 '/$/s' => ' ?'.'>' , # Add ending close tag 00227 ); 00228 00229 $Input = preg_replace( 00230 array_keys($replace), 00231 array_values($replace), 00232 $Input 00233 ); 00234 00235 return($Input); 00236 }
|
|
Strip out NODEBUG blocks from code. So you have a file which you want to put debug code in, but don't want that very same code going to a production server. The solution is simple! Just put small comment tags around the debug code, and pass it through a simple script which will remove such blocks. That's what this does!
Definition at line 259 of file PhpCompiler.class.php. Referenced by Compile(). 00260 { 00261 $strlen = strlen($Input); 00262 $inblock = FALSE; 00263 $return = ""; 00264 $block = ""; 00265 for($x = 0; $x < $strlen; $x++) 00266 { 00267 if(START_TAG == substr($Input, $x, strlen(START_TAG))) 00268 { 00269 if($block) 00270 { 00271 $return .= $block; 00272 $block = ""; 00273 } 00274 00275 $inblock = TRUE; 00276 } 00277 if(END_TAG == substr($Input, $x, strlen(END_TAG))) 00278 { 00279 if($inblock) 00280 { 00281 $inblock = FALSE; 00282 $block = ""; 00283 $x += strlen(END_TAG); 00284 } 00285 } 00286 if(!$inblock) 00287 { 00288 $return .= $Input[$x]; 00289 } 00290 else 00291 { 00292 $block .= $Input[$x]; 00293 } 00294 } 00295 00296 if($return !== $Input) 00297 { 00298 return($this->NoDebugCode($return)); 00299 } 00300 00301 return($return); 00302 }
|
|
Strip out white-space and comments from PHP code. Have a PHP file with a lot of comments, white space, and other junk that you'd like to strip out? Use this! Admittedly, it's just a system call to php -w, but in the future this may be updated to take advantage of PHP 5 code parsing functions.
Definition at line 318 of file PhpCompiler.class.php. Referenced by Compile(). 00319 { 00320 $Input = escapeshellarg($Input); 00321 $Command = "echo $Input | php -w "; 00322 $Return = shell_exec($Command); 00323 return($Return); 00324 }
|
|
Boolean optionally use this component.
Definition at line 24 of file PhpCompiler.class.php. |
|
Boolean optionally use this component.
Definition at line 33 of file PhpCompiler.class.php. |
|
Boolean optionally use this component.
Definition at line 42 of file PhpCompiler.class.php. |