PEAR_Frontend_Gtk2
[ class tree: PEAR_Frontend_Gtk2 ] [ index: PEAR_Frontend_Gtk2 ] [ all elements ]

Source for file Config.php

Documentation is available at Config.php

  1. <?php
  2. /**
  3. *   This file contains the configuration options
  4. *   for PEAR_Frontend_Gtk2, beginning with channel
  5. *   colors/images, default channel and more.
  6. *   It can load and write the config from an .ini file,
  7. *   and from and to the GUI.
  8. *
  9. *   @author Christian Weiske <cweiske@php.net>
  10. */
  11. class PEAR_Frontend_Gtk2_Config
  12. {
  13.     /**
  14.     *   Color settings for the different channels.
  15.     *   When a channel is selected from the dropdown,
  16.     *   this array is read and the background color
  17.     *   as well as the text color  of the bar on the right
  18.     *   top is is set according to this settings here.
  19.     *
  20.     *   If there is no entry for a specific channel, the
  21.     *   settings in "default" are used.
  22.     *
  23.     *   @var array 
  24.     */
  25.     public static $arChannels = array(
  26.         'pear.php.net'  => array(
  27.             'background-color'  => '#339900',
  28.             'color'             => '#FFF'
  29.         ),
  30.         'pecl.php.net'  => array(
  31.             'background-color'  => '#2C1D83',
  32.             'color'             => '#FFF'
  33.         ),
  34.         'pear.chiaraquartet.net'  => array(
  35.             'background-color'  => '#333333',
  36.             'color'             => '#FFF'
  37.         ),
  38.         'tradebit.bogo' => array(
  39.             'background-color'  => '#FFF',
  40.             'color'             => '#000'
  41.         ),
  42.         'gnope.org' => array(
  43.             'background-color'  => '#FFF',
  44.             'color'             => '#000'
  45.         ),
  46.         'gnope.bogo' => array(
  47.             'background-color'  => '#FFF',
  48.             'color'             => '#000'
  49.         ),
  50.         'default' => array(
  51.             'background-color'  => '#FFF',
  52.             'color'             => '#000'
  53.         )
  54.     );
  55.  
  56.     /**
  57.     *   The channel which is shown first.
  58.     *   @var string 
  59.     */
  60.     public static $strDefaultChannel 'gnope.org';
  61.  
  62.     /**
  63.     *   The package which is selected first.
  64.     *   @var string 
  65.     */
  66.     public static $strDefaultPackage = null;
  67.  
  68.     /**
  69.     *   Work offline? If yes, then no internet connection is established.
  70.     *   @var boolean 
  71.     */
  72.     public static $bWorkOffline = false;
  73.  
  74.     /**
  75.     *   Force installation?
  76.     *   @var boolean 
  77.     */
  78.     public static $bForceInstall = false;
  79.  
  80.     /**
  81.     *   What dependency option should be used when installing
  82.     *   a package.
  83.     *   One of: onlyreqdeps, alldeps, nodeps or "".
  84.     *   @var string 
  85.     */
  86.     public static $strDepOptions 'onlyreqdeps';
  87.  
  88.     /**
  89.     *   The dependency options for installation, and the
  90.     *   corresponding widget names from the GUI.
  91.     *   @var array 
  92.     */
  93.     protected static $arDepWidgets = array(
  94.         'onlyreqdeps' => 'mnuOptDepsReq',
  95.         'alldeps'     => 'mnuOptDepsAll',
  96.         'nodeps'      => 'mnuOptDepsNo',
  97.         ''            => 'mnuOptDepNothing'
  98.     );
  99.  
  100.  
  101.  
  102.     /**
  103.     *   Load the config file into the variables here.
  104.     *
  105.     *   @return boolean  True if all is ok, false if not
  106.     */
  107.     public static function loadConfig()
  108.     {
  109.         require_once 'Config.php';
  110.         $config = new Config();
  111.         $root   $config->parseConfig(self::getConfigFilePath()'inifile');
  112.  
  113.         if (PEAR::isError($root)) {
  114.             //we have default values if there is no config file yet
  115.             return false;
  116.         }
  117.         $arRoot $root->toArray();
  118.         if (!isset($arRoot['root']['installer']|| !is_array($arRoot['root']['installer'])) {
  119.             return false;
  120.         }
  121.         $arConf array_merge(self::getConfigArray()$arRoot['root']['installer']);
  122.  
  123.         self::$bWorkOffline     = (boolean)$arConf['offline'];
  124.         self::$strDepOptions    = (string) $arConf['depOption'];
  125.         self::$bForceInstall    = (boolean)$arConf['force'];
  126.  
  127.         self::loadCommandLineArguments();
  128.  
  129.         return true;
  130.     }//public static function loadConfig()
  131.  
  132.  
  133.  
  134.     /**
  135.     *   Loads some command line arguments into the config.
  136.     *   Args are:
  137.     *   * -c channelname        Select channelname
  138.     *   * -O                    Work offline
  139.     *   * -a                    All dependencies
  140.     *   * -f                    Force installation
  141.     *   * -o                    Only required dependencies
  142.     *   * -n                    No dependencies
  143.     *   * -v                    Version information
  144.     */
  145.     protected static function loadCommandLineArguments()
  146.     {
  147.         //we can't use argc here because "pear -G" removes
  148.         // the first element
  149.         if (count($GLOBALS['argv']<= 1{
  150.             return;
  151.         }
  152.  
  153.         $nCurrentPos = 1;
  154.         do {
  155.             switch ($GLOBALS['argv'][$nCurrentPos]{
  156.                 case '-c':
  157.                 case '--channel':
  158.                     if ($GLOBALS['argc'$nCurrentPos + 1{
  159.                         self::$strDefaultChannel $GLOBALS['argv'][++$nCurrentPos];
  160.                     }
  161.                     break;
  162.                 case '-f':
  163.                 case '--force':
  164.                     self::$bForceInstall = true;
  165.                     break;
  166.                 case '-p':
  167.                 case '--package':
  168.                     if ($GLOBALS['argc'$nCurrentPos + 1{
  169.                         self::$strDefaultPackage $GLOBALS['argv'][++$nCurrentPos];
  170.                     }
  171.                     break;
  172.                 case '-O':
  173.                     self::$bWorkOffline = true;
  174.                     break;
  175.                 case '-n':
  176.                 case '--nodeps':
  177.                     self::$strDepOptions 'nodeps';
  178.                     break;
  179.                 case '-a':
  180.                 case '--alldeps':
  181.                     self::$strDepOptions 'alldeps';
  182.                     break;
  183.                 case '-o':
  184.                 case '--onlyreqdeps':
  185.                     self::$strDepOptions 'onlyreqdeps';
  186.                     break;
  187.                 case '-v':
  188.                 case '--version':
  189.                     echo "PEAR_Frontend_Gtk2 version @VERSION_PEAR_Frontend_Gtk2@\r\n";
  190.                     exit;
  191.                     break;
  192.                 case '-h':
  193.                 case '--help':
  194. echo <<<HELP
  195. pear -G [options]
  196.  
  197. Shows the Gtk2 PEAR Frontend that allows managing
  198. (installing/uninstalling) packages and channels.
  199.  
  200.   -c, --channel channelname
  201.         Show channelname package on startup
  202.   -p, --package [channel/]packagename
  203.         Select the given package on startup
  204.   -n, --nodeps
  205.         Ignore dependencies, upgrade anyway
  206.   -a, --alldeps
  207.         Install all required and optional dependencies
  208.   -o, --onlyreqdeps
  209.         Install all required dependencies
  210.   -f, --force
  211.         Force installation
  212.   -O, --offline
  213.         Do not attempt to download any urls or contact channels
  214.  
  215.  
  216. HELP;
  217.                     exit;
  218.                     break;
  219.             }
  220.         while (++$nCurrentPos < count($GLOBALS['argv']));
  221.  
  222.         if (self::$strDefaultPackage !== null{
  223.             $arSplit explode('/'self::$strDefaultPackage);
  224.             if (count($arSplit== 2{
  225.                 self::$strDefaultChannel $arSplit[0];
  226.                 self::$strDefaultPackage $arSplit[1];
  227.             }
  228.         }
  229.         if (self::$strDefaultChannel !== null{
  230.             self::$strDefaultChannel =
  231.                 PEAR_Config::singleton()->getRegistry()->_getChannelFromAlias(
  232.                     self::$strDefaultChannel
  233.                 );
  234.         }
  235.     }//protected static function loadCommandLineArguments()
  236.  
  237.  
  238.  
  239.     /**
  240.     *   Save the config in the config file
  241.     */
  242.     public static function saveConfig()
  243.     {
  244.         require_once 'Config.php';
  245.         $conf   = new Config_Container('section''installer');
  246.         $arConf = self::getConfigArray();
  247.         foreach ($arConf as $key => $value{
  248.             $conf->createDirective($key$value);
  249.         }
  250.  
  251.         $config = new Config();
  252.         $config->setRoot($conf);
  253.         $config->writeConfig(self::getConfigFilePath()'inifile');
  254.     }//public static function saveConfig()
  255.  
  256.  
  257.  
  258.     /**
  259.     *   The config array with all current values.
  260.     *   Used for loading and storing
  261.     *
  262.     *   @return array  Arra with all the config options: option name => option value
  263.     */
  264.     public static function getConfigArray()
  265.     {
  266.         return array(
  267.             'offline'   => self::$bWorkOffline,
  268.             'depOption' => self::$strDepOptions,
  269.             'force'     => self::$bForceInstall
  270.         );
  271.     }//public static function getConfigArray()
  272.  
  273.  
  274.  
  275.     /**
  276.     *   The config file path. (Where the config file is/shall be stored)
  277.     *
  278.     *   @return string  The config file path
  279.     */
  280.     protected static function getConfigFilePath()
  281.     {
  282.         return PEAR_Config::singleton()->get('data_dir'. DIRECTORY_SEPARATOR . get_class('.ini';
  283.     }//protected static function getConfigFilePath()
  284.  
  285.  
  286.  
  287.     /**
  288.     *   Loads the current configuration into the GUI.
  289.     *   Sets all the widgets which reflect the config settings
  290.     *   in a way (e.g. the radio menu group for dep options)
  291.     *
  292.     *   @param PEAR_Frontend_Gtk2   $fe     The current frontend to where the config shall be transferred
  293.     */
  294.     public static function loadCurrentConfigIntoGui(PEAR_Frontend_Gtk2 $fe)
  295.     {
  296.         $fe->getWidget('mnuOffline')   ->set_active(self::$bWorkOffline);
  297.         $fe->getWidget('mnuOptForce')  ->set_active(self::$bForceInstall);
  298.         foreach (self::$arDepWidgets as $strValue => $strWidget{
  299.             $fe->getWidget($strWidget)->set_active(self::$strDepOptions == $strValue);
  300.         }
  301.     }//public static function loadConfigIntoGui(PEAR_Frontend_Gtk2 $fe)
  302.  
  303.  
  304.  
  305.     /**
  306.     *   Loads the configuration from the GUI to this config.
  307.     *   This needs to be done before saving the config file.
  308.     *   It checks the widgets responsible for the config options and reads their
  309.     *   settings, saving them intho this config class.
  310.     *
  311.     *   @param PEAR_Frontend_Gtk2   $fe     The current frontend to where the config shall be transferred
  312.     */
  313.     public static function loadConfigurationFromGui(PEAR_Frontend_Gtk2 $fe)
  314.     {
  315.         self::$bWorkOffline  $fe->getWidget('mnuOffline')->get_active();
  316.         self::$bForceInstall $fe->getWidget('mnuOptForce')->get_active();
  317.         foreach (self::$arDepWidgets as $strValue => $strWidget{
  318.             if ($fe->getWidget($strWidget)->get_active()) {
  319.                 self::$strDepOptions $strValue;
  320.             }
  321.         }
  322.     }//public static function loadConfigurationFromGui(PEAR_Frontend_Gtk2 $fe)
  323.  
  324.  
  325.  
  326.     public static function getInstallOptionString()
  327.     {
  328.         $strOpt = self::$strDepOptions;
  329.         if (self::$bForceInstall{
  330.             $strOpt .= ' -f';
  331.         }
  332.  
  333.         return $strOpt;
  334.     }//public static function getInstallOptionString()
  335.  
  336. }//class PEAR_Frontend_Gtk2_Config
  337. ?>

Documentation generated on Mon, 11 Mar 2019 15:46:46 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.