当前位置: 首页>>代码示例>>PHP>>正文


PHP System::mktemp方法代码示例

本文整理汇总了PHP中System::mktemp方法的典型用法代码示例。如果您正苦于以下问题:PHP System::mktemp方法的具体用法?PHP System::mktemp怎么用?PHP System::mktemp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System的用法示例。


在下文中一共展示了System::mktemp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: processInstallation

 function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null)
 {
     $test = parent::processInstallation($pkg, $atts, $file, $tmp_path, $layer);
     if (@file_exists($test[2])) {
         // configuration has already been installed, check for mods
         if (md5_file($test[2]) !== md5_file($test[3])) {
             // configuration has been modified, so save our version as
             // configfile-version
             $old = $test[2];
             $test[2] .= '.new-' . $pkg->getVersion();
             // backup original and re-install it
             PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
             $tmpcfg = $this->config->get('temp_dir');
             $newloc = System::mkdir(array('-p', $tmpcfg));
             if (!$newloc) {
                 // try temp_dir
                 $newloc = System::mktemp(array('-d'));
                 if (!$newloc || PEAR::isError($newloc)) {
                     PEAR::popErrorHandling();
                     return PEAR::raiseError('Could not save existing configuration file ' . $old . ', unable to install.  Please set temp_dir ' . 'configuration variable to a writeable location and try again');
                 }
             } else {
                 $newloc = $tmpcfg;
             }
             if (!@copy($old, $newloc . DIRECTORY_SEPARATOR . 'savefile')) {
                 PEAR::popErrorHandling();
                 return PEAR::raiseError('Could not save existing configuration file ' . $old . ', unable to install.  Please set temp_dir ' . 'configuration variable to a writeable location and try again');
             }
             PEAR::popErrorHandling();
             $this->installer->addFileOperation('rename', array($newloc . DIRECTORY_SEPARATOR . 'savefile', $old, false));
             $this->installer->addFileOperation('delete', array($newloc . DIRECTORY_SEPARATOR . 'savefile'));
         }
     }
     return $test;
 }
开发者ID:arkosoft,项目名称:S-Admin,代码行数:35,代码来源:Cfg.php

示例2: beforeInsert

 function beforeInsert($q, $roo)
 {
     if (isset($q['_remote_upload'])) {
         require_once 'System.php';
         $tmpdir = System::mktemp("-d remote_upload");
         $path = $tmpdir . '/' . basename($q['_remote_upload']);
         if (!file_exists($path)) {
             file_put_contents($path, file_get_contents($q['_remote_upload']));
         }
         $imageInfo = getimagesize($path);
         require_once 'File/MimeType.php';
         $y = new File_MimeType();
         $ext = $y->toExt(trim((string) $imageInfo['mime']));
         if (!preg_match("/\\." . $ext . "\$/", $path, $matches)) {
             rename($path, $path . "." . $ext);
             $path .= "." . $ext;
         }
         if (!$this->createFrom($path)) {
             $roo->jerr("erro making image" . $q['_remote_upload']);
         }
         if (!empty($q['_return_after_create'])) {
             return;
         }
         $roo->addEvent("ADD", $this, $this->toEventString());
         $r = DB_DataObject::factory($this->tableName());
         $r->id = $this->id;
         $roo->loadMap($r);
         $r->limit(1);
         $r->find(true);
         $roo->jok($r->URL(-1, '/Images') . '#attachment-' . $r->id);
     }
 }
开发者ID:roojs,项目名称:Pman.Core,代码行数:32,代码来源:Images.php

