read() public method

Includes a specified PHP configuration file and incorporates its return value (which should be an associative array) into the current configuration settings.
public read ( string $file ) : Phergie_Config
$file string Path to the file to read
return Phergie_Config Provides a fluent interface
Beispiel #1
0
 /**
  * Returns the entire configuration in use or the value of a specific 
  * configuration setting.
  *
  * @param string $index Optional index of a specific configuration 
  *        setting for which the corresponding value should be returned
  *
  * @return mixed Value corresponding to $index or the entire 
  *         configuration if $index is not specified
  */
 public function getConfig($index = null)
 {
     if (empty($this->config)) {
         $this->config = new Phergie_Config();
         $this->config->read('Settings.php');
     }
     if ($index !== null) {
         return $this->config[$index];
     }
     return $this->config;
 }
Beispiel #2
0
 /**
  * Returns the entire configuration in use or the value of a specific
  * configuration setting.
  *
  * @param string $index   Optional index of a specific configuration
  *        setting for which the corresponding value should be returned
  * @param mixed  $default Value to return if no match is found for $index
  *
  * @return mixed Value corresponding to $index or the entire
  *         configuration if $index is not specified
  */
 public function getConfig($index = null, $default = null)
 {
     if (empty($this->config)) {
         $this->config = new Phergie_Config();
         $this->config->read('Settings.php');
     }
     if ($index !== null) {
         if (isset($this->config[$index])) {
             return $this->config[$index];
         } else {
             return $default;
         }
     }
     return $this->config;
 }
Beispiel #3
0
 /**
  * Tests that the configuration object is able to write setting values
  * back out to multiple files.
  *
  * @return void
  * @depends testImplementsOffsetExists
  * @depends testImplementsOffsetGet
  * @depends testImplementsOffsetSet
  */
 public function testWrite()
 {
     $file1 = $this->createTempFile();
     $file2 = $this->createTempFile();
     file_put_contents($file1, '<?php return array("foo" => "bar");');
     file_put_contents($file2, '<?php return array("baz" => "bay");');
     $this->config->read($file1);
     $this->config->read($file2);
     $this->config['foo'] = 'test1';
     $this->config['baz'] = 'test2';
     $returned = $this->config->write();
     $this->assertSame($returned, $this->config, 'write() does not implement a fluent interface');
     $this->config = new Phergie_Config();
     $this->config->read($file1);
     $this->config->read($file2);
     $this->assertEquals('test1', $this->config['foo']);
     $this->assertEquals('test2', $this->config['baz']);
 }
Beispiel #4
0
 /**
  * Returns the entire configuration in use or the value of a specific
  * configuration setting.
  *
  * @param string $index   Optional index of a specific configuration
  *        setting for which the corresponding value should be returned
  * @param mixed  $default Value to return if no match is found for $index
  *
  * @return mixed Value corresponding to $index or the entire
  *         configuration if $index is not specified
  */
 public function getConfig($index = null, $default = null)
 {
     if (empty($this->config)) {
         $config = $this->getDefaultConfiguration();
         if (false === $config) {
             throw new Exception('Phergie could not locate file Settings.php, ' . 'try "phergie path/to/file/Settings.php"');
         }
         $this->config = new Phergie_Config();
         $this->config->read($config);
     }
     if ($index !== null) {
         if (isset($this->config[$index])) {
             return $this->config[$index];
         } else {
             return $default;
         }
     }
     return $this->config;
 }
Beispiel #5
0
 * @author    Phergie Development Team <*****@*****.**>
 * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
 * @license   http://phergie.org/license New BSD License
 * @link      http://pear.phergie.org/package/Phergie
 */
/**
 * @see Phergie_Autoload
 */
require 'Phergie/Autoload.php';
Phergie_Autoload::registerAutoloader();
$bot = new Phergie_Bot();
if (!isset($argc)) {
    echo 'The PHP setting register_argc_argv must be enabled for Phergie ', 'configuration files to be specified using command line arguments; ', 'defaulting to Settings.php in the current working directory', PHP_EOL;
} else {
    if ($argc > 0) {
        // Skip the current file for manual installations
        // ex: php phergie.php Settings.php
        if (realpath($argv[0]) == __FILE__) {
            array_shift($argv);
        }
        // If configuration files were specified, override default behavior
        if (count($argv) > 0) {
            $config = new Phergie_Config();
            foreach ($argv as $file) {
                $config->read($file);
            }
            $bot->setConfig($config);
        }
    }
}
$bot->run();