저자: Phergie Development Team (team@phergie.org)
상속: implements ArrayAccess
예제 #1
0
파일: TestCase.php 프로젝트: nickl-/phergie
 /**
  * Returns a mock configuration object.
  *
  * @return Phergie_Config
  */
 protected function getMockConfig()
 {
     if (empty($this->config)) {
         $this->config = $this->getMock('Phergie_Config', array('offsetExists', 'offsetGet'));
         $this->config->expects($this->any())->method('offsetExists')->will($this->returnCallback(array($this, 'configOffsetExists')));
         $this->config->expects($this->any())->method('offsetGet')->will($this->returnCallback(array($this, 'configOffsetGet')));
     }
     return $this->config;
 }
예제 #2
0
파일: Bot.php 프로젝트: Bittarman/phergie
 /**
  * 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;
 }
예제 #3
0
 /**
  * Tests adding plugin paths via configuration.
  *
  * @return void
  */
 public function testAddPluginPathsViaConfiguration()
 {
     $dir = dirname(__FILE__);
     $prefix = 'Phergie_Plugin_';
     $paths = array($dir => $prefix);
     $this->config->expects($this->any())->method('offsetExists')->will($this->returnValue(true));
     $this->config->expects($this->any())->method('offsetGet')->will($this->returnValue($paths));
     // Reinitialize the handler so the configuration change takes effect
     // within the constructor
     $this->handler = new Phergie_Plugin_Handler($this->config, $this->events);
     $this->handler->setAutoload(true);
     $this->handler->getPlugin('Mock');
 }
예제 #4
0
파일: Bot.php 프로젝트: Nom4d3/phergie
 /**
  * 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;
 }
예제 #5
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']);
 }
예제 #6
0
파일: Bot.php 프로젝트: phergie/phergie
 /**
  * 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;
 }
예제 #7
0
 /**
  * Initiate connection
  *
  * @return void
  */
 public function connect()
 {
     if (!$this->conn) {
         $this->conn = new Phergie_StatusnetBot();
         $config = new Phergie_Config();
         $config->readArray(array('connections' => array(array('host' => $this->plugin->host, 'port' => $this->plugin->port, 'username' => $this->plugin->username, 'realname' => $this->plugin->realname, 'nick' => $this->plugin->nick, 'password' => $this->plugin->password, 'transport' => $this->plugin->transporttype, 'encoding' => $this->plugin->encoding)), 'driver' => 'statusnet', 'processor' => 'async', 'processor.options' => array('sec' => 0, 'usec' => 0), 'plugins' => array('Pong', 'NickServ', 'AutoJoin', 'Statusnet'), 'plugins.autoload' => true, 'nickserv.password' => $this->plugin->nickservpassword, 'nickserv.identify_message' => $this->plugin->nickservidentifyregexp, 'autojoin.channels' => $this->plugin->channels, 'statusnet.messagecallback' => array($this, 'handle_irc_message'), 'statusnet.regcallback' => array($this, 'handle_reg_response'), 'statusnet.connectedcallback' => array($this, 'handle_connected'), 'statusnet.unregregexp' => $this->plugin->unregregexp, 'statusnet.regregexp' => $this->plugin->regregexp));
         $this->conn->setConfig($config);
         $this->conn->connect();
         $this->lastPing = time();
         $this->lastMessage = time();
     }
     return $this->conn;
 }
예제 #8
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();