コード例 #1
0
ファイル: eventMatchingTest.php プロジェクト: erebot/erebot
 public function setUp()
 {
     $sxml = new SimpleXMLElement('<foo/>');
     $this->_mainConfig = $this->getMockBuilder('\\Erebot\\Interfaces\\Config\\Main')->getMock();
     $networkConfig = $this->getMockBuilder('\\Erebot\\Interfaces\\Config\\Network')->setConstructorArgs(array($this->_mainConfig, $sxml))->getMock();
     $serverConfig = $this->getMockBuilder('\\Erebot\\Interfaces\\Config\\Server')->setConstructorArgs(array($networkConfig, $sxml))->getMock();
     $bot = $this->getMockBuilder('\\Erebot\\Interfaces\\Core')->setConstructorArgs(array($this->_mainConfig))->getMock();
     $this->_connection = $this->getMockBuilder('\\Erebot\\Interfaces\\Connection')->setConstructorArgs(array($bot, $serverConfig))->getMock();
     $this->_cb = \Erebot\CallableWrapper::wrap(array($this, 'dummyCallback'));
 }
コード例 #2
0
ファイル: TimerGettersTest.php プロジェクト: erebot/timer
 /**
  * @covers \Erebot\Timer::setRepetition
  * @covers \Erebot\Timer::getRepetition
  */
 public function testRepetition()
 {
     $callback = \Erebot\CallableWrapper::wrap(array($this, 'helper'));
     $args = array('foo', 'bar');
     $timer = new \Erebot\Timer($callback, 42, FALSE, $args);
     $this->assertEquals(1, $timer->getRepetition());
     $timer->setRepetition(TRUE);
     $this->assertEquals(-1, $timer->getRepetition());
     $timer->setRepetition(2);
     $this->assertEquals(2, $timer->getRepetition());
 }
コード例 #3
0
ファイル: TimerTest.php プロジェクト: erebot/timer
 /**
  * Nominal case for timers.
  *
  * We create a timer set to go off twice with a delay of 2.5 seconds.
  * We check that each parameter is correctly set before each run.
  *
  * @covers \Erebot\Timer::reset
  * @covers \Erebot\Timer::getStream
  * @covers \Erebot\Timer::activate
  * @covers \Erebot\Timer::__construct
  * @covers \Erebot\Timer::__destruct
  */
 public function testNominalCase()
 {
     $this->timer = new \Erebot\Timer(\Erebot\CallableWrapper::wrap(array($this, 'helper')), $this->delay, 2, array('foo', 'bar'));
     // Do a first pass : after that,
     // we expect exactly 1 repetition left.
     $this->check();
     $this->assertEquals(1, $this->timer->getRepetition());
     // Do a second pass : after that,
     // we expect exactly 0 repetitions left.
     $this->check();
     $this->assertEquals(0, $this->timer->getRepetition());
     // Trying to reset the timer MUST fail
     // because there are no more repetitions left.
     $this->assertFalse($this->timer->reset());
 }
コード例 #4
0
ファイル: Patches.php プロジェクト: erebot/erebot
 /**
  * Apply a few patches to PHP.
  *
  * \return
  *      This method does not return anything.
  */
 public static function patch()
 {
     set_error_handler(function ($errno, $errstr, $errfile, $errline) {
         if (($errno & error_reporting()) !== $errno) {
             return false;
         }
         throw new \Erebot\ErrorReportingException($errstr, $errno, $errfile, $errline);
     }, E_ALL);
     \Erebot\CallableWrapper::initialize();
     // The name "glob" is already used internally as of PHP 5.3.0.
     // Moreover, the wrapper returns an XML document, hence "xglob".
     if (!in_array("xglob", stream_get_wrappers())) {
         stream_wrapper_register('xglob', '\\Erebot\\XGlobStream', STREAM_IS_URL);
     }
     /* Needed to prevent libxml from trying to magically "fix" URLs
      * included with XInclude as this breaks a lot of things.
      * This requires libxml >= 2.6.20 (which was released in 2005). */
     if (!defined('LIBXML_NOBASEFIX')) {
         define('LIBXML_NOBASEFIX', 1 << 18);
     }
 }
