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.     *   What dependency option should be used when installing
  76.     *   a package.
  77.     *   One of: onlyreqdeps, alldeps, nodeps or "".
  78.     *   @var string 
  79.     */
  80.     public static $strDepOptions 'onlyreqdeps';
  81.  
  82.     /**
  83.     *   The dependency options for installation, and the
  84.     *   corresponding widget names from the GUI.
  85.     *   @var array 
  86.     */
  87.     protected static $arDepWidgets = array(
  88.         'onlyreqdeps' => 'mnuOptDepsReq',
  89.         'alldeps'     => 'mnuOptDepsAll',
  90.         'nodeps'      => 'mnuOptDepsNo',
  91.         ''            => 'mnuOptDepNothing'
  92.     );
  93.  
  94.  
  95.  
  96.     /**
  97.     *   Load the config file into the variables here.
  98.     *
  99.     *   @return boolean  True if all is ok, false if not
  100.     */
  101.     public static function loadConfig()
  102.     {
  103.         require_once 'Config.php';
  104.         $config = new Config();
  105.         $root   $config->parseConfig(self::getConfigFilePath()'inifile');
  106.  
  107.         if (PEAR::isError($root)) {
  108.             //we have default values if there is no config file yet
  109.             return false;
  110.         }
  111.         $arRoot $root->toArray();
  112.         if (!isset($arRoot['root']['installer']|| !is_array($arRoot['root']['installer'])) {
  113.             return false;
  114.         }
  115.         $arConf array_merge(self::getConfigArray()$arRoot['root']['installer']);
  116.  
  117.         self::$bWorkOffline     = (boolean)$arConf['offline'];
  118.         self::$strDepOptions    = (string) $arConf['depOption'];
  119.  
  120.         self::loadCommandLineArguments();
  121.  
  122.         return true;
  123.     }//public static function loadConfig()
  124.  
  125.  
  126.  
  127.     /**
  128.     *   Loads some command line arguments into the config.
  129.     *   Args are:
  130.     *   * -c channelname        Select channelname
  131.     *   * -O                    Work offline
  132.     *   * -a                    All dependencies
  133.     *   * -o                    Only required dependencies
  134.     *   * -n                    No dependencies
  135.     *   * -v                    Version information
  136.     */
  137.     protected static function loadCommandLineArguments()
  138.     {
  139.         //we can't use argc here because "pear -G" removes
  140.         // the first element
  141.         if (count($GLOBALS['argv']<= 1{
  142.             return;
  143.         }
  144.  
  145.         $nCurrentPos = 1;
  146.         do {
  147.             switch ($GLOBALS['argv'][$nCurrentPos]{
  148.                 case '-c':
  149.                 case '--channel':
  150.                     if ($GLOBALS['argc'$nCurrentPos + 1{
  151.                         self::$strDefaultChannel $GLOBALS['argv'][++$nCurrentPos];
  152.                     }
  153.                     break;
  154.                 case '-p':
  155.                 case '--package':
  156.                     if ($GLOBALS['argc'$nCurrentPos + 1{
  157.                         self::$strDefaultPackage $GLOBALS['argv'][++$nCurrentPos];
  158.                     }
  159.                     break;
  160.                 case '-O':
  161.                     self::$bWorkOffline = true;
  162.                     break;
  163.                 case '-n':
  164.                 case '--nodeps':
  165.                     self::$strDepOptions 'nodeps';
  166.                     break;
  167.                 case '-a':
  168.                 case '--alldeps':
  169.                     self::$strDepOptions 'alldeps';
  170.                     break;
  171.                 case '-o':
  172.                 case '--onlyreqdeps':
  173.                     self::$strDepOptions 'onlyreqdeps';
  174.                     break;
  175.                 case '-v':
  176.                 case '--version':
  177.                     echo "PEAR_Frontend_Gtk2 version 0.1.0\r\n";
  178.                     exit;
  179.                     break;
  180.                 case '-h':
  181.                 case '--help':
  182. echo <<<HELP
  183. pear -G [options]
  184.  
  185. Shows the Gtk2 PEAR Frontend that allows managing
  186. (installing/uninstalling) packages and channels.
  187.  
  188.   -c, --channel channelname
  189.         Show channelname package on startup
  190.   -p, --package [channel/]packagename
  191.         Select the given package on startup
  192.   -n, --nodeps
  193.         ignore dependencies, upgrade anyway
  194.   -a, --alldeps
  195.         install all required and optional dependencies
  196.   -o, --onlyreqdeps
  197.         install all required dependencies
  198.   -O, --offline
  199.         do not attempt to download any urls or contact channels
  200.  
  201.  
  202. HELP;
  203.                     exit;
  204.                     break;
  205.             }
  206.         while (++$nCurrentPos < count($GLOBALS['argv']));
  207.  
  208.         if (self::$strDefaultPackage !== null{
  209.             $arSplit explode('/'self::$strDefaultPackage);
  210.             if (count($arSplit== 2{
  211.                 self::$strDefaultChannel $arSplit[0];
  212.                 self::$strDefaultPackage $arSplit[1];
  213.             }
  214.         }
  215.         if (self::$strDefaultChannel !== null{
  216.             self::$strDefaultChannel =
  217.                 PEAR_Config::singleton()->getRegistry()->_getChannelFromAlias(
  218.                     self::$strDefaultChannel
  219.                 );
  220.         }
  221.     }//protected static function loadCommandLineArguments()
  222.  
  223.  
  224.  
  225.     /**
  226.     *   Save the config in the config file
  227.     */
  228.     public static function saveConfig()
  229.     {
  230.         require_once 'Config.php';
  231.         $conf   = new Config_Container('section''installer');
  232.         $arConf = self::getConfigArray();
  233.         foreach ($arConf as $key => $value{
  234.             $conf->createDirective($key$value);
  235.         }
  236.  
  237.         $config = new Config();
  238.         $config->setRoot($conf);
  239.         $config->writeConfig(self::getConfigFilePath()'inifile');
  240.     }//public static function saveConfig()
  241.  
  242.  
  243.  
  244.     /**
  245.     *   The config array with all current values.
  246.     *   Used for loading and storing
  247.     *
  248.     *   @return array  Arra with all the config options: option name => option value
  249.     */
  250.     public static function getConfigArray()
  251.     {
  252.         return array(
  253.             'offline' => self::$bWorkOffline,
  254.             'depOption' => self::$strDepOptions
  255.         );
  256.     }//public static function getConfigArray()
  257.  
  258.  
  259.  
  260.     /**
  261.     *   The config file path. (Where the config file is/shall be stored)
  262.     *
  263.     *   @return string  The config file path
  264.     */
  265.     protected static function getConfigFilePath()
  266.     {
  267.         return PEAR_Config::singleton()->get('data_dir'. DIRECTORY_SEPARATOR . get_class('.ini';
  268.     }//protected static function getConfigFilePath()
  269.  
  270.  
  271.  
  272.     /**
  273.     *   Loads the current configuration into the GUI.
  274.     *   Sets all the widgets which reflect the config settings
  275.     *   in a way (e.g. the radio menu group for dep options)
  276.     *
  277.     *   @param PEAR_Frontend_Gtk2   $fe     The current frontend to where the config shall be transferred
  278.     */
  279.     public static function loadCurrentConfigIntoGui(PEAR_Frontend_Gtk2 $fe)
  280.     {
  281.         $fe->getWidget('mnuOffline')   ->set_active(self::$bWorkOffline);
  282.         foreach (self::$arDepWidgets as $strValue => $strWidget{
  283.             $fe->getWidget($strWidget)->set_active(self::$strDepOptions == $strValue);
  284.         }
  285.     }//public static function loadConfigIntoGui(PEAR_Frontend_Gtk2 $fe)
  286.  
  287.  
  288.  
  289.     /**
  290.     *   Loads the configuration from the GUI to this config.
  291.     *   This needs to be done before saving the config file.
  292.     *   It checks the widgets responsible for the config options and reads their
  293.     *   settings, saving them intho this config class.
  294.     *
  295.     *   @param PEAR_Frontend_Gtk2   $fe     The current frontend to where the config shall be transferred
  296.     */
  297.     public static function loadConfigurationFromGui(PEAR_Frontend_Gtk2 $fe)
  298.     {
  299.         self::$bWorkOffline $fe->getWidget('mnuOffline')->get_active();
  300.         foreach (self::$arDepWidgets as $strValue => $strWidget{
  301.             if ($fe->getWidget($strWidget)->get_active()) {
  302.                 self::$strDepOptions $strValue;
  303.             }
  304.         }
  305.     }//public static function loadConfigurationFromGui(PEAR_Frontend_Gtk2 $fe)
  306.  
  307. }//class PEAR_Frontend_Gtk2_Config
  308. ?>

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