- added function to FroxlorPkgCreator::addFile($name, $data)

This commit is contained in:
Andreas Burchert (scarya)
2010-10-20 21:09:52 +00:00
parent 71d3410b4f
commit 7a83a01095

View File

@@ -39,9 +39,8 @@
*/ */
class FroxlorPkgCreator class FroxlorPkgCreator
{ {
/** /**
* Path to file-include list. * Path to save file.
* *
* @var string * @var string
*/ */
@@ -54,6 +53,14 @@ class FroxlorPkgCreator
*/ */
private $_config = array(); private $_config = array();
/**
* Manual added files.
* Uses key as filename!
*
* @var array
*/
private $_manualFiles = array();
/** /**
* Constructor. * Constructor.
* *
@@ -62,30 +69,30 @@ class FroxlorPkgCreator
*/ */
public function __construct($incListPath, $toPath) public function __construct($incListPath, $toPath)
{ {
$this->_path = $incListPath; $this->_path = $toPath;
// load the config // load the config
$this->_config = $this->_readConfig(); $this->_config = $this->_readConfig($incListPath);
// parse the config // parse the config
if (!$this->_checkConfig()) { if (!$this->_checkConfig()) {
throw new Exception("Error in FroxlorPkgCreator::_checkConfig()"); throw new Exception("Error in FroxlorPkgCreator::_checkConfig()");
} }
$this->pack($toPath);
} }
/** /**
* Loads the config to an array. * Loads the config to an array.
* *
* @param string $path path to inc-list
*
* @return array pathes to files * @return array pathes to files
*/ */
private function _readConfig() private function _readConfig($path)
{ {
$arr = array(); $arr = array();
if (is_readable($this->_path)) { if (is_readable($path)) {
$arr = file($this->_path); $arr = file($path);
} }
return $arr; return $arr;
@@ -116,6 +123,17 @@ class FroxlorPkgCreator
return true; return true;
} }
/**
* Adds a "file".
*
* @param string $name filename (containg path like lib/userdata.inc.php)
* @param string $data data to write
*/
public function addFile($name, $data)
{
$this->_manualFiles[$name] = $data;
}
/** /**
* This functions creates the package. * This functions creates the package.
* *
@@ -123,8 +141,10 @@ class FroxlorPkgCreator
* *
* @return string path * @return string path
*/ */
public function pack($toPath) public function pack()
{ {
$toPath = $this->_path;
$zip = new ZipArchive; $zip = new ZipArchive;
// create archive // create archive
@@ -135,6 +155,11 @@ class FroxlorPkgCreator
$zip->addFile($var, $name); $zip->addFile($var, $name);
} }
// add manual files
foreach ($this->_manualFiles as $key=>$var) {
$zip->addFromString($key, $var);
}
// close it // close it
$zip->close(); $zip->close();