PEAR_Config::get PHP Method

get() public method

Returns a configuration value, prioritizing layers as per the layers property.
public get ( $key, $layer = null, $channel = false ) : mixed
return mixed the config value, or NULL if not found
    function get($key, $layer = null, $channel = false)
    {
        if (!isset($this->configuration_info[$key])) {
            return null;
        }
        if ($key == '__channels') {
            return null;
        }
        if ($key == 'default_channel') {
            return $this->getDefaultChannel($layer);
        }
        if (!$channel) {
            $channel = $this->getDefaultChannel();
        } elseif ($channel != 'pear.php.net') {
            $this->_lazyChannelSetup();
        }
        $channel = strtolower($channel);
        $test = in_array($key, $this->_channelConfigInfo) ? $this->_getChannelValue($key, $layer, $channel) : null;
        if ($test !== null) {
            if ($this->_installRoot) {
                if (in_array($this->getGroup($key), array('File Locations', 'File Locations (Advanced)')) && $this->getType($key) == 'directory') {
                    return $this->_prependPath($test, $this->_installRoot);
                }
            }
            return $test;
        }
        if ($layer === null) {
            foreach ($this->layers as $layer) {
                if (isset($this->configuration[$layer][$key])) {
                    $test = $this->configuration[$layer][$key];
                    if ($this->_installRoot) {
                        if (in_array($this->getGroup($key), array('File Locations', 'File Locations (Advanced)')) && $this->getType($key) == 'directory') {
                            return $this->_prependPath($test, $this->_installRoot);
                        }
                    }
                    if ($key == 'preferred_mirror') {
                        $reg =& $this->getRegistry();
                        if (is_object($reg)) {
                            $chan =& $reg->getChannel($channel);
                            if (PEAR::isError($chan)) {
                                return $channel;
                            }
                            if (!$chan->getMirror($test) && $chan->getName() != $test) {
                                return $channel;
                                // mirror does not exist
                            }
                        }
                    }
                    return $test;
                }
            }
        } elseif (isset($this->configuration[$layer][$key])) {
            $test = $this->configuration[$layer][$key];
            if ($this->_installRoot) {
                if (in_array($this->getGroup($key), array('File Locations', 'File Locations (Advanced)')) && $this->getType($key) == 'directory') {
                    return $this->_prependPath($test, $this->_installRoot);
                }
            }
            if ($key == 'preferred_mirror') {
                $reg =& $this->getRegistry();
                if (is_object($reg)) {
                    $chan =& $reg->getChannel($channel);
                    if (PEAR::isError($chan)) {
                        return $channel;
                    }
                    if (!$chan->getMirror($test) && $chan->getName() != $test) {
                        return $channel;
                        // mirror does not exist
                    }
                }
            }
            return $test;
        }
        return null;
    }

Usage Example

Beispiel #1
0
 /**
  * This is called for each file to set up the directories and files
  * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
  * @param array attributes from the <file> tag
  * @param string file name
  * @return array an array consisting of:
  *
  *    1 the original, pre-baseinstalldir installation directory
  *    2 the final installation directory
  *    3 the full path to the final location of the file
  *    4 the location of the pre-installation file
  */
 function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null)
 {
     if (!$this->_setup['locationconfig']) {
         return false;
     }
     if ($this->_setup['honorsbaseinstall']) {
         $dest_dir = $save_destdir = $this->config->get($this->_setup['locationconfig'], $layer, $pkg->getChannel());
         if (!empty($atts['baseinstalldir'])) {
             $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
         }
     } elseif ($this->_setup['unusualbaseinstall']) {
         $dest_dir = $save_destdir = $this->config->get($this->_setup['locationconfig'], null, $pkg->getChannel()) . DIRECTORY_SEPARATOR . $pkg->getPackage();
         if (!empty($atts['baseinstalldir'])) {
             $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
         }
     } else {
         $dest_dir = $save_destdir = $this->config->get($this->_setup['locationconfig'], null, $pkg->getChannel()) . DIRECTORY_SEPARATOR . $pkg->getPackage();
     }
     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'];
     }
     $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file;
     // Clean up the DIRECTORY_SEPARATOR mess
     $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
     list($dest_dir, $dest_file, $orig_file) = preg_replace(array('!\\\\+!', '!/!', "!{$ds2}+!"), array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), array($dest_dir, $dest_file, $orig_file));
     return array($save_destdir, $dest_dir, $dest_file, $orig_file);
 }
All Usage Examples Of PEAR_Config::get