home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / tmp / PEAR-1.7.1 / PEAR / Installer / Role / Common.php < prev    next >
Encoding:
PHP Script  |  2008-02-15  |  6.5 KB  |  180 lines

  1. <?php
  2. /**
  3.  * Base class for all installation roles.
  4.  *
  5.  * PHP versions 4 and 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @category   pear
  14.  * @package    PEAR
  15.  * @author     Greg Beaver <cellog@php.net>
  16.  * @copyright  1997-2006 The PHP Group
  17.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  18.  * @version    CVS: $Id: Common.php,v 1.12 2006/10/19 23:55:32 cellog Exp $
  19.  * @link       http://pear.php.net/package/PEAR
  20.  * @since      File available since Release 1.4.0a1
  21.  */
  22. /**
  23.  * Base class for all installation roles.
  24.  *
  25.  * This class allows extensibility of file roles.  Packages with complex
  26.  * customization can now provide custom file roles along with the possibility of
  27.  * adding configuration values to match.
  28.  * @category   pear
  29.  * @package    PEAR
  30.  * @author     Greg Beaver <cellog@php.net>
  31.  * @copyright  1997-2006 The PHP Group
  32.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  33.  * @version    Release: 1.7.1
  34.  * @link       http://pear.php.net/package/PEAR
  35.  * @since      Class available since Release 1.4.0a1
  36.  */
  37. class PEAR_Installer_Role_Common
  38. {
  39.     /**
  40.      * @var PEAR_Config
  41.      * @access protected
  42.      */
  43.     var $config;
  44.  
  45.     /**
  46.      * @param PEAR_Config
  47.      */
  48.     function PEAR_Installer_Role_Common(&$config)
  49.     {
  50.         $this->config = $config;
  51.     }
  52.  
  53.     /**
  54.      * Retrieve configuration information about a file role from its XML info
  55.      *
  56.      * @param string $role Role Classname, as in "PEAR_Installer_Role_Data"
  57.      * @return array
  58.      */
  59.     function getInfo($role)
  60.     {
  61.         if (empty($GLOBALS['_PEAR_INSTALLER_ROLES'][$role])) {
  62.             return PEAR::raiseError('Unknown Role class: "' . $role . '"');
  63.         }
  64.         return $GLOBALS['_PEAR_INSTALLER_ROLES'][$role];
  65.     }
  66.  
  67.     /**
  68.      * This is called for each file to set up the directories and files
  69.      * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
  70.      * @param array attributes from the <file> tag
  71.      * @param string file name
  72.      * @return array an array consisting of:
  73.      *
  74.      *    1 the original, pre-baseinstalldir installation directory
  75.      *    2 the final installation directory
  76.      *    3 the full path to the final location of the file
  77.      *    4 the location of the pre-installation file
  78.      */
  79.     function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null)
  80.     {
  81.         $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' . 
  82.             ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
  83.         if (PEAR::isError($roleInfo)) {
  84.             return $roleInfo;
  85.         }
  86.         if (!$roleInfo['locationconfig']) {
  87.             return false;
  88.         }
  89.         if ($roleInfo['honorsbaseinstall']) {
  90.             $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'], $layer,
  91.                 $pkg->getChannel());
  92.             if (!empty($atts['baseinstalldir'])) {
  93.                 $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
  94.             }
  95.         } elseif ($roleInfo['unusualbaseinstall']) {
  96.             $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'],
  97.                     $layer, $pkg->getChannel()) . DIRECTORY_SEPARATOR . $pkg->getPackage();
  98.             if (!empty($atts['baseinstalldir'])) {
  99.                 $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
  100.             }
  101.         } else {
  102.             $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'],
  103.                     $layer, $pkg->getChannel()) . DIRECTORY_SEPARATOR . $pkg->getPackage();
  104.         }
  105.         if (dirname($file) != '.' && empty($atts['install-as'])) {
  106.             $dest_dir .= DIRECTORY_SEPARATOR . dirname($file);
  107.         }
  108.         if (empty($atts['install-as'])) {
  109.             $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file);
  110.         } else {
  111.             $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as'];
  112.         }
  113.         $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file;
  114.  
  115.         // Clean up the DIRECTORY_SEPARATOR mess
  116.         $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
  117.         
  118.         list($dest_dir, $dest_file, $orig_file) = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),
  119.                                                     array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR,
  120.                                                           DIRECTORY_SEPARATOR),
  121.                                                     array($dest_dir, $dest_file, $orig_file));
  122.         return array($save_destdir, $dest_dir, $dest_file, $orig_file);
  123.     }
  124.  
  125.     /**
  126.      * Get the name of the configuration variable that specifies the location of this file
  127.      * @return string|false
  128.      */
  129.     function getLocationConfig()
  130.     {
  131.         $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' . 
  132.             ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
  133.         if (PEAR::isError($roleInfo)) {
  134.             return $roleInfo;
  135.         }
  136.         return $roleInfo['locationconfig'];
  137.     }
  138.  
  139.     /**
  140.      * Do any unusual setup here
  141.      * @param PEAR_Installer
  142.      * @param PEAR_PackageFile_v2
  143.      * @param array file attributes
  144.      * @param string file name
  145.      */
  146.     function setup(&$installer, $pkg, $atts, $file)
  147.     {
  148.     }
  149.  
  150.     function isExecutable()
  151.     {
  152.         $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' . 
  153.             ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
  154.         if (PEAR::isError($roleInfo)) {
  155.             return $roleInfo;
  156.         }
  157.         return $roleInfo['executable'];
  158.     }
  159.  
  160.     function isInstallable()
  161.     {
  162.         $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' . 
  163.             ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
  164.         if (PEAR::isError($roleInfo)) {
  165.             return $roleInfo;
  166.         }
  167.         return $roleInfo['installable'];
  168.     }
  169.  
  170.     function isExtension()
  171.     {
  172.         $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' . 
  173.             ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
  174.         if (PEAR::isError($roleInfo)) {
  175.             return $roleInfo;
  176.         }
  177.         return $roleInfo['phpextension'];
  178.     }
  179. }
  180. ?>