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: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299:
<?php
include_once(__DIR__.'/Php/Completer.php');
class Packager_Php extends Packager_Php_Completer
{
const FS_MODE_PRESERVE_HDD = 'PHP_PRESERVE_HDD';
const FS_MODE_PRESERVE_PACKAGE = 'PHP_PRESERVE_PACKAGE';
const FS_MODE_STRICT_HDD = 'PHP_STRICT_HDD';
const FS_MODE_STRICT_PACKAGE = 'PHP_STRICT_PACKAGE';
const FS_MODE_PHP_LIBRARY = 'PHP_LIBRARY';
/**
* Create singleton instance with configuration
*
* @param array $cfg
*
* @return Packager_Php
*/
public static function Create ($cfg = []) {
return parent::Create($cfg);
}
/**
* Get instance and merge configuration or create singleton instance with configuration
*
* @param array $cfg
*
* @return Packager_Php
*/
public static function Get ($cfg = []) {
return parent::Get($cfg);
}
/**
* Set application sources directory
*
* @param string $fullOrRelativePath
*
* @return Packager_Php
*/
public function SetSourceDir ($fullOrRelativePath = '') {
return parent::SetSourceDir($fullOrRelativePath);
}
/**
* Set compilation result(s) directory, all files will be removed first.
*
* @param string $fullOrRelativePath
*
* @return Packager_Phar
*/
public function SetReleaseDir ($fullOrRelativePath = '') {
return parent::SetReleaseDir($fullOrRelativePath);
}
/**
* Set compilation result PHP script file name, '/index.php` by default.
*
* @param string $releaseFileName
*
* @return Packager_Phar
*/
public function SetReleaseFileName ($releaseFileName = '/index.php') {
return parent::SetReleaseFileName($releaseFileName);
}
/**
* Set preg_replace() patterns array or single string about
* which files or folders will be excluded from result file.
* Function replace all previous configuration records.
*
* @param array|string $excludePatterns
*
* @return Packager_Php
*/
public function SetExcludePatterns ($excludePatterns = []) {
return parent::SetExcludePatterns($excludePatterns);
}
/**
* Add preg_replace() patterns array or single string about
* which files or folders will be excluded from result file.
*
* @param array|string $excludePatterns
*
* @return Packager_Php
*/
public function AddExcludePatterns ($excludePatterns = []) {
return parent::AddExcludePatterns($excludePatterns);
}
/**
* Set patterns/replacements array about what will be replaced
* in *.php and *.phtml files by preg_replace(pattern, replacement, source)
* before possible minification process.
* Function replace all previous configuration records.
*
* @param array $patternReplacements
*
* @return Packager_Php
*/
public function SetPatternReplacements ($patternReplacements = []) {
return parent::SetPatternReplacements($patternReplacements);
}
/**
* Add patterns/replacements array about what will be replaced
* in *.php and *.phtml files by preg_replace(pattern, replacement, source)
* before possible minification process.
*
* @param array $patternReplacements
*
* @return Packager_Php
*/
public function AddPatternReplacements ($patternReplacements = []) {
return parent::AddPatternReplacements($patternReplacements);
}
/**
* Set str_replace() key/value array about
* what will be simply replaced in result file.
* Function replace all previous configuration records.
*
* @param array $stringReplacements
*
* @return Packager_Php
*/
public function SetStringReplacements ($stringReplacements = []) {
return parent::SetStringReplacements($stringReplacements);
}
/**
* Add str_replace() key/value array about
* what will be simply replaced in result file.
*
* @param array $stringReplacements
*
* @return Packager_Php
*/
public function AddStringReplacements ($stringReplacements = []) {
return parent::AddStringReplacements($stringReplacements);
}
/**
* Set list of relative PHP file path(s) from application document root
* to include in result file as first, after everything will be included
* by automatic order determination. List will be prepended or appended
* before or after existing list by second param
* Function replace all previous configuration records.
*
* @param array|string $includeFirst
*
* @return Packager_Php
*/
public function SetIncludeFirst ($includeFirst = []) {
return parent::SetIncludeFirst($includeFirst);
}
/**
* Add list of relative PHP file path(s) from application document root
* to include in result file as first, after everything will be included
* by automatic order determination. List will be prepended or appended
* before or after existing list by second param.
*
* @param array|string $includeFirst
* @param string $mode 'append' or 'prepend'
*
* @return Packager_Php
*/
public function AddIncludeFirst ($includeFirst = [], $mode = 'append') {
return parent::AddIncludeFirst($includeFirst, $mode);
}
/**
* Set list of relative PHP file path(s) from application document root
* to include in result file as last, after everything will be included
* by automatic order determination. List will be prepended or appended
* before or after existing list by second param
* Function replace all previous configuration records.
*
* @param array|string $includeLast
*
* @return Packager_Php
*/
public function SetIncludeLast ($includeLast = []) {
return parent::SetIncludeLast($includeLast);
}
/**
* Add list of relative PHP file path(s) from application document root
* to include in result file as last, after everything will be included
* by automatic order determination. List will be prepended or appended
* before or after existing list by second param.
* By default, there is initialized by default "index.php" file to include
* as last, see Packager_Php::SetIncludeLastDefault() to overwrite it
* or use (new Packager_Php)->SetIncludeLast() to overwrite it.
*
* @param array|string $includeLast
* @param string $mode 'append' or 'prepend'
*
* @return Packager_Php
*/
public function AddIncludeLast ($includeLast = [], $mode = 'append') {
return parent::AddIncludeLast($includeLast, $mode);
}
/**
* Set boolean if *.phtml templates will be minimized before saving into result file
*
* @param string $minifyTemplates
*
* @return Packager_Php
*/
public function SetMinifyTemplates ($minifyTemplates = TRUE) {
return parent::SetMinifyTemplates($minifyTemplates);
}
/**
* Set boolean if *.php scripts will be minimized before saving into result file
*
* @param string $minifyPhp
*
* @return Packager_Php
*/
public function SetMinifyPhp ($minifyPhp = TRUE) {
return parent::SetMinifyPhp($minifyPhp);
}
/**
* Set mode for wrapper class how to behave when any replaced file system php
* function will be called - it here will be searching in memory and after in HDD
* or HDD first and then memory or no memory or no HDD.
*
* @param string $fsMode
*
* @return Packager_Php
*/
public function SetPhpFileSystemMode ($fsMode = self::FS_MODE_PRESERVE_HDD) {
return parent::SetPhpFileSystemMode($fsMode);
}
/**
* Enable or disable PHP files order detection by autoloader(s),
* by MvcCore startup.php autoloader or by startup.php and composer autoloader.
*
* @param bool $enabled
*
* @return Packager_Php
*/
public function SetAutoloadingOrderDetection ($enabled = TRUE) {
return parent::SetAutoloadingOrderDetection($enabled);
}
/**
* Define all php functions you want to replace with internal php file calls as strings,
* named functions will not be used in original way to read/write anything from hard drive,
* all specified functions will be replaced with wrapper calls to give results from memory variables.
* It's possible to name 'include' and 'require', but all 'include_once' and 'require_once'
* are replaced automatically if there is safely detected line content - string only, no variables inside
*
* @param string $phpFuncStr,...
*
* @return Packager_Php
*/
public function ReplacePhpFunctions () {
return parent::ReplacePhpFunctions(func_get_args());
}
/**
* Define all php functions you don't want to replace with internal php file calls as strings,
* named functions will be used in original way to read/write anything from hard drive.
* It's possible to name 'include' and 'require', but all 'include_once' and 'require_once'
* are replaced automatically if there is safely detected line content - string only, no variables inside
*
* @param string $phpFuncStr
*
* @return Packager_Php
*/
public function KeepPhpFunctions () {
return parent::KeepPhpFunctions(func_get_args());
}
/**
* Set array with statically copied files or directories from `./development` to `./release` directory.
* If key is numeric, source and destination relative path are the same. If key is string, source
* relative path is defined by array key and destination relative path is defined by array value.
*
* @param array $staticCopies
*
* @return Packager_Php
*/
public function SetStaticCopies ($staticCopies = [/* '/from-dir' => '/to-dir', '/filename', '/dirname' */]) {
return parent::SetStaticCopies($staticCopies);
}
/**
* Merge multilevel configuration array with previously initialized values.
* New values sent into this function will be used as preferred.
*
* @param array $cfg
*
* @return Packager_Php
*/
public function MergeConfiguration ($cfg = []) {
return parent::MergeConfiguration($cfg);
}
/**
* Run PHP compilation process, print output to CLI or browser.
*
* @return Packager_Php
*/
public function Run () {
parent::Run();
list($jobMethod, $params) = $this->completeJobAndParams();
$this->$jobMethod($params);
return $this;
}
}