Remove unrelated classes and tests

This commit is contained in:
Timothy Warren 2012-05-31 09:48:17 -04:00
parent 2b0d1c207e
commit 121dfd1401
4 changed files with 0 additions and 439 deletions

View File

@ -1,89 +0,0 @@
<?php
/**
* Query
*
* Free Query Builder / Database Abstraction Layer
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/Query
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* Connection registry
*
* Decouples the Settings class from the query builder
* and organizes database connections
*
* @package Query
* @subpackage Helper Classes
*/
class DB_Reg {
/**
* Static array of connections
*/
private static $instance=array();
/**
* Registry access method
*
* @param string $key
* @return object
*/
public static function &get_db($key)
{
if ( ! isset(self::$instance[$key]))
{
// The constructor sets the instance
new DB_Reg($key);
}
return self::$instance[$key];
}
// --------------------------------------------------------------------------
/**
* Private constructor
*
* @param string $key
*/
private function __construct($key)
{
// Get the db connection parameters for the current database
$db_params = Settings::get_instance()->get_db($key);
// Set the current key in the registry
self::$instance[$key] = new Query_Builder($db_params);
}
// --------------------------------------------------------------------------
/**
* Return exiting connections
*
* @return array
*/
public static function get_connections()
{
return array_keys(self::$instance);
}
// --------------------------------------------------------------------------
/**
* Remove a database connection
*
* @param string $key
* @return void
*/
public static function remove_db($key)
{
unset(self::$instance[$key]);
}
}
// End of dbreg.php

View File

@ -1,258 +0,0 @@
<?php
/**
* Query
*
* Free Query Builder / Database Abstraction Layer
*
* @package Query
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/Query
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* Class for manipulating datbase connections, and miscellaneous settings
*
* @package Query
* @subpackage Helper Classes
*/
class Settings {
/**
* Settings object represented by the currently loaded JSON file
*/
private $current;
/**
* Singleton instance
*/
private static $instance;
/**
* Static method to retreive current instance
* of the singleton
*
* @return Settings
*/
public static function &get_instance()
{
if( ! isset(self::$instance))
{
$name = __CLASS__;
self::$instance = new $name();
}
return self::$instance;
}
/**
* Load the settings file - private so it can't be loaded
* directly - the settings should be safe!
*/
private function __construct()
{
// For testing and use outside of OpenSQLManager,
// define a different SETTINGS_DIR
if ( ! defined('SETTINGS_DIR'))
{
define('SETTINGS_DIR', '.');
}
$path = SETTINGS_DIR.'/settings.json';
if( ! is_file($path))
{
//Create the file!
touch($path);
$this->current = new stdClass();
}
else
{
$this->current = json_decode(file_get_contents($path));
}
// Add the DB object under the settings if it doesn't already exist
if( ! isset($this->current->dbs))
{
$this->current->dbs = new stdClass();
}
}
// --------------------------------------------------------------------------
/**
* Output the settings on destruct
*/
public function __destruct()
{
$file_string = (defined('JSON_PRETTY_PRINT'))
? json_encode($this->current, JSON_PRETTY_PRINT)
: json_encode($this->current);
file_put_contents(SETTINGS_DIR . '/settings.json', $file_string);
}
// --------------------------------------------------------------------------
/**
* Magic method to simplify isset checking for config options
*
* @param string $key
* @return mixed
*/
public function __get($key)
{
return (isset($this->current->{$key}) && $key != "dbs")
? $this->current->{$key}
: NULL;
}
// --------------------------------------------------------------------------
/**
* Magic method to simplify setting config options
*
* @param string $key
* @param mixed
*/
public function __set($key, $val)
{
//Don't allow direct db config changes
if($key == "dbs")
{
return FALSE;
}
return $this->current->{$key} = $val;
}
// --------------------------------------------------------------------------
/**
* Add a database connection
*
* @param string $name
* @param array $params
*/
public function add_db($name, $params)
{
// Return on bad data
if (empty($name) || empty($params))
{
return FALSE;
}
if( ! isset($this->current->dbs->{$name}))
{
$params['name'] = $name;
$this->current->dbs->{$name} = array();
$this->current->dbs->{$name} = $params;
}
else
{
return FALSE;
}
// Save the json
$this->__destruct();
}
// --------------------------------------------------------------------------
/**
* Edit a database connection
*
* @param string $name
* @param array $params
*/
public function edit_db($name, $params)
{
// Return on bad data
if (empty($name) || empty($params))
{
return FALSE;
}
if (isset($this->current->dbs->{$name}) && ($name === $params['name']))
{
$this->current->dbs->{$name} = $params;
}
elseif ($name !== $params['name'])
{
unset($this->current->dbs->{$name});
if ( ! isset($this->current->dbs->{$params['name']}))
{
$this->current->dbs->{$params['name']} = $params;
}
else
{
return FALSE;
}
}
else
{
return FALSE;
}
// Save the json
$this->__destruct();
return TRUE;
}
// --------------------------------------------------------------------------
/**
* Remove a database connection
*
* @param string $name
*/
public function remove_db($name)
{
if( ! isset($this->current->dbs->{$name}))
{
return FALSE;
}
// Remove the db name from the object
unset($this->current->dbs->{$name});
// Save the json
$this->__destruct();
}
// --------------------------------------------------------------------------
/**
* Retreive all db connections
*
* @return array
*/
public function get_dbs()
{
return $this->current->dbs;
}
// --------------------------------------------------------------------------
/**
* Retreive a specific database connection
*
* @param string $name
* @return object
*/
public function get_db($name)
{
return (isset($this->current->dbs->{$name}))
? $this->current->dbs->{$name}
: FALSE;
}
}
// End of settings.php

View File

@ -1,91 +0,0 @@
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* Settings Class Test Class
*/
class SettingsTest extends UnitTestCase {
public function __construct()
{
parent::__construct();
$this->settings =& Settings::get_instance();
// Make sure to delete 'foo' if it exists
$this->settings->remove_db('foo');
}
// --------------------------------------------------------------------------
public function TestExists()
{
$this->assertIsA($this->settings, 'Settings');
}
// --------------------------------------------------------------------------
public function TestGetEmptyDBs()
{
$this->assertTrue(is_object($this->settings->get_dbs()));
}
// --------------------------------------------------------------------------
public function TestGetNull()
{
$this->assertFalse(isset($this->settings->foo));
}
// --------------------------------------------------------------------------
public function TestSet()
{
$bar = $this->settings->foo = 'bar';
$this->assertEqual('bar', $bar);
}
// --------------------------------------------------------------------------
public function TestGet()
{
$this->assertEqual('bar', $this->settings->foo);
}
// --------------------------------------------------------------------------
public function TestSetDBProperty()
{
$res = $this->settings->__set('dbs', 2);
$this->assertFalse($res);
}
// --------------------------------------------------------------------------
public function TestGetEmptyDB()
{
$this->assertFalse($this->settings->get_db('foo'));
}
// --------------------------------------------------------------------------
public function TestAddDB()
{
$this->settings->add_db('foo', array());
$db = $this->settings->get_db('foo');
$this->assertTrue(isset($db));
}
}

View File

@ -29,7 +29,6 @@ require_once(QBASE_DIR . 'autoload.php');
// Require base testing classes
require_once(QTEST_DIR . '/core/core.php');
require_once(QTEST_DIR . '/core/settings.php');
require_once(QTEST_DIR . '/core/db_test.php');
require_once(QTEST_DIR . '/core/db_qb_test.php');