static public function instance($db_type='', $db_params=array(), $force_new_instance=false)
  {
    if(!$db_type)
      $db_type = getIniOption('common.ini', 'type', 'DB');
    elseif(!$db_type)
      $db_type = 'null';

    $db_class_name = self :: _mapTypeToClass($db_type);

    $obj = null;
    if (isset($GLOBALS['global_db_handler']))
      $obj =& $GLOBALS['global_db_handler'];

    if (get_class($obj) != $db_class_name ||  $force_new_instance)
    {
      if(!$db_params &&  $db_type !== 'null')
      {
        $conf = getIni('common.ini');
        $db_params['host'] = $conf->getOption('host', 'DB');
        $db_params['login'] = $conf->getOption('login', 'DB');
        $db_params['password'] = $conf->getOption('password', 'DB');
        $db_params['name'] = $conf->getOption('name', 'DB');
      }

      include_once(LIMB_DIR . '/class/lib/db/' . $db_class_name . '.class.php');

      $obj = new $db_class_name($db_params);

      $GLOBALS['global_db_handler'] = $obj;
    }
    return $obj;
  }
Esempio n. 2
0
 function brain()
 {
     $ini = getIni($this);
     if ($ini->result == 100) {
         $me = 'Jenius';
     } else {
         $me = 'Normal People';
     }
     return $me;
 }
  function testGetConnection()
  {
    $ini =& getIni('common.ini');

    $conf = new MockDbConfig($this);

    $conf->expectCallCount('get', 7);

    $conf->setReturnValue('get', 'test', array('name'));
    $conf->setReturnValue('get', $ini->getOption('driver', 'DB'), array('driver'));
    $conf->setReturnValue('get', $ini->getOption('host', 'DB'), array('host'));
    $conf->setReturnValue('get', $ini->getOption('database', 'DB'), array('database'));
    $conf->setReturnValue('get', $ini->getOption('user', 'DB'), array('user'));
    $conf->setReturnValue('get', $ini->getOption('password', 'DB'), array('password'));

    $pool = new LimbDbPool();

    $conn1 = $pool->getConnection($conf);
    $conn2 = $pool->getConnection($conf);

    $this->assertTrue($conn1 === $conn2);

    $conf->tally();
  }
  public function getINI($ini_path)
  {
    if(isset($this->ini_cache[$ini_path]))
      return $this->ini_cache[$ini_path];

    include_once(LIMB_DIR . '/class/lib/util/ini_support.inc.php');

    $ini = getIni($ini_path);

    $this->ini_cache[$ini_path] = $ini;

    return $ini;
  }
  function testAssignOption()
  {
    registerTestingIni(
      'testing.ini',
      '
        unassigned =
        test = 1

        [test]
        test = 2
      '
    );

    $ini = getIni('testing.ini');

    $this->assertTrue($ini->assignOption($test, 'unassigned'));
    $this->assertEqual($test, '');

    $this->assertTrue($ini->assignOption($test, 'test'));
    $this->assertEqual($test, 1);

    $this->assertTrue($ini->assignOption($test, 'test', 'test'));
    $this->assertEqual($test, 2);
    $this->assertFalse($ini->assignOption($test, 'no_such_option', 'test'));
    $this->assertEqual($test, 2);
  }
  function testGetRulesFromIni()
  {
    $cache_manager = new ImageCacheManager();

    registerTestingIni(
      'image_cache.ini',
      '
      [rule1]
       path_regex = /root/test1
      [rule2]
       path_regex = /root/test2
       groups[] = members
       groups[] = visitors
      [not_valid_rule]
       path_regex = /root/test3
      '
    );

    $this->toolkit->setReturnValue('getINI',
                                   getIni('image_cache.ini'),
                                   array('image_cache.ini'));

    $this->assertEqual($cache_manager->getRules(),
      array(
        array('path_regex' => '/root/test1'),
        array('path_regex' => '/root/test2', 'groups' => array('members', 'visitors'))
      )
    );

    clearTestingIni();
  }
function getIniOption($file_path, $var_name, $group_name = 'default', $use_cache = null)
{
  $ini =& getIni($file_path, $use_cache);
  return $ini->getOption($var_name, $group_name);
}
  function & getINI($ini_path, $resolver_name = 'ini')
  {
    if(isset($this->ini_cache[$ini_path]))
      return $this->ini_cache[$ini_path];

    include_once(LIMB_DIR . '/core/util/ini_support.inc.php');

    $ini = getIni($ini_path, null, $resolver_name);

    $this->ini_cache[$ini_path] = $ini;

    return $ini;
  }