示例3: send

    /**
     * Send a bunch of files or directories as an archive
     * 
     * Example:
     * <code>
     *  require_once 'HTTP/Download/Archive.php';
     *  HTTP_Download_Archive::send(
     *      'myArchive.tgz',
     *      '/var/ftp/pub/mike',
     *      HTTP_DOWNLOAD_BZ2,
     *      '',
     *      '/var/ftp/pub'
     *  );
     * </code>
     *
     * @see         Archive_Tar::createModify()
     * @static
     * @access  public
     * @return  mixed   Returns true on success or PEAR_Error on failure.
     * @param   string  $name       name the sent archive should have
     * @param   mixed   $files      files/directories
     * @param   string  $type       archive type
     * @param   string  $add_path   path that should be prepended to the files
     * @param   string  $strip_path path that should be stripped from the files
     */
    function send($name, $files, $type = HTTP_DOWNLOAD_TGZ, $add_path = '', $strip_path = '')
    {
        $tmp = System::mktemp();
        
        switch ($type = strToUpper($type))
        {
            case HTTP_DOWNLOAD_TAR:
                include_once 'Archive/Tar.php';
                $arc = &new Archive_Tar($tmp);
                $content_type = 'x-tar';
            break;

            case HTTP_DOWNLOAD_TGZ:
                include_once 'Archive/Tar.php';
                $arc = &new Archive_Tar($tmp, 'gz');
                $content_type = 'x-gzip';
            break;

            case HTTP_DOWNLOAD_BZ2:
                include_once 'Archive/Tar.php';
                $arc = &new Archive_Tar($tmp, 'bz2');
                $content_type = 'x-bzip2';
            break;

            case HTTP_DOWNLOAD_ZIP:
                include_once 'Archive/Zip.php';
                $arc = &new Archive_Zip($tmp);
                $content_type = 'x-zip';
            break;
            
            default:
                return PEAR::raiseError(
                    'Archive type not supported: ' . $type,
                    HTTP_DOWNLOAD_E_INVALID_ARCHIVE_TYPE
                );
        }
        
        if ($type == HTTP_DOWNLOAD_ZIP) {
            $options = array(   'add_path' => $add_path, 
                                'remove_path' => $strip_path);
            if (!$arc->create($files, $options)) {
                return PEAR::raiseError('Archive creation failed.');
            }
        } else {
            if (!$e = $arc->createModify($files, $add_path, $strip_path)) {
                return PEAR::raiseError('Archive creation failed.');
            }
            if (PEAR::isError($e)) {
                return $e;
            }
        }
        unset($arc);
        
        $dl = &new HTTP_Download(array('file' => $tmp));
        $dl->setContentType('application/' . $content_type);
        $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $name);
        return $dl->send();
    }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:83,代码来源:Archive.php

示例4: post

 function post()
 {
     if (isset($_REQUEST['_convertToPlain'])) {
         require_once 'System.php';
         $tmpdir = System::mktemp("-d convertPlain");
         $path = $tmpdir . '/' . time() . '.html';
         if (isset($_REQUEST['_check_unsubscribe'])) {
             libxml_use_internal_errors(true);
             $doc = new DOMDocument('1.0', 'UTF-8');
             $doc->loadHTML($_REQUEST['bodytext']);
             $xpath = new DOMXpath($doc);
             foreach ($xpath->query('//a[@href]') as $a) {
                 $href = $a->getAttribute('href');
                 if (!preg_match('/^#unsubscribe/', $href)) {
                     continue;
                 }
                 $a->parentNode->replaceChild($doc->createTextNode($a->nodeValue . ' {unsubscribe_link}'), $a);
             }
             $_REQUEST['bodytext'] = $doc->saveHTML();
             libxml_use_internal_errors(false);
         }
         if (!file_exists($path)) {
             file_put_contents($path, $_REQUEST['bodytext']);
         }
         require_once 'File/Convert.php';
         $fc = new File_Convert($path, 'text/html');
         $plain = $fc->convert('text/plain');
         $this->jok(file_get_contents($plain));
     }
     // Import from URL
     if (isset($_REQUEST['importUrl'])) {
         $this->checkHeader($_REQUEST['importUrl']);
         $data = $this->convertStyle($_REQUEST['importUrl'], '', true);
         $this->jok($data);
     }
     // Import from file
     $htmlFile = DB_DataObject::factory('images');
     $htmlFile->setFrom(array('onid' => 0, 'ontable' => 'crm_mailing_list_message'));
     $htmlFile->onUpload(false);
     if ($htmlFile->mimetype != 'text/html') {
         $this->jerr('accept html file only!');
     }
     if (!file_exists($htmlFile->getStoreName())) {
         $this->jerr('update failed!');
     }
     $data = $this->convertStyle('', $htmlFile->getStoreName(), false);
     $htmlFile->delete();
     unlink($htmlFile->getStoreName()) or die('Unable to delete the file');
     $this->jok($data);
 }
开发者ID:roojs,项目名称:Pman.Core,代码行数:50,代码来源:ImportMailMessage.php

示例5: save

 function save($fn)
 {
     require_once __DIR__ . '/../../Document/Word/Writer.php';
     require_once __DIR__ . '/../../System.php';
     $this->tmpdir = System::mktemp("-d abitodocx");
     //$this->tmpdir  = '/tmp';
     $this->link = '';
     $this->style[] = array();
     $this->keepSection = false;
     $this->writer = new Document_Word_Writer();
     // New Word Document
     $this->section = $this->writer->createSection();
     $this->pass = 1;
     $this->parseAbi();
     $this->pass = 2;
     $this->parseAbi();
     $this->saveDocx($fn);
     // uses this->writer...
 }
开发者ID:roojs,项目名称:pear,代码行数:19,代码来源:AbiToDocx.php

示例6: mkTempDir

 /**
  * Create and register a temporary directory.
  *
  * @param string $tmpdir (optional) Directory to use as tmpdir.
  *                       Will use system defaults (for example
  *                       /tmp or c:\windows\temp) if not specified
  *
  * @return string name of created directory
  *
  * @access public
  */
 function mkTempDir($tmpdir = '')
 {
     $topt = $tmpdir ? array('-t', $tmpdir) : array();
     $topt = array_merge($topt, array('-d', 'pear'));
     if (!class_exists('System')) {
         require_once 'System.php';
     }
     if (!($tmpdir = System::mktemp($topt))) {
         return false;
     }
     $this->addTempFile($tmpdir);
     return $tmpdir;
 }
开发者ID:TheSkyNet,项目名称:railoapacheportable,代码行数:24,代码来源:Common.php

示例7: array

<?php

/**
 * Unit tests for HTML_Template_Sigma class
 * 
 * $Id: test.php,v 1.3 2004/04/10 10:28:45 avb Exp $
 */
require_once 'System.php';
$Sigma_cache_dir = System::mktemp('-d sigma');
// What class are we going to test?
// It is possible to also use the unit tests to test HTML_Template_ITX, which
// also implements Integrated Templates API
$IT_class = 'Sigma';
// $IT_class = 'ITX';
// Sigma_cache_testcase is useless if testing HTML_Template_ITX
$testcases = array('Sigma_api_testcase', 'Sigma_cache_testcase', 'Sigma_usage_testcase');
if (@file_exists('../' . $IT_class . '.php')) {
    require_once '../' . $IT_class . '.php';
} else {
    require_once 'HTML/Template/' . $IT_class . '.php';
}
require_once 'PHPUnit.php';
$suite =& new PHPUnit_TestSuite();
foreach ($testcases as $testcase) {
    include_once $testcase . '.php';
    $methods = preg_grep('/^test/i', get_class_methods($testcase));
    foreach ($methods as $method) {
        $suite->addTest(new $testcase($method));
    }
}
require_once './Console_TestListener.php';
开发者ID:GeekyNinja,项目名称:LifesavingCAD,代码行数:31,代码来源:test.php

