Location: PHPKode > projects > ZZ/OSS Installer > zic-1.1.0dev1/installer/lib/ZZOSS_Package/Instant.php
<?php  
    /*
    Copyright (C) 2001-2004 ZZOSS GbR, http://www.zzoss.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */
    
    /**
    @version $Id: Instant.php,v 1.1 2004/04/03 16:14:46 ordnas Exp $
    @copyright Copyright &copy; 2001-2004 ZZ/OSS GbR, http://www.zzoss.com
    @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
    */

require_once 'PEAR.php';
require_once 'ZZOSS_File/Find.php';

/**   
 * This class parses the XML config file and provides the objects of the  
 * XML document.   
 *   
 * Extends PEAR XML_Parser class.   
 *   
 * @version  1   
 * @author   Sandro Zic <hide@address.com>; |    
 */   
   
class ZZOSS_PackageInstant extends PEAR {
    /**
    * The path to the instant tgz.
    */
    var $_instant_tgz = '';
    
    /*
    * Destructor
    */
    function _ZZOSS_PackageInstant()
    {
        // clean up temporary bundle tgz
        if ($this->_instant_tgz != ''){
            @unlink($this->_instant_tgz);
        }
        $this->_PEAR();
    }
    
    function create($instant_name, $installer_dir, $bundles = array())
    {
        // check if bundles have been passed as array
        if(!is_array($bundles)){
            return PEAR::raiseError('Bundles must be provided in a numeric array.');
        }
        
        // check if the installer dir exists
        if(!is_dir($installer_dir)){
            return PEAR::raiseError("'$installer_dir' is not a directory.");
        }
        // check if installer dir is readable
        if(!is_readable($installer_dir.DIRECTORY_SEPARATOR.'.')){
            return PEAR::raiseError("Cannot read '$installer_dir'.");
        }
        
        // reset previous instant tgz
        $this->_instant_tgz = '';
        
        // The temporary instant tgz
        $instant_tgz_tmp = System::tmpdir().DIRECTORY_SEPARATOR.$instant_name.'.tgz';
        
        // Grab all installer files from the various installer directories.
        $filter_dirs = array('CVS', 'bundles');
        // TODO: .bak
        $filter_files = '/[~#]$/i';
        // Create tar file list.
        $zi_filefind = new ZZOSS_FileFind;
        $zi_filefind->setFilterDirs($filter_dirs);
        $zi_filefind->setFilterFiles($filter_files);
        $tar_list = $zi_filefind->listFiles($installer_dir);
        /*
        echo '<pre>';
        print_r($tar_list);
        echo '</pre>';
        */
        
        $tar = new Archive_Tar($instant_tgz_tmp);
        //$tar->setErrorHandling(PEAR_ERROR_PRINT);
        
        $cwd = getcwd();
        chdir($installer_dir);
        $tar->createModify($tar_list, $instant_name.'/installer/');
        chdir($cwd);
        
        // add the bundles to the temporary instant tgz
        if(count($bundles)){
            foreach($bundles as $bundle_tgz){
                if(!file_exists($bundle_tgz)){
                    PEAR::raiseError("The bundle '$bundle_tgz' does not exist.");
                }
                $tar->addModify($bundle_tgz, $instant_name.'/installer/bundles/', dirname($bundle_tgz));
            }
        }
        
        // We use PEAR to clean up the temporary bundle upon shutdown
        // with the destructor.
        // Notice that ZZOSS_Package extends PEAR!
        $this->PEAR();
        
        $this->_instant_tgz = $instant_tgz_tmp;
        
        return $this->_instant_tgz;
    }
}
?>
Return current item: ZZ/OSS Installer