コード例 #5
0
ファイル: Proxy.php プロジェクト: erebot/erebot
 public function parseReal($module, $param, $default = null)
 {
     return $this->parseSomething($module, $param, $default, \Erebot\CallableWrapper::wrap(array($this, 'parseRealHelper')), __FUNCTION__, \Erebot\CallableWrapper::wrap('is_real'));
 }
コード例 #6
0
ファイル: Timer.php プロジェクト: erebot/timer
 public function reset()
 {
     if ($this->repeat > 0) {
         $this->repeat--;
     } elseif (!$this->repeat) {
         return false;
     }
     $this->cleanup();
     if (self::$windowsStrategy == 1) {
         // We create a temporary file to which the subprocess will write to.
         // This makes it possible to wait for the delay to pass by using
         // select() on this file descriptor.
         // Simpler approaches don't work on Windows because the underlying
         // php_select() implementation doesn't seem to support pipes.
         // Note:    this does not work anymore (tested with PHP 5.3.16),
         //          hence the second strategy below (for PHP >= 5.3.0).
         $this->handle = tmpfile();
         $descriptors = $this->handle;
     } elseif (self::$windowsStrategy == 2) {
         // Create a pair of interconnected sockets to implement the timer.
         // Windows' firewall will throw a popup (once),
         // but it's still better than no timers at all!
         $pair = stream_socket_pair(STREAM_PF_INET, STREAM_SOCK_STREAM, 0);
         $descriptors = $pair[0];
         $this->handle = $pair[1];
     } else {
         // On other OSes, we just use a pipe to communicate.
         $descriptors = array('pipe', 'w');
     }
     // Build the command that will be executed by the subprocess.
     $command = self::$binary . ' -n -d detect_unicode=Off ' . '-d display_errors=Off -d display_startup_errors=Off ' . '-r "usleep(' . (int) ($this->delay * 1000000) . '); ' . 'var_dump(42); ' . '// ' . addslashes(\Erebot\CallableWrapper::represent($this->callback)) . '"';
     $this->resource = proc_open($command, array(1 => $descriptors), $pipes, null, null, array('bypass_shell' => true));
     if (self::$windowsStrategy == 1) {
         // Required to remove the "read-ready" flag from the fd.
         // The call will always return false since no data has
         // been written to the temporary file yet.
         fgets($this->handle);
     } elseif (self::$windowsStrategy == 2) {
         // Close the second socket as we have no real use for it.
         fclose($pair[0]);
     } else {
         $this->handle = $pipes[1];
     }
     return true;
 }
コード例 #7
0
ファイル: Base.php プロジェクト: erebot/api
 /**
  * Public method to (re)load a module.
  * This eventually reconfigures the bot.
  *
  * \param Erebot::Interface::Connection $connection
  *      IRC connection associated with this instance.
  *
  * \param int $flags
  *      A bitwise OR of the Erebot::Module::Base::RELOAD_*
  *      constants. Your method should take proper actions
  *      depending on the value of those flags.
  *
  * \note
  *      See the documentation on individual RELOAD_*
  *      constants for a list of possible values.
  */
 public final function reloadModule(\Erebot\Interfaces\Connection $connection, $flags)
 {
     if ($this->connection === null) {
         $flags |= self::RELOAD_INIT;
     } else {
         $flags &= ~self::RELOAD_INIT;
     }
     $this->connection = $connection;
     $serverCfg = $this->connection->getConfig(null);
     $this->mainCfg = $serverCfg->getMainCfg();
     $this->translator = $this->mainCfg->getTranslator(get_called_class());
     $this->reload($flags);
     if ($this instanceof \Erebot\Interfaces\HelpEnabled) {
         $this->registerHelpMethod(\Erebot\CallableWrapper::wrap(array($this, 'getHelp')));
     }
 }