Implementing the Database class.

* Updated the Database class to work like a Singleton with a getInstance() method.

 * The Database class does not have a private constructor so it can still be instantiated in case someone needs to do so.

 * Replaced Logger class with Log class.

 * Updated Module to have an instance of the Database object as well as the Model class.

 * In my perfect vision for usage, the Module classes should never talk directly to the database, but do so via Models, but I know that's asking a lot, so I'm leaving in some options for folks.

 * Updated documentation.
This commit is contained in:
Josh Sherman 2010-03-16 22:54:21 -04:00
parent 8c1ecea92b
commit cda9c7d28e
43 changed files with 1672 additions and 789 deletions

View file

@ -25,6 +25,19 @@
*/
class Database extends Object
{
/**
* Instance of the Database object
*
* Within the PICKLES system, the database instance is shared, but the
* Database constructor is not private, just in case someone wants to
* create new Database objects.
*
* @static
* @access private
* @var object
*/
private static $instance;
/**
* Hostname for the MySQL Server
*
@ -114,6 +127,25 @@ class Database extends Object
}
}
/**
* Get instance of the object
*
* Instantiates a new object if one isn't already available, then
* returns the instance.
*
* @static
* @return object self::$instance instance of the Database
*/
public static function getInstance()
{
if (!isset(self::$instance) || empty(self::$instance))
{
self::$instance = new Database();
}
return self::$instance;
}
/**
* Opens database connection
*
@ -180,7 +212,7 @@ class Database extends Object
public function execute($sql, $input_parameters = null)
{
$this->open();
Log::query($sql);
// Checks if the query is blank