Reworked Database stuff to be Datastore stuff
Wanted a generic grouping for all datastores so there's a place for memcached and redis.
This commit is contained in:
parent
df0ef6d959
commit
ebd0018473
12 changed files with 170 additions and 180 deletions
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database Class File for PICKLES
|
* Datastore Class File for PICKLES
|
||||||
*
|
*
|
||||||
* PHP version 5
|
* PHP version 5
|
||||||
*
|
*
|
||||||
|
@ -9,26 +9,24 @@
|
||||||
* Redistribution of these files must retain the above copyright notice.
|
* Redistribution of these files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @author Josh Sherman <pickles@joshtronic.com>
|
* @author Josh Sherman <pickles@joshtronic.com>
|
||||||
* @copyright Copyright 2007-2012, Josh Sherman
|
* @copyright Copyright 2007-2013, Josh Sherman
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html
|
* @license http://www.opensource.org/licenses/mit-license.html
|
||||||
* @package PICKLES
|
* @package PICKLES
|
||||||
* @link https://github.com/joshtronic/pickles
|
* @link https://github.com/joshtronic/pickles
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database Factory
|
* Datastore Factory
|
||||||
*
|
*
|
||||||
* Generic class to simplify connecting to a database. All database objects
|
* Generic class to simplify connecting to a datastore.
|
||||||
* should be created by this class to future proof against any internal changes
|
|
||||||
* to PICKLES.
|
|
||||||
*/
|
*/
|
||||||
class Database extends Object
|
class Datastore extends Object
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* Attempts to get an instance of the passed database type or attempts to
|
* Attempts to get an instance of the passed datastore name or attempts
|
||||||
* use a default specified in the config.
|
* to use a default specified in the config.
|
||||||
*
|
*
|
||||||
* @param string $name optional name of the connection to use
|
* @param string $name optional name of the connection to use
|
||||||
*/
|
*/
|
||||||
|
@ -36,16 +34,17 @@ class Database extends Object
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
return Database::getInstance($name);
|
return Datastore::getInstance($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Instance
|
* Get Instance
|
||||||
*
|
*
|
||||||
* Looks up the datasource using the passed name and gets an instance of
|
* Looks up the datasource using the passed name and gets an instance
|
||||||
* it. Allows for easy sharing of certain classes within the system to
|
* of it. Allows for easy sharing of certain classes within the system
|
||||||
* avoid the extra overhead of creating new objects each time. Also avoids
|
* to avoid the extra overhead of creating new objects each time. Also
|
||||||
* the hassle of passing around variables (yeah I know, very global-ish)
|
* avoids the hassle of passing around variables (yeah I know, very
|
||||||
|
* global-ish, don't just me).
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @param string $name name of the datasource
|
* @param string $name name of the datasource
|
||||||
|
@ -85,7 +84,7 @@ class Database extends Object
|
||||||
|
|
||||||
$datasource['driver'] = strtolower($datasource['driver']);
|
$datasource['driver'] = strtolower($datasource['driver']);
|
||||||
|
|
||||||
if (!isset(self::$instances['Database'][$name]))
|
if (!isset(self::$instances[$name]))
|
||||||
{
|
{
|
||||||
// Checks the driver is legit and scrubs the name
|
// Checks the driver is legit and scrubs the name
|
||||||
switch ($datasource['driver'])
|
switch ($datasource['driver'])
|
||||||
|
@ -99,8 +98,8 @@ class Database extends Object
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instantiates our database class
|
// Instantiates our datastore class
|
||||||
$class = 'Database_' . $class;
|
$class = 'Datastore_' . $class;
|
||||||
$instance = new $class();
|
$instance = new $class();
|
||||||
|
|
||||||
// Sets our database parameters
|
// Sets our database parameters
|
||||||
|
@ -116,11 +115,11 @@ class Database extends Object
|
||||||
// Caches the instance for possible reuse later
|
// Caches the instance for possible reuse later
|
||||||
if (isset($instance))
|
if (isset($instance))
|
||||||
{
|
{
|
||||||
self::$instances['Database'][$name] = $instance;
|
self::$instances[$name] = $instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the instance
|
// Returns the instance
|
||||||
return self::$instances['Database'][$name];
|
return self::$instances[$name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common Database Class File for PICKLES
|
* Common Datastore Class File for PICKLES
|
||||||
*
|
*
|
||||||
* PHP version 5
|
* PHP version 5
|
||||||
*
|
*
|
||||||
|
@ -9,19 +9,19 @@
|
||||||
* Redistribution of these files must retain the above copyright notice.
|
* Redistribution of these files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @author Josh Sherman <pickles@joshtronic.com>
|
* @author Josh Sherman <pickles@joshtronic.com>
|
||||||
* @copyright Copyright 2007-2012, Josh Sherman
|
* @copyright Copyright 2007-2013, Josh Sherman
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html
|
* @license http://www.opensource.org/licenses/mit-license.html
|
||||||
* @package PICKLES
|
* @package PICKLES
|
||||||
* @link https://github.com/joshtronic/pickles
|
* @link https://github.com/joshtronic/pickles
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common Database Abstraction Layer
|
* Common Datastore Abstraction Layer
|
||||||
*
|
*
|
||||||
* Parent class that our database driver classes should be extending. Contains
|
* Parent class that our datastore classes should be extending.
|
||||||
* basic functionality for instantiation and interfacing.
|
* Contains basic functionality for instantiation and interfacing.
|
||||||
*/
|
*/
|
||||||
abstract class Database_Common extends Object
|
abstract class Datastore_Common extends Object
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Driver
|
* Driver
|
||||||
|
@ -66,9 +66,9 @@ abstract class Database_Common extends Object
|
||||||
public $password = null;
|
public $password = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database name for the server
|
* Database name (or number) for the server
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string or integer
|
||||||
*/
|
*/
|
||||||
public $database = null;
|
public $database = null;
|
||||||
|
|
||||||
|
@ -94,30 +94,9 @@ abstract class Database_Common extends Object
|
||||||
public $results = null;
|
public $results = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Open Connection
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
|
|
||||||
// Checks the driver is set and available
|
|
||||||
if ($this->driver == null)
|
|
||||||
{
|
|
||||||
throw new Exception('Driver name is not set');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (extension_loaded($this->driver) == false)
|
|
||||||
{
|
|
||||||
throw new Exception('Driver "' . $this->driver . '" is not loaded');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open Database Connection
|
|
||||||
*
|
*
|
||||||
* Establishes a connection to the MySQL database based on the configuration
|
* Establishes a connection to the datastore based on the configuration
|
||||||
* options that are available in the Config object.
|
* options that are available in the Config object.
|
||||||
*
|
*
|
||||||
* @abstract
|
* @abstract
|
||||||
|
@ -126,7 +105,7 @@ abstract class Database_Common extends Object
|
||||||
abstract public function open();
|
abstract public function open();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close Database Connection
|
* Close Connection
|
||||||
*
|
*
|
||||||
* Sets the connection to null regardless of state.
|
* Sets the connection to null regardless of state.
|
||||||
*
|
*
|
0
classes/Datastore/Memcached.php
Normal file
0
classes/Datastore/Memcached.php
Normal file
|
@ -20,7 +20,7 @@
|
||||||
*
|
*
|
||||||
* Parent class for any of our database classes that use PDO.
|
* Parent class for any of our database classes that use PDO.
|
||||||
*/
|
*/
|
||||||
class Database_PDO_Common extends Database_Common
|
class Datastore_PDO_Common extends Datastore_Common
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* DSN format
|
* DSN format
|
||||||
|
@ -49,6 +49,19 @@ class Database_PDO_Common extends Database_Common
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
|
// Checks the driver is set and available
|
||||||
|
if ($this->driver == null)
|
||||||
|
{
|
||||||
|
throw new Exception('Driver name is not set');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (extension_loaded($this->driver) == false)
|
||||||
|
{
|
||||||
|
throw new Exception('Driver "' . $this->driver . '" is not loaded');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Checks that the prefix is set
|
// Checks that the prefix is set
|
||||||
if ($this->dsn == null)
|
if ($this->dsn == null)
|
||||||
{
|
{
|
||||||
|
@ -68,8 +81,8 @@ class Database_PDO_Common extends Database_Common
|
||||||
/**
|
/**
|
||||||
* Opens database connection
|
* Opens database connection
|
||||||
*
|
*
|
||||||
* Establishes a connection to the database based on the set configuration
|
* Establishes a connection to the database based on the set
|
||||||
* options.
|
* configuration options.
|
||||||
*
|
*
|
||||||
* @return boolean true on success, throws an exception overwise
|
* @return boolean true on success, throws an exception overwise
|
||||||
*/
|
*/
|
||||||
|
@ -125,8 +138,8 @@ class Database_PDO_Common extends Database_Common
|
||||||
/**
|
/**
|
||||||
* Executes an SQL Statement
|
* Executes an SQL Statement
|
||||||
*
|
*
|
||||||
* Executes a standard or prepared query based on passed parameters. All
|
* Executes a standard or prepared query based on passed parameters.
|
||||||
* queries are logged to a file as well as timed and logged in the
|
* All queries are logged to a file as well as timed and logged in the
|
||||||
* execution time is over 1 second.
|
* execution time is over 1 second.
|
||||||
*
|
*
|
||||||
* @param string $sql statement to execute
|
* @param string $sql statement to execute
|
|
@ -9,7 +9,7 @@
|
||||||
* Redistribution of these files must retain the above copyright notice.
|
* Redistribution of these files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @author Josh Sherman <pickles@joshtronic.com>
|
* @author Josh Sherman <pickles@joshtronic.com>
|
||||||
* @copyright Copyright 2007-2012, Josh Sherman
|
* @copyright Copyright 2007-2013, Josh Sherman
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html
|
* @license http://www.opensource.org/licenses/mit-license.html
|
||||||
* @package PICKLES
|
* @package PICKLES
|
||||||
* @link https://github.com/joshtronic/pickles
|
* @link https://github.com/joshtronic/pickles
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
/**
|
/**
|
||||||
* MySQL Database Abstraction Layer
|
* MySQL Database Abstraction Layer
|
||||||
*/
|
*/
|
||||||
class Database_PDO_MySQL extends Database_PDO_Common
|
class Datastore_PDO_MySQL extends Datastore_PDO_Common
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Driver
|
* Driver
|
|
@ -18,7 +18,7 @@
|
||||||
/**
|
/**
|
||||||
* PostgreSQL Database Abstraction Layer
|
* PostgreSQL Database Abstraction Layer
|
||||||
*/
|
*/
|
||||||
class Database_PDO_PostgreSQL extends Database_PDO_Common
|
class Datastore_PDO_PostgreSQL extends Datastore_PDO_Common
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Driver
|
* Driver
|
|
@ -18,7 +18,7 @@
|
||||||
/**
|
/**
|
||||||
* SQLite Database Abstraction Layer
|
* SQLite Database Abstraction Layer
|
||||||
*/
|
*/
|
||||||
class Database_PDO_SQLite extends Database_PDO_Common
|
class Datastore_PDO_SQLite extends Datastore_PDO_Common
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Driver
|
* Driver
|
0
classes/Datastore/Redis.php
Normal file
0
classes/Datastore/Redis.php
Normal file
|
@ -310,7 +310,7 @@ class Model extends Object
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
// Gets an instance of the database and check which it is
|
// Gets an instance of the database and check which it is
|
||||||
$this->db = Database::getInstance();
|
$this->db = Datastore::getInstance();
|
||||||
$this->use_cache = $this->db->cache;
|
$this->use_cache = $this->db->cache;
|
||||||
$this->mysql = ($this->db->driver == 'pdo_mysql');
|
$this->mysql = ($this->db->driver == 'pdo_mysql');
|
||||||
$this->postgresql = ($this->db->driver == 'pdo_pgsql');
|
$this->postgresql = ($this->db->driver == 'pdo_pgsql');
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
* Redistribution of these files must retain the above copyright notice.
|
* Redistribution of these files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @author Josh Sherman <pickles@joshtronic.com>
|
* @author Josh Sherman <pickles@joshtronic.com>
|
||||||
* @copyright Copyright 2007-2012, Josh Sherman
|
* @copyright Copyright 2007-2013, Josh Sherman
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html
|
* @license http://www.opensource.org/licenses/mit-license.html
|
||||||
* @package PICKLES
|
* @package PICKLES
|
||||||
* @link https://github.com/joshtronic/pickles
|
* @link https://github.com/joshtronic/pickles
|
||||||
|
@ -18,12 +18,13 @@
|
||||||
/**
|
/**
|
||||||
* Module Class
|
* Module Class
|
||||||
*
|
*
|
||||||
* This is a parent class that all PICKLES modules should be extending. Each
|
* This is a parent class that all PICKLES modules should be extending.
|
||||||
* module can specify it's own meta data and whether or not a user must be
|
* Each module can specify it's own meta data and whether or not a user
|
||||||
* properly authenticated to view the page. Currently any pages without a
|
* must be properly authenticated to view the page. Currently any pages
|
||||||
* template are treated as pages being requested via AJAX and the return will
|
* without a template are treated as pages being requested via AJAX and the
|
||||||
* be JSON encoded. In the future this may need to be changed out for logic
|
* return will be JSON encoded. In the future this may need to be changed
|
||||||
* that allows the requested module to specify what display type(s) it can use.
|
* out for logic that allows the requested module to specify what display
|
||||||
|
* type(s) it can use.
|
||||||
*/
|
*/
|
||||||
class Module extends Object
|
class Module extends Object
|
||||||
{
|
{
|
||||||
|
@ -126,9 +127,9 @@ class Module extends Object
|
||||||
/**
|
/**
|
||||||
* Hash
|
* Hash
|
||||||
*
|
*
|
||||||
* Whether or not to validate the security hash. Boolean true will indicate
|
* Whether or not to validate the security hash. Boolean true will
|
||||||
* using the name of the module as the hash, a string value will use the
|
* indicate using the name of the module as the hash, a string value
|
||||||
* value instead.
|
* will use the value instead.
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @var string or boolean, null by default
|
* @var string or boolean, null by default
|
||||||
|
@ -149,9 +150,10 @@ class Module extends Object
|
||||||
/**
|
/**
|
||||||
* Default Template
|
* Default Template
|
||||||
*
|
*
|
||||||
* Defaults to null but could be set to any valid template basename. The
|
* Defaults to null but could be set to any valid template basename.
|
||||||
* value is overwritten by the config value if not set by the module. The
|
* The value is overwritten by the config value if not set by the
|
||||||
* display engine determines what the file extension should be.
|
* module. The display engine determines what the file extension should
|
||||||
|
* be.
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @var string, 'index' by default
|
* @var string, 'index' by default
|
||||||
|
@ -163,8 +165,8 @@ class Module extends Object
|
||||||
*
|
*
|
||||||
* Array that is returned to the template in the case of the module not
|
* Array that is returned to the template in the case of the module not
|
||||||
* returning anything itself. This is somewhat of a one way trip as you
|
* returning anything itself. This is somewhat of a one way trip as you
|
||||||
* cannot get the variable unless you reference the return array explicitly
|
* cannot get the variable unless you reference the return array
|
||||||
* $this->return['variable']
|
* explicitly $this->return['variable']
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @var array
|
* @var array
|
||||||
|
@ -175,9 +177,10 @@ class Module extends Object
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* The constructor does nothing by default but can be passed a boolean
|
* The constructor does nothing by default but can be passed a boolean
|
||||||
* variable to tell it to automatically run the __default() method. This is
|
* variable to tell it to automatically run the __default() method.
|
||||||
* typically used when a module is called outside of the scope of the
|
* This is typically used when a module is called outside of the scope
|
||||||
* controller (the registration page calls the login page in this manner.
|
* of the controller (the registration page calls the login page in
|
||||||
|
* this manner).
|
||||||
*
|
*
|
||||||
* @param boolean $autorun optional flag to autorun __default()
|
* @param boolean $autorun optional flag to autorun __default()
|
||||||
*/
|
*/
|
||||||
|
@ -186,7 +189,7 @@ class Module extends Object
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->cache = Cache::getInstance();
|
$this->cache = Cache::getInstance();
|
||||||
$this->db = Database::getInstance();
|
$this->db = Datastore::getInstance();
|
||||||
|
|
||||||
if ($autorun === true)
|
if ($autorun === true)
|
||||||
{
|
{
|
||||||
|
@ -198,10 +201,10 @@ class Module extends Object
|
||||||
* Default "Magic" Method
|
* Default "Magic" Method
|
||||||
*
|
*
|
||||||
* This function is overloaded by the module. The __default() method is
|
* This function is overloaded by the module. The __default() method is
|
||||||
* where you want to place any code that needs to be executed at runtime.
|
* where you want to place any code that needs to be executed at
|
||||||
* The reason the code isn't in the constructor is because the module must
|
* runtime. The reason the code isn't in the constructor is because the
|
||||||
* be instantiated before the code is executed so that the controller
|
* module must be instantiated before the code is executed so that the
|
||||||
* script is aware of the authentication requirements.
|
* controller script is aware of the authentication requirements.
|
||||||
*/
|
*/
|
||||||
public function __default()
|
public function __default()
|
||||||
{
|
{
|
||||||
|
@ -211,9 +214,10 @@ class Module extends Object
|
||||||
/**
|
/**
|
||||||
* Magic Setter Method
|
* Magic Setter Method
|
||||||
*
|
*
|
||||||
* Places the variables that are being modified in the return array that is
|
* Places the variables that are being modified in the return array
|
||||||
* returned if nothing is returned by the module itself. This also prohibits
|
* that is returned if nothing is returned by the module itself. This
|
||||||
* the direct modification of module variables which could cause issues.
|
* also prohibits the direct modification of module variables which
|
||||||
|
* could cause issues.
|
||||||
*
|
*
|
||||||
* @param string $name name of the variable to be set
|
* @param string $name name of the variable to be set
|
||||||
* @param mixed $value value of the variable to be set
|
* @param mixed $value value of the variable to be set
|
||||||
|
@ -226,8 +230,8 @@ class Module extends Object
|
||||||
/**
|
/**
|
||||||
* Magic Getter Method
|
* Magic Getter Method
|
||||||
*
|
*
|
||||||
* Attempts to load the module variable. If it's not set, will attempt to
|
* Attempts to load the module variable. If it's not set, will attempt
|
||||||
* load from the config.
|
* to load from the config.
|
||||||
*
|
*
|
||||||
* @param string $name name of the variable requested
|
* @param string $name name of the variable requested
|
||||||
* @return mixed value of the variable or boolean false
|
* @return mixed value of the variable or boolean false
|
||||||
|
|
|
@ -179,7 +179,7 @@ class Session extends Object
|
||||||
$this->table = $table;
|
$this->table = $table;
|
||||||
|
|
||||||
// Gets a database instance
|
// Gets a database instance
|
||||||
$this->db = Database::getInstance($this->datasource);
|
$this->db = Datastore::getInstance($this->datasource);
|
||||||
|
|
||||||
// Initializes the session
|
// Initializes the session
|
||||||
$this->initialize();
|
$this->initialize();
|
||||||
|
|
175
jar.php
175
jar.php
|
@ -1781,7 +1781,7 @@ class Convert
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common Database Class File for PICKLES
|
* Common Datastore Class File for PICKLES
|
||||||
*
|
*
|
||||||
* PHP version 5
|
* PHP version 5
|
||||||
*
|
*
|
||||||
|
@ -1789,19 +1789,19 @@ class Convert
|
||||||
* Redistribution of these files must retain the above copyright notice.
|
* Redistribution of these files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @author Josh Sherman <pickles@joshtronic.com>
|
* @author Josh Sherman <pickles@joshtronic.com>
|
||||||
* @copyright Copyright 2007-2012, Josh Sherman
|
* @copyright Copyright 2007-2013, Josh Sherman
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html
|
* @license http://www.opensource.org/licenses/mit-license.html
|
||||||
* @package PICKLES
|
* @package PICKLES
|
||||||
* @link https://github.com/joshtronic/pickles
|
* @link https://github.com/joshtronic/pickles
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common Database Abstraction Layer
|
* Common Datastore Abstraction Layer
|
||||||
*
|
*
|
||||||
* Parent class that our database driver classes should be extending. Contains
|
* Parent class that our datastore classes should be extending.
|
||||||
* basic functionality for instantiation and interfacing.
|
* Contains basic functionality for instantiation and interfacing.
|
||||||
*/
|
*/
|
||||||
abstract class Database_Common extends Object
|
abstract class Datastore_Common extends Object
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Driver
|
* Driver
|
||||||
|
@ -1846,9 +1846,9 @@ abstract class Database_Common extends Object
|
||||||
public $password = null;
|
public $password = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database name for the server
|
* Database name (or number) for the server
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string or integer
|
||||||
*/
|
*/
|
||||||
public $database = null;
|
public $database = null;
|
||||||
|
|
||||||
|
@ -1874,30 +1874,9 @@ abstract class Database_Common extends Object
|
||||||
public $results = null;
|
public $results = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Open Connection
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
|
|
||||||
// Checks the driver is set and available
|
|
||||||
if ($this->driver == null)
|
|
||||||
{
|
|
||||||
throw new Exception('Driver name is not set');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (extension_loaded($this->driver) == false)
|
|
||||||
{
|
|
||||||
throw new Exception('Driver "' . $this->driver . '" is not loaded');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open Database Connection
|
|
||||||
*
|
*
|
||||||
* Establishes a connection to the MySQL database based on the configuration
|
* Establishes a connection to the datastore based on the configuration
|
||||||
* options that are available in the Config object.
|
* options that are available in the Config object.
|
||||||
*
|
*
|
||||||
* @abstract
|
* @abstract
|
||||||
|
@ -1906,7 +1885,7 @@ abstract class Database_Common extends Object
|
||||||
abstract public function open();
|
abstract public function open();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close Database Connection
|
* Close Connection
|
||||||
*
|
*
|
||||||
* Sets the connection to null regardless of state.
|
* Sets the connection to null regardless of state.
|
||||||
*
|
*
|
||||||
|
@ -1936,7 +1915,7 @@ abstract class Database_Common extends Object
|
||||||
*
|
*
|
||||||
* Parent class for any of our database classes that use PDO.
|
* Parent class for any of our database classes that use PDO.
|
||||||
*/
|
*/
|
||||||
class Database_PDO_Common extends Database_Common
|
class Datastore_PDO_Common extends Datastore_Common
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* DSN format
|
* DSN format
|
||||||
|
@ -1965,6 +1944,19 @@ class Database_PDO_Common extends Database_Common
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
|
// Checks the driver is set and available
|
||||||
|
if ($this->driver == null)
|
||||||
|
{
|
||||||
|
throw new Exception('Driver name is not set');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (extension_loaded($this->driver) == false)
|
||||||
|
{
|
||||||
|
throw new Exception('Driver "' . $this->driver . '" is not loaded');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Checks that the prefix is set
|
// Checks that the prefix is set
|
||||||
if ($this->dsn == null)
|
if ($this->dsn == null)
|
||||||
{
|
{
|
||||||
|
@ -1984,8 +1976,8 @@ class Database_PDO_Common extends Database_Common
|
||||||
/**
|
/**
|
||||||
* Opens database connection
|
* Opens database connection
|
||||||
*
|
*
|
||||||
* Establishes a connection to the database based on the set configuration
|
* Establishes a connection to the database based on the set
|
||||||
* options.
|
* configuration options.
|
||||||
*
|
*
|
||||||
* @return boolean true on success, throws an exception overwise
|
* @return boolean true on success, throws an exception overwise
|
||||||
*/
|
*/
|
||||||
|
@ -2041,8 +2033,8 @@ class Database_PDO_Common extends Database_Common
|
||||||
/**
|
/**
|
||||||
* Executes an SQL Statement
|
* Executes an SQL Statement
|
||||||
*
|
*
|
||||||
* Executes a standard or prepared query based on passed parameters. All
|
* Executes a standard or prepared query based on passed parameters.
|
||||||
* queries are logged to a file as well as timed and logged in the
|
* All queries are logged to a file as well as timed and logged in the
|
||||||
* execution time is over 1 second.
|
* execution time is over 1 second.
|
||||||
*
|
*
|
||||||
* @param string $sql statement to execute
|
* @param string $sql statement to execute
|
||||||
|
@ -2191,7 +2183,7 @@ class Database_PDO_Common extends Database_Common
|
||||||
* Redistribution of these files must retain the above copyright notice.
|
* Redistribution of these files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @author Josh Sherman <pickles@joshtronic.com>
|
* @author Josh Sherman <pickles@joshtronic.com>
|
||||||
* @copyright Copyright 2007-2012, Josh Sherman
|
* @copyright Copyright 2007-2013, Josh Sherman
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html
|
* @license http://www.opensource.org/licenses/mit-license.html
|
||||||
* @package PICKLES
|
* @package PICKLES
|
||||||
* @link https://github.com/joshtronic/pickles
|
* @link https://github.com/joshtronic/pickles
|
||||||
|
@ -2200,7 +2192,7 @@ class Database_PDO_Common extends Database_Common
|
||||||
/**
|
/**
|
||||||
* MySQL Database Abstraction Layer
|
* MySQL Database Abstraction Layer
|
||||||
*/
|
*/
|
||||||
class Database_PDO_MySQL extends Database_PDO_Common
|
class Datastore_PDO_MySQL extends Datastore_PDO_Common
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Driver
|
* Driver
|
||||||
|
@ -2242,7 +2234,7 @@ class Database_PDO_MySQL extends Database_PDO_Common
|
||||||
/**
|
/**
|
||||||
* PostgreSQL Database Abstraction Layer
|
* PostgreSQL Database Abstraction Layer
|
||||||
*/
|
*/
|
||||||
class Database_PDO_PostgreSQL extends Database_PDO_Common
|
class Datastore_PDO_PostgreSQL extends Datastore_PDO_Common
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Driver
|
* Driver
|
||||||
|
@ -2284,7 +2276,7 @@ class Database_PDO_PostgreSQL extends Database_PDO_Common
|
||||||
/**
|
/**
|
||||||
* SQLite Database Abstraction Layer
|
* SQLite Database Abstraction Layer
|
||||||
*/
|
*/
|
||||||
class Database_PDO_SQLite extends Database_PDO_Common
|
class Datastore_PDO_SQLite extends Datastore_PDO_Common
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Driver
|
* Driver
|
||||||
|
@ -2302,7 +2294,7 @@ class Database_PDO_SQLite extends Database_PDO_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database Class File for PICKLES
|
* Datastore Class File for PICKLES
|
||||||
*
|
*
|
||||||
* PHP version 5
|
* PHP version 5
|
||||||
*
|
*
|
||||||
|
@ -2310,26 +2302,24 @@ class Database_PDO_SQLite extends Database_PDO_Common
|
||||||
* Redistribution of these files must retain the above copyright notice.
|
* Redistribution of these files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @author Josh Sherman <pickles@joshtronic.com>
|
* @author Josh Sherman <pickles@joshtronic.com>
|
||||||
* @copyright Copyright 2007-2012, Josh Sherman
|
* @copyright Copyright 2007-2013, Josh Sherman
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html
|
* @license http://www.opensource.org/licenses/mit-license.html
|
||||||
* @package PICKLES
|
* @package PICKLES
|
||||||
* @link https://github.com/joshtronic/pickles
|
* @link https://github.com/joshtronic/pickles
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database Factory
|
* Datastore Factory
|
||||||
*
|
*
|
||||||
* Generic class to simplify connecting to a database. All database objects
|
* Generic class to simplify connecting to a datastore.
|
||||||
* should be created by this class to future proof against any internal changes
|
|
||||||
* to PICKLES.
|
|
||||||
*/
|
*/
|
||||||
class Database extends Object
|
class Datastore extends Object
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* Attempts to get an instance of the passed database type or attempts to
|
* Attempts to get an instance of the passed datastore name or attempts
|
||||||
* use a default specified in the config.
|
* to use a default specified in the config.
|
||||||
*
|
*
|
||||||
* @param string $name optional name of the connection to use
|
* @param string $name optional name of the connection to use
|
||||||
*/
|
*/
|
||||||
|
@ -2337,16 +2327,17 @@ class Database extends Object
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
return Database::getInstance($name);
|
return Datastore::getInstance($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Instance
|
* Get Instance
|
||||||
*
|
*
|
||||||
* Looks up the datasource using the passed name and gets an instance of
|
* Looks up the datasource using the passed name and gets an instance
|
||||||
* it. Allows for easy sharing of certain classes within the system to
|
* of it. Allows for easy sharing of certain classes within the system
|
||||||
* avoid the extra overhead of creating new objects each time. Also avoids
|
* to avoid the extra overhead of creating new objects each time. Also
|
||||||
* the hassle of passing around variables (yeah I know, very global-ish)
|
* avoids the hassle of passing around variables (yeah I know, very
|
||||||
|
* global-ish, don't just me).
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @param string $name name of the datasource
|
* @param string $name name of the datasource
|
||||||
|
@ -2386,7 +2377,7 @@ class Database extends Object
|
||||||
|
|
||||||
$datasource['driver'] = strtolower($datasource['driver']);
|
$datasource['driver'] = strtolower($datasource['driver']);
|
||||||
|
|
||||||
if (!isset(self::$instances['Database'][$name]))
|
if (!isset(self::$instances[$name]))
|
||||||
{
|
{
|
||||||
// Checks the driver is legit and scrubs the name
|
// Checks the driver is legit and scrubs the name
|
||||||
switch ($datasource['driver'])
|
switch ($datasource['driver'])
|
||||||
|
@ -2400,8 +2391,8 @@ class Database extends Object
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instantiates our database class
|
// Instantiates our datastore class
|
||||||
$class = 'Database_' . $class;
|
$class = 'Datastore_' . $class;
|
||||||
$instance = new $class();
|
$instance = new $class();
|
||||||
|
|
||||||
// Sets our database parameters
|
// Sets our database parameters
|
||||||
|
@ -2417,11 +2408,11 @@ class Database extends Object
|
||||||
// Caches the instance for possible reuse later
|
// Caches the instance for possible reuse later
|
||||||
if (isset($instance))
|
if (isset($instance))
|
||||||
{
|
{
|
||||||
self::$instances['Database'][$name] = $instance;
|
self::$instances[$name] = $instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the instance
|
// Returns the instance
|
||||||
return self::$instances['Database'][$name];
|
return self::$instances[$name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4885,7 +4876,7 @@ class Model extends Object
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
// Gets an instance of the database and check which it is
|
// Gets an instance of the database and check which it is
|
||||||
$this->db = Database::getInstance();
|
$this->db = Datastore::getInstance();
|
||||||
$this->use_cache = $this->db->cache;
|
$this->use_cache = $this->db->cache;
|
||||||
$this->mysql = ($this->db->driver == 'pdo_mysql');
|
$this->mysql = ($this->db->driver == 'pdo_mysql');
|
||||||
$this->postgresql = ($this->db->driver == 'pdo_pgsql');
|
$this->postgresql = ($this->db->driver == 'pdo_pgsql');
|
||||||
|
@ -6104,7 +6095,7 @@ class Model extends Object
|
||||||
* Redistribution of these files must retain the above copyright notice.
|
* Redistribution of these files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @author Josh Sherman <pickles@joshtronic.com>
|
* @author Josh Sherman <pickles@joshtronic.com>
|
||||||
* @copyright Copyright 2007-2012, Josh Sherman
|
* @copyright Copyright 2007-2013, Josh Sherman
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html
|
* @license http://www.opensource.org/licenses/mit-license.html
|
||||||
* @package PICKLES
|
* @package PICKLES
|
||||||
* @link https://github.com/joshtronic/pickles
|
* @link https://github.com/joshtronic/pickles
|
||||||
|
@ -6113,12 +6104,13 @@ class Model extends Object
|
||||||
/**
|
/**
|
||||||
* Module Class
|
* Module Class
|
||||||
*
|
*
|
||||||
* This is a parent class that all PICKLES modules should be extending. Each
|
* This is a parent class that all PICKLES modules should be extending.
|
||||||
* module can specify it's own meta data and whether or not a user must be
|
* Each module can specify it's own meta data and whether or not a user
|
||||||
* properly authenticated to view the page. Currently any pages without a
|
* must be properly authenticated to view the page. Currently any pages
|
||||||
* template are treated as pages being requested via AJAX and the return will
|
* without a template are treated as pages being requested via AJAX and the
|
||||||
* be JSON encoded. In the future this may need to be changed out for logic
|
* return will be JSON encoded. In the future this may need to be changed
|
||||||
* that allows the requested module to specify what display type(s) it can use.
|
* out for logic that allows the requested module to specify what display
|
||||||
|
* type(s) it can use.
|
||||||
*/
|
*/
|
||||||
class Module extends Object
|
class Module extends Object
|
||||||
{
|
{
|
||||||
|
@ -6221,9 +6213,9 @@ class Module extends Object
|
||||||
/**
|
/**
|
||||||
* Hash
|
* Hash
|
||||||
*
|
*
|
||||||
* Whether or not to validate the security hash. Boolean true will indicate
|
* Whether or not to validate the security hash. Boolean true will
|
||||||
* using the name of the module as the hash, a string value will use the
|
* indicate using the name of the module as the hash, a string value
|
||||||
* value instead.
|
* will use the value instead.
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @var string or boolean, null by default
|
* @var string or boolean, null by default
|
||||||
|
@ -6244,9 +6236,10 @@ class Module extends Object
|
||||||
/**
|
/**
|
||||||
* Default Template
|
* Default Template
|
||||||
*
|
*
|
||||||
* Defaults to null but could be set to any valid template basename. The
|
* Defaults to null but could be set to any valid template basename.
|
||||||
* value is overwritten by the config value if not set by the module. The
|
* The value is overwritten by the config value if not set by the
|
||||||
* display engine determines what the file extension should be.
|
* module. The display engine determines what the file extension should
|
||||||
|
* be.
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @var string, 'index' by default
|
* @var string, 'index' by default
|
||||||
|
@ -6258,8 +6251,8 @@ class Module extends Object
|
||||||
*
|
*
|
||||||
* Array that is returned to the template in the case of the module not
|
* Array that is returned to the template in the case of the module not
|
||||||
* returning anything itself. This is somewhat of a one way trip as you
|
* returning anything itself. This is somewhat of a one way trip as you
|
||||||
* cannot get the variable unless you reference the return array explicitly
|
* cannot get the variable unless you reference the return array
|
||||||
* $this->return['variable']
|
* explicitly $this->return['variable']
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @var array
|
* @var array
|
||||||
|
@ -6270,9 +6263,10 @@ class Module extends Object
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* The constructor does nothing by default but can be passed a boolean
|
* The constructor does nothing by default but can be passed a boolean
|
||||||
* variable to tell it to automatically run the __default() method. This is
|
* variable to tell it to automatically run the __default() method.
|
||||||
* typically used when a module is called outside of the scope of the
|
* This is typically used when a module is called outside of the scope
|
||||||
* controller (the registration page calls the login page in this manner.
|
* of the controller (the registration page calls the login page in
|
||||||
|
* this manner).
|
||||||
*
|
*
|
||||||
* @param boolean $autorun optional flag to autorun __default()
|
* @param boolean $autorun optional flag to autorun __default()
|
||||||
*/
|
*/
|
||||||
|
@ -6281,7 +6275,7 @@ class Module extends Object
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->cache = Cache::getInstance();
|
$this->cache = Cache::getInstance();
|
||||||
$this->db = Database::getInstance();
|
$this->db = Datastore::getInstance();
|
||||||
|
|
||||||
if ($autorun === true)
|
if ($autorun === true)
|
||||||
{
|
{
|
||||||
|
@ -6293,10 +6287,10 @@ class Module extends Object
|
||||||
* Default "Magic" Method
|
* Default "Magic" Method
|
||||||
*
|
*
|
||||||
* This function is overloaded by the module. The __default() method is
|
* This function is overloaded by the module. The __default() method is
|
||||||
* where you want to place any code that needs to be executed at runtime.
|
* where you want to place any code that needs to be executed at
|
||||||
* The reason the code isn't in the constructor is because the module must
|
* runtime. The reason the code isn't in the constructor is because the
|
||||||
* be instantiated before the code is executed so that the controller
|
* module must be instantiated before the code is executed so that the
|
||||||
* script is aware of the authentication requirements.
|
* controller script is aware of the authentication requirements.
|
||||||
*/
|
*/
|
||||||
public function __default()
|
public function __default()
|
||||||
{
|
{
|
||||||
|
@ -6306,9 +6300,10 @@ class Module extends Object
|
||||||
/**
|
/**
|
||||||
* Magic Setter Method
|
* Magic Setter Method
|
||||||
*
|
*
|
||||||
* Places the variables that are being modified in the return array that is
|
* Places the variables that are being modified in the return array
|
||||||
* returned if nothing is returned by the module itself. This also prohibits
|
* that is returned if nothing is returned by the module itself. This
|
||||||
* the direct modification of module variables which could cause issues.
|
* also prohibits the direct modification of module variables which
|
||||||
|
* could cause issues.
|
||||||
*
|
*
|
||||||
* @param string $name name of the variable to be set
|
* @param string $name name of the variable to be set
|
||||||
* @param mixed $value value of the variable to be set
|
* @param mixed $value value of the variable to be set
|
||||||
|
@ -6321,8 +6316,8 @@ class Module extends Object
|
||||||
/**
|
/**
|
||||||
* Magic Getter Method
|
* Magic Getter Method
|
||||||
*
|
*
|
||||||
* Attempts to load the module variable. If it's not set, will attempt to
|
* Attempts to load the module variable. If it's not set, will attempt
|
||||||
* load from the config.
|
* to load from the config.
|
||||||
*
|
*
|
||||||
* @param string $name name of the variable requested
|
* @param string $name name of the variable requested
|
||||||
* @return mixed value of the variable or boolean false
|
* @return mixed value of the variable or boolean false
|
||||||
|
@ -7563,7 +7558,7 @@ class Session extends Object
|
||||||
$this->table = $table;
|
$this->table = $table;
|
||||||
|
|
||||||
// Gets a database instance
|
// Gets a database instance
|
||||||
$this->db = Database::getInstance($this->datasource);
|
$this->db = Datastore::getInstance($this->datasource);
|
||||||
|
|
||||||
// Initializes the session
|
// Initializes the session
|
||||||
$this->initialize();
|
$this->initialize();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue