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


PHP PEAR_Installer_Role::factory方法代码示例

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


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

示例1: _installFile2

 /**
  * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
  * @param string filename
  * @param array attributes from <file> tag in package.xml
  * @param string path to install the file in
  * @param array options from command-line
  * @access private
  */
 function _installFile2(&$pkg, $file, $atts, $tmp_path, $options)
 {
     if (!isset($this->_registry)) {
         $this->_registry =& $this->config->getRegistry();
     }
     $channel = $pkg->getChannel();
     // {{{ assemble the destination paths
     if (!in_array($atts['attribs']['role'], PEAR_Installer_Role::getValidRoles($pkg->getPackageType()))) {
         return $this->raiseError('Invalid role `' . $atts['attribs']['role'] . "' for file {$file}");
     }
     $role =& PEAR_Installer_Role::factory($pkg, $atts['attribs']['role'], $this->config);
     $err = $role->setup($this, $pkg, $atts['attribs'], $file);
     if (PEAR::isError($err)) {
         return $err;
     }
     if (!$role->isInstallable()) {
         return;
     }
     $info = $role->processInstallation($pkg, $atts['attribs'], $file, $tmp_path);
     if (PEAR::isError($info)) {
         return $info;
     } else {
         list($save_destdir, $dest_dir, $dest_file, $orig_file) = $info;
     }
     $final_dest_file = $installed_as = $dest_file;
     if (isset($this->_options['packagingroot'])) {
         $final_dest_file = $this->_prependPath($final_dest_file, $this->_options['packagingroot']);
     }
     $dest_dir = dirname($final_dest_file);
     $dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file);
     // }}}
     if (empty($this->_options['register-only'])) {
         if (!@is_dir($dest_dir)) {
             if (!$this->mkDirHier($dest_dir)) {
                 return $this->raiseError("failed to mkdir {$dest_dir}", PEAR_INSTALLER_FAILED);
             }
             $this->log(3, "+ mkdir {$dest_dir}");
         }
     }
     $attribs = $atts['attribs'];
     unset($atts['attribs']);
     // pretty much nothing happens if we are only registering the install
     if (empty($this->_options['register-only'])) {
         if (!count($atts)) {
             // no tasks
             if (!file_exists($orig_file)) {
                 return $this->raiseError("file {$orig_file} does not exist", PEAR_INSTALLER_FAILED);
             }
             if (!@copy($orig_file, $dest_file)) {
                 return $this->raiseError("failed to write {$dest_file}", PEAR_INSTALLER_FAILED);
             }
             $this->log(3, "+ cp {$orig_file} {$dest_file}");
             if (isset($attribs['md5sum'])) {
                 $md5sum = md5_file($dest_file);
             }
         } else {
             // file with tasks
             if (!file_exists($orig_file)) {
                 return $this->raiseError("file {$orig_file} does not exist", PEAR_INSTALLER_FAILED);
             }
             if (function_exists('file_get_contents')) {
                 $contents = file_get_contents($orig_file);
             } else {
                 $fp = fopen($orig_file, "r");
                 $contents = @fread($fp, filesize($orig_file));
                 // filesize can be 0
                 fclose($fp);
             }
             if ($contents === false) {
                 $contents = '';
             }
             if (isset($attribs['md5sum'])) {
                 $md5sum = md5($contents);
             }
             foreach ($atts as $tag => $raw) {
                 $tag = str_replace($pkg->getTasksNs() . ':', '', $tag);
                 $task = "PEAR_Task_{$tag}";
                 $task =& new $task($this->config, $this, PEAR_TASK_INSTALL);
                 if (!$task->isScript()) {
                     // scripts are only handled after installation
                     $task->init($raw, $attribs, $pkg->getLastInstalledVersion());
                     $res = $task->startSession($pkg, $contents, $final_dest_file);
                     if ($res === false) {
                         continue;
                         // skip this file
                     }
                     if (PEAR::isError($res)) {
                         return $res;
                     }
                     $contents = $res;
                     // save changes
                 }
//.........这里部分代码省略.........
开发者ID:zseand,项目名称:kloxo,代码行数:101,代码来源:Installer.php

示例2: _installFile2

 /**
  * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
  * @param string filename
  * @param array attributes from <file> tag in package.xml
  * @param string path to install the file in
  * @param array options from command-line
  * @access private
  */
 function _installFile2(&$pkg, $file, &$real_atts, $tmp_path, $options)
 {
     $atts = $real_atts;
     if (!isset($this->_registry)) {
         $this->_registry =& $this->config->getRegistry();
     }
     $channel = $pkg->getChannel();
     // assemble the destination paths
     $roles = PEAR_Installer_Role::getValidRoles($pkg->getPackageType());
     if (!in_array($atts['attribs']['role'], $roles)) {
         return $this->raiseError('Invalid role `' . $atts['attribs']['role'] . "' for file {$file}");
     }
     $role =& PEAR_Installer_Role::factory($pkg, $atts['attribs']['role'], $this->config);
     $err = $role->setup($this, $pkg, $atts['attribs'], $file);
     if (PEAR::isError($err)) {
         return $err;
     }
     if (!$role->isInstallable()) {
         return;
     }
     $info = $role->processInstallation($pkg, $atts['attribs'], $file, $tmp_path);
     if (PEAR::isError($info)) {
         return $info;
     }
     list($save_destdir, $dest_dir, $dest_file, $orig_file) = $info;
     if (preg_match('~/\\.\\.(/|\\z)|^\\.\\./~', str_replace('\\', '/', $dest_file))) {
         return $this->raiseError("SECURITY ERROR: file {$file} (installed to {$dest_file}) contains parent directory reference ..", PEAR_INSTALLER_FAILED);
     }
     $final_dest_file = $installed_as = $dest_file;
     if (isset($this->_options['packagingroot'])) {
         $final_dest_file = $this->_prependPath($final_dest_file, $this->_options['packagingroot']);
     }
     $dest_dir = dirname($final_dest_file);
     $dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file);
     if (empty($this->_options['register-only'])) {
         if (!file_exists($dest_dir) || !is_dir($dest_dir)) {
             if (!$this->mkDirHier($dest_dir)) {
                 return $this->raiseError("failed to mkdir {$dest_dir}", PEAR_INSTALLER_FAILED);
             }
             $this->log(3, "+ mkdir {$dest_dir}");
         }
     }
     $attribs = $atts['attribs'];
     unset($atts['attribs']);
     // pretty much nothing happens if we are only registering the install
     $htype = 'md5sum';
     if (empty($this->_options['register-only'])) {
         if (!count($atts)) {
             // no tasks
             if (!file_exists($orig_file)) {
                 return $this->raiseError("file {$orig_file} does not exist", PEAR_INSTALLER_FAILED);
             }
             if (!@copy($orig_file, $dest_file)) {
                 return $this->raiseError("failed to write {$dest_file}: {$php_errormsg}", PEAR_INSTALLER_FAILED);
             }
             $this->log(3, "+ cp {$orig_file} {$dest_file}");
             if (isset($attribs['sha1sum'])) {
                 $hash = sha1_file($dest_file);
                 $htype = 'sha1sum';
             } elseif (isset($attribs['md5sum'])) {
                 $hash = md5_file($dest_file);
                 $htype = 'md5sum';
             }
         } else {
             // file with tasks
             if (!file_exists($orig_file)) {
                 return $this->raiseError("file {$orig_file} does not exist", PEAR_INSTALLER_FAILED);
             }
             $contents = file_get_contents($orig_file);
             if ($contents === false) {
                 $contents = '';
             }
             if (isset($attribs['sha1sum'])) {
                 $hash = sha1($contents);
                 $htype = 'sha1sum';
             } elseif (isset($attribs['md5sum'])) {
                 $hash = md5($contents);
                 $htype = 'md5sum';
             }
             foreach ($atts as $tag => $raw) {
                 $tag = str_replace(array($pkg->getTasksNs() . ':', '-'), array('', '_'), $tag);
                 $task = "PEAR_Task_{$tag}";
                 $task =& new $task($this->config, $this, PEAR_TASK_INSTALL);
                 if (!$task->isScript()) {
                     // scripts are only handled after installation
                     $task->init($raw, $attribs, $pkg->getLastInstalledVersion());
                     $res = $task->startSession($pkg, $contents, $final_dest_file);
                     if ($res === false) {
                         continue;
                         // skip this file
                     }
                     if (PEAR::isError($res)) {
//.........这里部分代码省略.........
开发者ID:cheeepsan,项目名称:pear-core,代码行数:101,代码来源:Installer.php

示例3: doFileList

 function doFileList($command, $options, $params)
 {
     if (count($params) !== 1) {
         return $this->raiseError('list-files expects 1 parameter');
     }
     $reg =& $this->config->getRegistry();
     $fp = false;
     if (!is_dir($params[0]) && (file_exists($params[0]) || ($fp = @fopen($params[0], 'r')))) {
         if ($fp) {
             fclose($fp);
         }
         if (!class_exists('PEAR_PackageFile')) {
             require_once 'PEAR/PackageFile.php';
         }
         $pkg =& new PEAR_PackageFile($this->config, $this->_debug);
         PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
         $info =& $pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
         PEAR::staticPopErrorHandling();
         $headings = array('Package File', 'Install Path');
         $installed = false;
     } else {
         PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
         $parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
         PEAR::staticPopErrorHandling();
         if (PEAR::isError($parsed)) {
             return $this->raiseError($parsed);
         }
         $info =& $reg->getPackage($parsed['package'], $parsed['channel']);
         $headings = array('Type', 'Install Path');
         $installed = true;
     }
     if (PEAR::isError($info)) {
         return $this->raiseError($info);
     }
     if ($info === null) {
         return $this->raiseError("`{$params['0']}' not installed");
     }
     $list = $info->getPackagexmlVersion() == '1.0' || $installed ? $info->getFilelist() : $info->getContents();
     if ($installed) {
         $caption = 'Installed Files For ' . $params[0];
     } else {
         $caption = 'Contents of ' . basename($params[0]);
     }
     $data = array('caption' => $caption, 'border' => true, 'headline' => $headings);
     if ($info->getPackagexmlVersion() == '1.0' || $installed) {
         foreach ($list as $file => $att) {
             if ($installed) {
                 if (empty($att['installed_as'])) {
                     continue;
                 }
                 $data['data'][] = array($att['role'], $att['installed_as']);
             } else {
                 if (isset($att['baseinstalldir']) && !in_array($att['role'], array('test', 'data', 'doc'))) {
                     $dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR . $file;
                 } else {
                     $dest = $file;
                 }
                 switch ($att['role']) {
                     case 'test':
                     case 'data':
                     case 'doc':
                         $role = $att['role'];
                         if ($role == 'test') {
                             $role .= 's';
                         }
                         $dest = $this->config->get($role . '_dir') . DIRECTORY_SEPARATOR . $info->getPackage() . DIRECTORY_SEPARATOR . $dest;
                         break;
                     case 'php':
                     default:
                         $dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR . $dest;
                 }
                 $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
                 $dest = preg_replace(array('!\\\\+!', '!/!', "!{$ds2}+!"), array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $dest);
                 $file = preg_replace('!/+!', '/', $file);
                 $data['data'][] = array($file, $dest);
             }
         }
     } else {
         // package.xml 2.0, not installed
         if (!isset($list['dir']['file'][0])) {
             $list['dir']['file'] = array($list['dir']['file']);
         }
         foreach ($list['dir']['file'] as $att) {
             $att = $att['attribs'];
             $file = $att['name'];
             $role =& PEAR_Installer_Role::factory($info, $att['role'], $this->config);
             $role->setup($this, $info, $att, $file);
             if (!$role->isInstallable()) {
                 $dest = '(not installable)';
             } else {
                 $dest = $role->processInstallation($info, $att, $file, '');
                 if (PEAR::isError($dest)) {
                     $dest = '(Unknown role "' . $att['role'] . ')';
                 } else {
                     list(, , $dest) = $dest;
                 }
             }
             $data['data'][] = array($file, $dest);
         }
     }
//.........这里部分代码省略.........
开发者ID:kaz6120,项目名称:Loggix,代码行数:101,代码来源:Registry.php

示例4: ftpInstall

 /**
  * Upload an installed package - does not work with register-only packages!
  * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
  */
 public function ftpInstall($pkg)
 {
     if ($pkg->getPackageType() != 'php') {
         return PEAR::raiseError('Error: can only install PHP scripts remotely,' . ' no PHP extensions can be compiled remotely');
     }
     $ftp =& $this->config->getFTP();
     if (!$ftp) {
         return PEAR::raiseError('FTP client not initialized');
     }
     $this->log(2, 'Connect to FTP server');
     $e = $ftp->init();
     if (PEAR::isError($e)) {
         return $e;
     }
     $pf =& $this->_registry->getPackage($pkg->getPackage(), $pkg->getChannel());
     foreach ($pf->getFilelist() as $file => $atts) {
         if ($pf->getPackagexmlVersion() == '1.0') {
             $channel = 'pear.php.net';
             switch ($atts['role']) {
                 case 'doc':
                 case 'data':
                 case 'test':
                     $dest_dir = $this->config->get($atts['role'] . '_dir', 'ftp', $channel) . DIRECTORY_SEPARATOR . $pf->getPackage();
                     unset($atts['baseinstalldir']);
                     break;
                 case 'ext':
                 case 'php':
                     $dest_dir = $this->config->get($atts['role'] . '_dir', 'ftp', $channel);
                     break;
                 case 'script':
                     $dest_dir = $this->config->get('bin_dir', 'ftp', $channel);
                     break;
                 default:
                     continue 2;
             }
             $save_destdir = $dest_dir;
             if (!empty($atts['baseinstalldir'])) {
                 $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
             }
             if (dirname($file) != '.' && empty($atts['install-as'])) {
                 $dest_dir .= DIRECTORY_SEPARATOR . dirname($file);
             }
             if (empty($atts['install-as'])) {
                 $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file);
             } else {
                 $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as'];
             }
             // Clean up the DIRECTORY_SEPARATOR mess
             $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
             $dest_file = preg_replace(array('!\\+!', '!/!', "!{$ds2}+!"), array('/', '/', '/'), $dest_file);
         } else {
             $role =& PEAR_Installer_Role::factory($pf, $atts['role'], $this->config);
             $role->setup($this, $pf, $atts, $file);
             if (!$role->isInstallable()) {
                 continue;
                 // this shouldn't happen
             }
             list($save_destdir, $dest_dir, $dest_file, $orig_file) = $role->processInstallation($pkg, $atts, $file, $file, 'ftp');
             $dest_file = str_replace(DIRECTORY_SEPARATOR, '/', $dest_file);
         }
         $installedas = $atts['installed_as'];
         $this->log(2, 'Uploading "' . $installedas . '" to "' . $dest_file . '"');
         if (PEAR::isError($e = $ftp->installFile($installedas, $dest_file))) {
             return $e;
         }
     }
     $this->log(2, 'Disconnect from FTP server');
     return $ftp->disconnect();
 }
开发者ID:codercv,项目名称:urbansurprisedev,代码行数:73,代码来源:RemoteInstaller.php


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