示例8: doMakeRPM

 function doMakeRPM($command, $options, $params)
 {
     require_once 'System.php';
     require_once 'Archive/Tar.php';
     if (sizeof($params) != 1) {
         return $this->raiseError("bad parameter(s), try \"help {$command}\"");
     }
     if (!file_exists($params[0])) {
         return $this->raiseError("file does not exist: {$params['0']}");
     }
     $reg =& $this->config->getRegistry();
     $pkg =& $this->getPackageFile($this->config, $this->_debug);
     $pf =& $pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
     if (PEAR::isError($pf)) {
         $u = $pf->getUserinfo();
         if (is_array($u)) {
             foreach ($u as $err) {
                 if (is_array($err)) {
                     $err = $err['message'];
                 }
                 $this->ui->outputData($err);
             }
         }
         return $this->raiseError("{$params['0']} is not a valid package");
     }
     $tmpdir = System::mktemp(array('-d', 'pear2rpm'));
     $instroot = System::mktemp(array('-d', 'pear2rpm'));
     $tmp = $this->config->get('verbose');
     $this->config->set('verbose', 0);
     $installer = $this->getInstaller($this->ui);
     require_once 'PEAR/Downloader/Package.php';
     $pack = new PEAR_Downloader_Package($installer);
     $pack->setPackageFile($pf);
     $params[0] =& $pack;
     $installer->setOptions(array('installroot' => $instroot, 'nodeps' => true, 'soft' => true));
     $installer->setDownloadedPackages($params);
     $info = $installer->install($params[0], array('installroot' => $instroot, 'nodeps' => true, 'soft' => true));
     $pkgdir = $pf->getPackage() . '-' . $pf->getVersion();
     $info['rpm_xml_dir'] = '/var/lib/pear';
     $this->config->set('verbose', $tmp);
     if (isset($options['spec-template'])) {
         $spec_template = $options['spec-template'];
     } else {
         $spec_template = '@DATA-DIR@/PEAR/template.spec';
     }
     $info['possible_channel'] = '';
     $info['extra_config'] = '';
     if (isset($options['rpm-pkgname'])) {
         $rpm_pkgname_format = $options['rpm-pkgname'];
     } else {
         if ($pf->getChannel() == 'pear.php.net' || $pf->getChannel() == 'pecl.php.net') {
             $alias = 'PEAR';
         } else {
             $chan =& $reg->getChannel($pf->getChannel());
             $alias = $chan->getAlias();
             $alias = strtoupper($alias);
             $info['possible_channel'] = $pf->getChannel() . '/';
         }
         $rpm_pkgname_format = $alias . '::%s';
     }
     $info['extra_headers'] = '';
     $info['doc_files'] = '';
     $info['files'] = '';
     $info['package2xml'] = '';
     $info['rpm_package'] = sprintf($rpm_pkgname_format, $pf->getPackage());
     $srcfiles = 0;
     foreach ($info['filelist'] as $name => $attr) {
         if (!isset($attr['role'])) {
             continue;
         }
         $name = preg_replace('![/:\\\\]!', '/', $name);
         if ($attr['role'] == 'doc') {
             $info['doc_files'] .= " {$name}";
             // Map role to the rpm vars
         } else {
             $c_prefix = '%{_libdir}/php/pear';
             switch ($attr['role']) {
                 case 'php':
                     $prefix = $c_prefix;
                     break;
                 case 'ext':
                     $prefix = '%{_libdir}/php';
                     break;
                     // XXX good place?
                 // XXX good place?
                 case 'src':
                     $srcfiles++;
                     $prefix = '%{_includedir}/php';
                     break;
                     // XXX good place?
                 // XXX good place?
                 case 'test':
                     $prefix = "{$c_prefix}/tests/" . $pf->getPackage();
                     break;
                 case 'data':
                     $prefix = "{$c_prefix}/data/" . $pf->getPackage();
                     break;
                 case 'script':
                     $prefix = '%{_bindir}';
                     break;
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:rheinaufcms-svn,代码行数:101,代码来源:Package.php

示例9: getDownloadDir

 /**
  * Retrieve the directory that downloads will happen in
  * @access private
  * @return string
  */
 function getDownloadDir()
 {
     if (isset($this->_downloadDir)) {
         return $this->_downloadDir;
     }
     $downloaddir = $this->config->get('download_dir');
     if (empty($downloaddir)) {
         if (!class_exists('System')) {
             require_once 'System.php';
         }
         if (PEAR::isError($downloaddir = System::mktemp('-d'))) {
             return $downloaddir;
         }
         $this->log(3, '+ tmp dir created at ' . $downloaddir);
     }
     return $this->_downloadDir = $downloaddir;
 }
开发者ID:soar-team,项目名称:kloxo,代码行数:22,代码来源:Downloader.php

示例10: _detectGlibcVersion

 function _detectGlibcVersion()
 {
     static $glibc = false;
     if ($glibc !== false) {
         return $glibc;
         // no need to run this multiple times
     }
     $major = $minor = 0;
     include_once "System.php";
     // Use glibc's <features.h> header file to
     // get major and minor version number:
     if (@file_exists('/usr/include/features.h') && @is_readable('/usr/include/features.h')) {
         if (!@file_exists('/usr/bin/cpp') || !@is_executable('/usr/bin/cpp')) {
             $features_file = fopen('/usr/include/features.h', 'rb');
             while (!feof($features_file)) {
                 $line = fgets($features_file, 8192);
                 if (!$line || strpos($line, '#define') === false) {
                     continue;
                 }
                 if (strpos($line, '__GLIBC__')) {
                     // major version number #define __GLIBC__ version
                     $line = preg_split('/\\s+/', $line);
                     $glibc_major = trim($line[2]);
                     if (isset($glibc_minor)) {
                         break;
                     }
                     continue;
                 }
                 if (strpos($line, '__GLIBC_MINOR__')) {
                     // got the minor version number
                     // #define __GLIBC_MINOR__ version
                     $line = preg_split('/\\s+/', $line);
                     $glibc_minor = trim($line[2]);
                     if (isset($glibc_major)) {
                         break;
                     }
                     continue;
                 }
             }
             fclose($features_file);
             if (!isset($glibc_major) || !isset($glibc_minor)) {
                 return $glibc = '';
             }
             return $glibc = 'glibc' . trim($glibc_major) . "." . trim($glibc_minor);
         }
         // no cpp
         $tmpfile = System::mktemp("glibctest");
         $fp = fopen($tmpfile, "w");
         fwrite($fp, "#include <features.h>\n__GLIBC__ __GLIBC_MINOR__\n");
         fclose($fp);
         $cpp = popen("/usr/bin/cpp {$tmpfile}", "r");
         while ($line = fgets($cpp, 1024)) {
             if ($line[0] == '#' || trim($line) == '') {
                 continue;
             }
             if (list($major, $minor) = explode(' ', trim($line))) {
                 break;
             }
         }
         pclose($cpp);
         unlink($tmpfile);
     }
     // features.h
     if (!($major && $minor) && @is_link('/lib/libc.so.6')) {
         // Let's try reading the libc.so.6 symlink
         if (preg_match('/^libc-(.*)\\.so$/', basename(readlink('/lib/libc.so.6')), $matches)) {
             list($major, $minor) = explode('.', $matches[1]);
         }
     }
     if (!($major && $minor)) {
         return $glibc = '';
     }
     return $glibc = "glibc{$major}.{$minor}";
 }
开发者ID:TheSkyNet,项目名称:railoapacheportable,代码行数:74,代码来源:Guess.php

示例11: saveParsedGraph

    /**
     * Saves GraphViz markup to file (in DOT language)
     *
     * @param string $file File to write the GraphViz markup to.
     *
     * @return string File to which the GraphViz markup was written, FALSE or
     *                or PEAR_Error on failure.
     * @access public
     */
    function saveParsedGraph($file = '')
    {
        $parsedGraph = $this->parse();

        if (!empty($parsedGraph)) {
            if (empty($file)) {
                $file = System::mktemp('graph_');
            }

            if ($fp = @fopen($file, 'wb')) {
                @fputs($fp, $parsedGraph);
                @fclose($fp);

                return $file;
            }
        }

        if ($this->_returnFalseOnError) {
            return false;
        }
        $error = PEAR::raiseError('Could not save graph');
        return $error;
    }
开发者ID:namesco,项目名称:Docblox,代码行数:32,代码来源:GraphViz.php

示例12: build

 /**
  * Build an extension from source.  Runs "phpize" in the source
  * directory, but compiles in a temporary directory
  * (TMPDIR/pear-build-USER/PACKAGE-VERSION).
  *
  * @param string|PEAR_PackageFile_v* $descfile path to XML package description file, or
  *               a PEAR_PackageFile object
  *
  * @param mixed $callback callback function used to report output,
  * see PEAR_Builder::_runCommand for details
  *
  * @return array an array of associative arrays with built files,
  * format:
  * array( array( 'file' => '/path/to/ext.so',
  *               'php_api' => YYYYMMDD,
  *               'zend_mod_api' => YYYYMMDD,
  *               'zend_ext_api' => YYYYMMDD ),
  *        ... )
  *
  * @access public
  *
  * @see PEAR_Builder::_runCommand
  */
 function build($descfile, $callback = null)
 {
     if (preg_match('/(\\/|\\\\|^)([^\\/\\\\]+)?php(.+)?$/', $this->config->get('php_bin'), $matches)) {
         if (isset($matches[2]) && strlen($matches[2]) && trim($matches[2]) != trim($this->config->get('php_prefix'))) {
             $this->log(0, 'WARNING: php_bin ' . $this->config->get('php_bin') . ' appears to have a prefix ' . $matches[2] . ', but' . ' config variable php_prefix does not match');
         }
         if (isset($matches[3]) && strlen($matches[3]) && trim($matches[3]) != trim($this->config->get('php_suffix'))) {
             $this->log(0, 'WARNING: php_bin ' . $this->config->get('php_bin') . ' appears to have a suffix ' . $matches[3] . ', but' . ' config variable php_suffix does not match');
         }
     }
     $this->current_callback = $callback;
     if (PEAR_OS == "Windows") {
         return $this->_build_win32($descfile, $callback);
     }
     if (PEAR_OS != 'Unix') {
         return $this->raiseError("building extensions not supported on this platform");
     }
     if (is_object($descfile)) {
         $pkg = $descfile;
         $descfile = $pkg->getPackageFile();
         if (is_a($pkg, 'PEAR_PackageFile_v1')) {
             $dir = dirname($descfile);
         } else {
             $dir = $pkg->_config->get('temp_dir') . '/' . $pkg->getName();
             // automatically delete at session end
             $this->addTempFile($dir);
         }
     } else {
         $pf =& new PEAR_PackageFile($this->config);
         $pkg =& $pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
         if (PEAR::isError($pkg)) {
             return $pkg;
         }
         $dir = dirname($descfile);
     }
     $old_cwd = getcwd();
     if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
         return $this->raiseError("could not chdir to {$dir}");
     }
     $vdir = $pkg->getPackage() . '-' . $pkg->getVersion();
     if (is_dir($vdir)) {
         chdir($vdir);
     }
     $dir = getcwd();
     $this->log(2, "building in {$dir}");
     putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH'));
     $err = $this->_runCommand($this->config->get('php_prefix') . "phpize" . $this->config->get('php_suffix'), array(&$this, 'phpizeCallback'));
     if (PEAR::isError($err)) {
         return $err;
     }
     if (!$err) {
         return $this->raiseError("`phpize' failed");
     }
     // {{{ start of interactive part
     $configure_command = "{$dir}/configure";
     $configure_options = $pkg->getConfigureOptions();
     if ($configure_options) {
         foreach ($configure_options as $o) {
             $default = array_key_exists('default', $o) ? $o['default'] : null;
             list($r) = $this->ui->userDialog('build', array($o['prompt']), array('text'), array($default));
             if (substr($o['name'], 0, 5) == 'with-' && ($r == 'yes' || $r == 'autodetect')) {
                 $configure_command .= " --{$o['name']}";
             } else {
                 $configure_command .= " --{$o['name']}=" . trim($r);
             }
         }
     }
     // }}} end of interactive part
     // FIXME make configurable
     if (!($user = getenv('USER'))) {
         $user = 'defaultuser';
     }
     $tmpdir = $this->config->get('temp_dir');
     $build_basedir = System::mktemp(" -t {$tmpdir} -d pear-build-{$user}");
     $build_dir = "{$build_basedir}/{$vdir}";
     $inst_dir = "{$build_basedir}/install-{$vdir}";
     $this->log(1, "building in {$build_dir}");
//.........这里部分代码省略.........
开发者ID:masayukiando,项目名称:wordpress-event-search,代码行数:101,代码来源:Builder.php

示例13: _downloadFile

 /**
  * @param string filename to download
  * @param string version/state
  * @param string original value passed to command-line
  * @param string|null preferred state (snapshot/devel/alpha/beta/stable)
  *                    Defaults to configuration preferred state
  * @return null|PEAR_Error|string
  * @access private
  */
 function _downloadFile($pkgfile, $version, $origpkgfile, $state = null)
 {
     if (is_null($state)) {
         $state = $this->_preferredState;
     }
     // {{{ check the package filename, and whether it's already installed
     $need_download = false;
     if (preg_match('#^(http|ftp)://#', $pkgfile)) {
         $need_download = true;
     } elseif (!@is_file($pkgfile)) {
         if ($this->validPackageName($pkgfile)) {
             if ($this->_registry->packageExists($pkgfile)) {
                 if (empty($this->_options['upgrade']) && empty($this->_options['force'])) {
                     $errors[] = "{$pkgfile} already installed";
                     return;
                 }
             }
             $pkgfile = $this->getPackageDownloadUrl($pkgfile, $version);
             $need_download = true;
         } else {
             if (strlen($pkgfile)) {
                 $errors[] = "Could not open the package file: {$pkgfile}";
             } else {
                 $errors[] = "No package file given";
             }
             return;
         }
     }
     // }}}
     // {{{ Download package -----------------------------------------------
     if ($need_download) {
         $downloaddir = $this->_config->get('download_dir');
         if (empty($downloaddir)) {
             if (PEAR::isError($downloaddir = System::mktemp('-d'))) {
                 return $downloaddir;
             }
             $this->log(3, '+ tmp dir created at ' . $downloaddir);
         }
         $callback = $this->ui ? array(&$this, '_downloadCallback') : null;
         $this->pushErrorHandling(PEAR_ERROR_RETURN);
         $file = $this->downloadHttp($pkgfile, $this->ui, $downloaddir, $callback);
         $this->popErrorHandling();
         if (PEAR::isError($file)) {
             if ($this->validPackageName($origpkgfile)) {
                 if (!PEAR::isError($info = $this->_remote->call('package.info', $origpkgfile))) {
                     if (!count($info['releases'])) {
                         return $this->raiseError('Package ' . $origpkgfile . ' has no releases');
                     } else {
                         return $this->raiseError('No releases of preferred state "' . $state . '" exist for package ' . $origpkgfile . '.  Use ' . $origpkgfile . '-state to install another' . ' state (like ' . $origpkgfile . '-beta)', PEAR_INSTALLER_ERROR_NO_PREF_STATE);
                     }
                 } else {
                     return $pkgfile;
                 }
             } else {
                 return $this->raiseError($file);
             }
         }
         $pkgfile = $file;
     }
     // }}}
     return $pkgfile;
 }
开发者ID:hendricson,项目名称:couponator,代码行数:71,代码来源:Downloader.php

示例14: package

 function package($pkgfile = null, $compress = true)
 {
     // {{{ validate supplied package.xml file
     if (empty($pkgfile)) {
         $pkgfile = 'package.xml';
     }
     // $this->pkginfo gets populated inside
     $pkginfo = $this->infoFromDescriptionFile($pkgfile);
     if (PEAR::isError($pkginfo)) {
         return $this->raiseError($pkginfo);
     }
     $pkgdir = dirname(realpath($pkgfile));
     $pkgfile = basename($pkgfile);
     $errors = $warnings = array();
     $this->validatePackageInfo($pkginfo, $errors, $warnings, $pkgdir);
     foreach ($warnings as $w) {
         $this->log(1, "Warning: {$w}");
     }
     foreach ($errors as $e) {
         $this->log(0, "Error: {$e}");
     }
     if (sizeof($errors) > 0) {
         return $this->raiseError('Errors in package');
     }
     // }}}
     $pkgver = $pkginfo['package'] . '-' . $pkginfo['version'];
     // {{{ Create the package file list
     $filelist = array();
     $i = 0;
     foreach ($pkginfo['filelist'] as $fname => $atts) {
         $file = $pkgdir . DIRECTORY_SEPARATOR . $fname;
         if (!file_exists($file)) {
             return $this->raiseError("File does not exist: {$fname}");
         } else {
             $filelist[$i++] = $file;
             if (empty($pkginfo['filelist'][$fname]['md5sum'])) {
                 $md5sum = md5_file($file);
                 $pkginfo['filelist'][$fname]['md5sum'] = $md5sum;
             }
             $this->log(2, "Adding file {$fname}");
         }
     }
     // }}}
     // {{{ regenerate package.xml
     $new_xml = $this->xmlFromInfo($pkginfo);
     if (PEAR::isError($new_xml)) {
         return $this->raiseError($new_xml);
     }
     if (!($tmpdir = System::mktemp(array('-d')))) {
         return $this->raiseError("PEAR_Packager: mktemp failed");
     }
     $newpkgfile = $tmpdir . DIRECTORY_SEPARATOR . 'package.xml';
     $np = @fopen($newpkgfile, 'wb');
     if (!$np) {
         return $this->raiseError("PEAR_Packager: unable to rewrite {$pkgfile} as {$newpkgfile}");
     }
     fwrite($np, $new_xml);
     fclose($np);
     // }}}
     // {{{ TAR the Package -------------------------------------------
     $ext = $compress ? '.tgz' : '.tar';
     $dest_package = getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext;
     $tar =& new Archive_Tar($dest_package, $compress);
     $tar->setErrorHandling(PEAR_ERROR_RETURN);
     // XXX Don't print errors
     // ----- Creates with the package.xml file
     $ok = $tar->createModify(array($newpkgfile), '', $tmpdir);
     if (PEAR::isError($ok)) {
         return $this->raiseError($ok);
     } elseif (!$ok) {
         return $this->raiseError('PEAR_Packager: tarball creation failed');
     }
     // ----- Add the content of the package
     if (!$tar->addModify($filelist, $pkgver, $pkgdir)) {
         return $this->raiseError('PEAR_Packager: tarball creation failed');
     }
     $this->log(1, "Package {$dest_package} done");
     if (file_exists("{$pkgdir}/CVS/Root")) {
         $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pkginfo['version']);
         $cvstag = "RELEASE_{$cvsversion}";
         $this->log(1, "Tag the released code with `pear cvstag {$pkgfile}'");
         $this->log(1, "(or set the CVS tag {$cvstag} by hand)");
     }
     // }}}
     return $dest_package;
 }
开发者ID:BackupTheBerlios,项目名称:wcms,代码行数:86,代码来源:Packager.php

示例15: install

 /**
  * Installs the files within the package file specified.
  *
  * @param $pkgfile path to the package file
  *
  * @return array package info if successful, null if not
  */
 function install($pkgfile, $options = array())
 {
     // recognized options:
     // - force         : force installation
     // - register-only : update registry but don't install files
     // - upgrade       : upgrade existing install
     // - soft          : fail silently
     //
     $php_dir = $this->config->get('php_dir');
     if (isset($options['installroot'])) {
         if (substr($options['installroot'], -1) == DIRECTORY_SEPARATOR) {
             $options['installroot'] = substr($options['installroot'], 0, -1);
         }
         $php_dir = $this->_prependPath($php_dir, $options['installroot']);
         $this->registry =& new PEAR_Registry($php_dir);
         $this->installroot = $options['installroot'];
     } else {
         $registry =& $this->registry;
         $this->installroot = '';
     }
     $need_download = false;
     //  ==> XXX should be removed later on
     $flag_old_format = false;
     if (preg_match('#^(http|ftp)://#', $pkgfile)) {
         $need_download = true;
     } elseif (!@is_file($pkgfile)) {
         if ($this->validPackageName($pkgfile)) {
             if ($this->registry->packageExists($pkgfile) && empty($options['upgrade']) && empty($options['force'])) {
                 return $this->raiseError("{$pkgfile} already installed");
             }
             $pkgfile = $this->getPackageDownloadUrl($pkgfile);
             $need_download = true;
         } else {
             if (strlen($pkgfile)) {
                 return $this->raiseError("Could not open the package file: {$pkgfile}");
             } else {
                 return $this->raiseError("No package file given");
             }
         }
     }
     // Download package -----------------------------------------------
     if ($need_download) {
         $downloaddir = $this->config->get('download_dir');
         if (empty($downloaddir)) {
             if (PEAR::isError($downloaddir = System::mktemp('-d'))) {
                 return $downloaddir;
             }
             $this->log(2, '+ tmp dir created at ' . $downloaddir);
         }
         $callback = $this->ui ? array(&$this, '_downloadCallback') : null;
         $file = $this->downloadHttp($pkgfile, $this->ui, $downloaddir, $callback);
         if (PEAR::isError($file)) {
             return $this->raiseError($file);
         }
         $pkgfile = $file;
     }
     if (substr($pkgfile, -4) == '.xml') {
         $descfile = $pkgfile;
     } else {
         // Decompress pack in tmp dir -------------------------------------
         // To allow relative package file names
         $oldcwd = getcwd();
         if (@chdir(dirname($pkgfile))) {
             $pkgfile = getcwd() . DIRECTORY_SEPARATOR . basename($pkgfile);
             chdir($oldcwd);
         }
         if (PEAR::isError($tmpdir = System::mktemp('-d'))) {
             return $tmpdir;
         }
         $this->log(2, '+ tmp dir created at ' . $tmpdir);
         $tar = new Archive_Tar($pkgfile);
         if (!@$tar->extract($tmpdir)) {
             return $this->raiseError("unable to unpack {$pkgfile}");
         }
         // ----- Look for existing package file
         $descfile = $tmpdir . DIRECTORY_SEPARATOR . 'package.xml';
         if (!is_file($descfile)) {
             // ----- Look for old package archive format
             // In this format the package.xml file was inside the
             // Package-n.n directory
             $dp = opendir($tmpdir);
             do {
                 $pkgdir = readdir($dp);
             } while ($pkgdir[0] == '.');
             $descfile = $tmpdir . DIRECTORY_SEPARATOR . $pkgdir . DIRECTORY_SEPARATOR . 'package.xml';
             $flag_old_format = true;
             $this->log(0, "warning : you are using an archive with an old format");
         }
         // <== XXX This part should be removed later on
     }
     if (!is_file($descfile)) {
         return $this->raiseError("no package.xml file after extracting the archive");
     }
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:logicalframe,代码行数:101,代码来源:Installer.php


注:本文中的System::mktemp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。