ZenMagick 0.9.10


org.zenmagick.core.utils.packer\ZMPhpCompressor
core\utils\packer\ZMPhpCompressor.php at line 56

Class ZMPhpCompressor

ZMPhpCompressor

public class ZMPhpCompressor

Generic PHP code compressor.

Can be used to compress all PHP files of a given folder or folder tree into a single PHP file.

Supports some archaic form of inheritance/dependencies in that levels are processed one after the other. That means that a class in a second level folder may extend any class that resides in the root folder or any first level folder.

If no temp folder is configured, the location of this file will be used to store temporary files and folders.

This class maintains its own version of findIncludes() as the ZMLoader version does not reflect the hierachy (any more).

Author:
DerManoMann

Field Summary
protected mixed

$errors_

protected mixed

$flatFolder_

protected mixed

$outputFilename_

protected mixed

$rootFolders_

protected mixed

$stripCode_

protected mixed

$stripRef_

protected mixed

$strippedFolder_

protected mixed

$tempFolder_

Method Summary
void

__construct(mixed root, string out, string temp)

Create new instance.

void

clean()

Clean up all temp.

boolean

compress()

Compress accoding to the current settings.

protected void

compressToSingleFile(string in, string outfile)

Compress all files into a single file

protected array

finaliseFiles(array files)

Empty callback to make final adjustments to the file list before compressing to a single file.

static array

findIncludes(string dir, string ext, boolean recursive)

Scan (recursively) for .php files.

protected void

flattenDirStructure(string in, string out)

Flatten the directory structure.

array

getErrors()

Get errors.

boolean

hasErrors()

Check for errors.

void

setOut(string out)

Set the output filename.

void

setRoot(mixed root)

Set the root folder(s).

void

setStripCode(boolean strip)

Configure whether or not to strip the compressed code.

void

setStripRef(boolean strip)

Configure whether or not to strip the use of references; eg.

void

setTemp(string temp)

Set the temp folder.

protected void

stripPhpDir(string in, string out, boolean recursive)

Recursivley strip a directory.

protected void

stripPhpFile(string in, string out)

Strip a PHP file.

protected string

stripPhpSource(string source)

Strip the given PHP source text.

Field Detail

core\utils\packer\ZMPhpCompressor.php at line 60

errors_

protected mixed $errors_

core\utils\packer\ZMPhpCompressor.php at line 64

flatFolder_

protected mixed $flatFolder_

core\utils\packer\ZMPhpCompressor.php at line 58

outputFilename_

protected mixed $outputFilename_

core\utils\packer\ZMPhpCompressor.php at line 57

rootFolders_

protected mixed $rootFolders_

core\utils\packer\ZMPhpCompressor.php at line 67

stripCode_

protected mixed $stripCode_

core\utils\packer\ZMPhpCompressor.php at line 68

stripRef_

protected mixed $stripRef_

core\utils\packer\ZMPhpCompressor.php at line 63

strippedFolder_

protected mixed $strippedFolder_

core\utils\packer\ZMPhpCompressor.php at line 59

tempFolder_

protected mixed $tempFolder_

Method Detail

core\utils\packer\ZMPhpCompressor.php at line 78

__construct

public void __construct(mixed root, string out, string temp)

Create new instance.

Parameters:
root - The root directory to compress (or array of directory names); default is null.
out - The [full] output filename; default is null.
temp - A temp folder for transient files and folders; default is null.

core\utils\packer\ZMPhpCompressor.php at line 172

clean

public void clean()

Clean up all temp. files.


core\utils\packer\ZMPhpCompressor.php at line 182

compress

public boolean compress()

Compress accoding to the current settings.

Returns:
true if successful, false on failure.

core\utils\packer\ZMPhpCompressor.php at line 467

compressToSingleFile

protected void compressToSingleFile(string in, string outfile)

Compress all files into a single file

Parameters:
in - The input directory.
outfile - The output file.

core\utils\packer\ZMPhpCompressor.php at line 457

finaliseFiles

protected array finaliseFiles(array files)

Empty callback to make final adjustments to the file list before compressing to a single file.

Parameters:
files - List of files.
Returns:
The final list.

core\utils\packer\ZMPhpCompressor.php at line 309

findIncludes

public static array findIncludes(string dir, string ext, boolean recursive)

Scan (recursively) for .php files.

It is worth mentioning that directories will always be processed only after all plain files in a directory are done.

Parameters:
dir - The name of the root directory to scan.
ext - Optional file suffix/extension; default is .php.
recursive - If true, scan recursively.
Returns:
List of full filenames of .php files.

core\utils\packer\ZMPhpCompressor.php at line 390

flattenDirStructure

protected void flattenDirStructure(string in, string out)

Flatten the directory structure.

Parameters:
in - The input directory.
out - The output directory.

core\utils\packer\ZMPhpCompressor.php at line 94

getErrors

public array getErrors()

Get errors.

Returns:
List of text messages.

core\utils\packer\ZMPhpCompressor.php at line 103

hasErrors

public boolean hasErrors()

Check for errors.

Returns:
true if errors exist.

core\utils\packer\ZMPhpCompressor.php at line 125

setOut

public void setOut(string out)

Set the output filename.

Parameters:
out - The [full] output filename.

core\utils\packer\ZMPhpCompressor.php at line 112

setRoot

public void setRoot(mixed root)

Set the root folder(s).

Parameters:
root - The root directory to compress (or array of directory names); default is null.

core\utils\packer\ZMPhpCompressor.php at line 156

setStripCode

public void setStripCode(boolean strip)

Configure whether or not to strip the compressed code.

Disabling stripping will have the following effects:

Parameters:
strip - The new value.

core\utils\packer\ZMPhpCompressor.php at line 165

setStripRef

public void setStripRef(boolean strip)

Configure whether or not to strip the use of references; eg. &$ or = &.

Parameters:
strip - The new value.

core\utils\packer\ZMPhpCompressor.php at line 134

setTemp

public void setTemp(string temp)

Set the temp folder.

Parameters:
temp - A temp folder for transient files and folders (unless stripping is off).

core\utils\packer\ZMPhpCompressor.php at line 351

stripPhpDir

protected void stripPhpDir(string in, string out, boolean recursive)

Recursivley strip a directory.

Uses self::findIncludes() to find files to process.

Parameters:
in - The input directory.
out - The output directory.
recursive - If true, strip recursivley.

core\utils\packer\ZMPhpCompressor.php at line 274

stripPhpFile

protected void stripPhpFile(string in, string out)

Strip a PHP file.

Parameters:
in - The input filename.
out - The output filename; if null just echo; default is null.

core\utils\packer\ZMPhpCompressor.php at line 220

stripPhpSource

protected string stripPhpSource(string source)

Strip the given PHP source text.

Parameters:
source - The PHP source code.
Returns:
The stripped code.

ZenMagick 0.9.10