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.     *   Work offline? If yes, then no internet connection is established.
  64.     *   @var boolean 
  65.     */
  66.     public static $bWorkOffline = false;
  67.  
  68.     /**
  69.     *   What dependency option should be used when installing
  70.     *   a package.
  71.     *   One of: onlyreqdeps, alldeps, nodeps or "".
  72.     *   @var string 
  73.     */
  74.     public static $strDepOptions 'onlyreqdeps';
  75.  
  76.     /**
  77.     *   The dependency options for installation, and the
  78.     *   corresponding widget names from the GUI.
  79.     *   @var array 
  80.     */
  81.     protected static $arDepWidgets = array(
  82.         'onlyreqdeps' => 'mnuOptDepsReq',
  83.         'alldeps'     => 'mnuOptDepsAll',
  84.         'nodeps'      => 'mnuOptDepsNo',
  85.         ''            => 'mnuOptDepNothing'
  86.     );
  87.  
  88.  
  89.  
  90.     /**
  91.     *   Load the config file into the variables here.
  92.     *
  93.     *   @return boolean  True if all is ok, false if not
  94.     */
  95.     public static function loadConfig()
  96.     {
  97.         require_once 'Config.php';
  98.         $config = new Config();
  99.         $root   $config->parseConfig(self::getConfigFilePath()'inifile');
  100.  
  101.         if (PEAR::isError($root)) {
  102.             //we have default values if there is no config file yet
  103.             return false;
  104.         }
  105.         $arRoot $root->toArray();
  106.         if (!isset($arRoot['root']['installer']|| !is_array($arRoot['root']['installer'])) {
  107.             return false;
  108.         }
  109.         $arConf array_merge(self::getConfigArray()$arRoot['root']['installer']);
  110.  
  111.         self::$bWorkOffline     = (boolean)$arConf['offline'];
  112.         self::$strDepOptions    = (string) $arConf['depOption'];
  113.  
  114.         return true;
  115.     }//public static function loadConfig()
  116.  
  117.  
  118.  
  119.     /**
  120.     *   Save the config in the config file
  121.     */
  122.     public static function saveConfig()
  123.     {
  124.         require_once 'Config.php';
  125.         $conf   = new Config_Container('section''installer');
  126.         $arConf = self::getConfigArray();
  127.         foreach ($arConf as $key => $value{
  128.             $conf->createDirective($key$value);
  129.         }
  130.  
  131.         $config = new Config();
  132.         $config->setRoot($conf);
  133.         $config->writeConfig(self::getConfigFilePath()'inifile');
  134.     }//public static function saveConfig()
  135.  
  136.  
  137.  
  138.     /**
  139.     *   The config array with all current values.
  140.     *   Used for loading and storing
  141.     *
  142.     *   @return array  Arra with all the config options: option name => option value
  143.     */
  144.     public static function getConfigArray()
  145.     {
  146.         return array(
  147.             'offline' => self::$bWorkOffline,
  148.             'depOption' => self::$strDepOptions
  149.         );
  150.     }//public static function getConfigArray()
  151.  
  152.  
  153.  
  154.     /**
  155.     *   The config file path. (Where the config file is/shall be stored)
  156.     *
  157.     *   @return string  The config file path
  158.     */
  159.     protected static function getConfigFilePath()
  160.     {
  161.         return PEAR_Config::singleton()->get('data_dir'. DIRECTORY_SEPARATOR . get_class('.ini';
  162.     }//protected static function getConfigFilePath()
  163.  
  164.  
  165.  
  166.     /**
  167.     *   Loads the current configuration into the GUI.
  168.     *   Sets all the widgets which reflect the config settings
  169.     *   in a way (e.g. the radio menu group for dep options)
  170.     *
  171.     *   @param PEAR_Frontend_Gtk2   $fe     The current frontend to where the config shall be transferred
  172.     */
  173.     public static function loadCurrentConfigIntoGui(PEAR_Frontend_Gtk2 $fe)
  174.     {
  175.         $fe->getWidget('mnuOffline')   ->set_active(self::$bWorkOffline);
  176.         foreach (self::$arDepWidgets as $strValue => $strWidget{
  177.             $fe->getWidget($strWidget)->set_active(self::$strDepOptions == $strValue);
  178.         }
  179.     }//public static function loadConfigIntoGui(PEAR_Frontend_Gtk2 $fe)
  180.  
  181.  
  182.  
  183.     /**
  184.     *   Loads the configuration from the GUI to this config.
  185.     *   This needs to be done before saving the config file.
  186.     *   It checks the widgets responsible for the config options and reads their
  187.     *   settings, saving them intho this config class.
  188.     *
  189.     *   @param PEAR_Frontend_Gtk2   $fe     The current frontend to where the config shall be transferred
  190.     */
  191.     public static function loadConfigurationFromGui(PEAR_Frontend_Gtk2 $fe)
  192.     {
  193.         self::$bWorkOffline $fe->getWidget('mnuOffline')->get_active();
  194.         foreach (self::$arDepWidgets as $strValue => $strWidget{
  195.             if ($fe->getWidget($strWidget)->get_active()) {
  196.                 self::$strDepOptions $strValue;
  197.             }
  198.         }
  199.     }//public static function loadConfigurationFromGui(PEAR_Frontend_Gtk2 $fe)
  200.  
  201. }//class PEAR_Frontend_Gtk2_Config
  202. ?>

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