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