*/
private $exception = null;
- // ###################################################################
/**
- * Constructor: cannot instantiate class directly
- */
+ * Constructor
+ */
public function __construct()
{
- BSApp::required_modules(array('Db', 'Input'));
+ if (!BSApp::$input instanceof BSInput)
+ {
+ throw new Exception('BSApp::$input is not an instance of BSInput');
+ }
+ if (!BSApp::$db instanceof BSDb)
+ {
+ throw new Exception('BSApp::$db is not an instance of BSDb');
+ }
}
// ###################################################################
throw new Exception('Field "' . $field . '" is not valid');
}
- $this->values["$field"] = ($doclean ? BSApp::registry()->getType('Input')->clean($value, $this->fields["$field"][F_TYPE]) : $value);
+ $this->values["$field"] = ($doclean ? BSApp::$input->clean($value, $this->fields["$field"][F_TYPE]) : $value);
$this->setfields["$field"] = $field;
$this->_runActionMethod('pre_fetch', $doPre);
- $result = BSApp::registry()->getType('Db')->queryFirst("SELECT * FROM {$this->prefix}{$this->table} WHERE {$this->condition}");
+ $result = BSApp::$db->queryFirst("SELECT * FROM {$this->prefix}{$this->table} WHERE {$this->condition}");
if (!$result)
{
return false;
$values[] = $this->_prepareFieldForSql($field);
}
- BSApp::registry()->getType('Db')->query("INSERT INTO {$this->prefix}{$this->table} (" . implode(',', $fields) . ") VALUES (" . implode(',', $values) . ")");
+ BSApp::$db->query("INSERT INTO {$this->prefix}{$this->table} (" . implode(',', $fields) . ") VALUES (" . implode(',', $values) . ")");
- if (BSApp::registry()->getType('DbPostgreSql'))
+ if (BSApp::$db instanceof BSDbPostgreSql)
{
foreach ($this->fields AS $field => $info)
{
}
}
- $this->insertid = BSApp::registry()->getType('Db')->insertId($this->prefix . $this->table, $autofield);
+ $this->insertid = BSApp::$db->insertId($this->prefix . $this->table, $autofield);
}
else
{
- $this->insertid = BSApp::registry()->getType('Db')->insertId();
+ $this->insertid = BSApp::$db->insertId();
}
$this->_runActionMethod('post_insert', $doPost);
}
$updates = implode(', ', $updates);
- BSApp::registry()->getType('Db')->query("UPDATE {$this->prefix}{$this->table} SET $updates WHERE {$this->condition}");
+ BSApp::$db->query("UPDATE {$this->prefix}{$this->table} SET $updates WHERE {$this->condition}");
$this->_runActionMethod('post_update', $doPost);
}
$this->_runActionMethod('pre_remove', $doPre);
- BSApp::registry()->getType('Db')->query("DELETE FROM {$this->prefix}{$this->table} WHERE {$this->condition}");
+ BSApp::$db->query("DELETE FROM {$this->prefix}{$this->table} WHERE {$this->condition}");
$this->_runActionMethod('post_remove', $doPost);
}
if ($type == TYPE_NONE OR $type == TYPE_STR OR $type == TYPE_STRUN)
{
- return "'" . BSApp::registry()->getType('Db')->escapeString($this->values["$name"]) . "'";
+ return "'" . BSApp::$db->escapeString($this->values["$name"]) . "'";
}
else if ($type == TYPE_BOOL)
{
}
else if ($type == TYPE_BIN)
{
- return "'" . BSApp::registry()->getType('Db')->escapeBinary($this->values["$name"]) . "'";
+ return "'" . BSApp::$db->escapeBinary($this->values["$name"]) . "'";
}
else
{
*/
protected function _verifyIsNotUnique($field)
{
- $res = BSApp::registry()->getType('Db')->queryFirst("SELECT $field FROM {$this->prefix}{$this->table} WHERE $field = " . $this->_prepareFieldForSql($field) . (empty($this->condition) ? "" : " AND !({$this->condition})"));
+ $res = BSApp::$db->queryFirst("SELECT $field FROM {$this->prefix}{$this->table} WHERE $field = " . $this->_prepareFieldForSql($field) . (empty($this->condition) ? "" : " AND !({$this->condition})"));
if ($res)
{
$this->_error(new FieldException(sprintf(_('The "%1$s" field must contain a unique value'), $field), $field));
*/
class BSApp
{
- /**
- * Instance of this class
- * @var object
- */
- private static $instance;
-
/**
* Debug mode?
* @var bool
*/
- private $debug = false;
-
- /**
- * The master registry list
- * @var array
- */
- private $registry = null;
+ private static $debug = false;
/**
* An array of debug messages
* @var array
*/
- private $debugInfo = array();
+ private static $debugInfo = array();
- // ###################################################################
/**
- * Constructor
- */
+ * Constructor
+ */
private function __construct()
- {
- $this->registry = new BSVariableRegistry();
- }
-
- // ###################################################################
- /**
- * Returns the single instance of the register
- *
- * @param string A string param
- *
- * @return object BSApp instance
- */
- private static function _instance()
- {
- if (!self::$instance)
- {
- self::$instance = new BSApp();
- }
- return self::$instance;
- }
+ {}
// ###################################################################
/**
*/
public static function set_debug($debug)
{
- self::_instance()->debug = $debug;
+ self::$debug = $debug;
}
// ###################################################################
*/
public static function get_debug()
{
- return self::_instance()->debug;
- }
-
- // ###################################################################
- /**
- * Returns the registry object without it ever being able to be cleared
- * or unset
- *
- * @return StdClass
- */
- public static function registry()
- {
- return self::_instance()->registry;
+ return self::$debug;
}
// ###################################################################
*/
public static function debug($msg)
{
- if (self::_instance()->debug)
+ if (self::$debug)
{
- self::_instance()->debugInfo[] = $msg;
+ self::$debugInfo[] = $msg;
}
}
*/
public static function get_debug_list()
{
- $output = '<select><option>Debug Notices (' . sizeof(self::_instance()->debugInfo) . ')</option>';
- foreach (self::_instance()->debugInfo AS $notice)
+ $output = '<select><option>Debug Notices (' . sizeof(self::$debugInfo) . ')</option>';
+ foreach (self::$debugInfo AS $notice)
{
$output .= "<option>--- $notice</option>";
}
}
// ###################################################################
+ // modules
+
/**
- * Loads the specified module.
- *
- * @param string Module name
- *
- * @return object Instantiated module
- */
- public static function load_module($name)
- {
- if (self::get_debug())
- {
- include_once(ISSO . "/$name.php");
- }
- else
- {
- @include_once(ISSO . "/$name.php");
- }
-
- $class = "BS$name";
-
- if (!class_exists($class))
- {
- throw new Exception('Specifed module does not conform to the ISSO specification, or the class is missing');
- return;
- }
-
- return new $class;
- }
-
- // ###################################################################
- /**
- * This function is used by other framework modules to check and see if
- * the passed array of module names have been loaded. If not, this will
- * throw an error informing the developer that the given modules are
- * required in order for the framework to work.
- *
- * @param array Array of module names to check for loadedness
- */
- public static function required_modules($modules)
- {
- foreach ($modules AS $module)
- {
- if (self::registry()->getType($module) == null)
- {
- throw new Exception('The ' . $module . ' module is required in order to use this framework module');
- }
- }
- }
-}
-
-/**
- * Variable Registry
- *
- * This class can be used to store unlimited number of properties. It is a (make believe)
- * inner class to BSApp and cannot be instantiated outside of it.
- *
- * @author Blue Static
- * @copyright Copyright (c)2005 - 2008, Blue Static
- * @version $Id$
- * @package ISSO
- *
- */
-class BSVariableRegistry
-{
- // ###################################################################
- /**
- * Constructor: only able to be called by BSApp
+ * BSDate
+ * @var object
*/
- public function __construct()
- {
- $bt = debug_backtrace();
- if (!isset($bt[1]['class']) OR $bt[1]['class'] != 'BSApp')
- {
- exit('You cannot instantiate ' . __CLASS__ . ' directly. It is an internal class.');
- }
- }
+ public static $date;
- // ###################################################################
/**
- * If you try and get a non-existent property, throw a new exception
+ * BSDb
+ * @var object
*/
- public function __get($name)
- {
- throw new Exception('Failed to get nonexistent property "' . $name . '"');
- }
+ public static $db;
- // ###################################################################
/**
- * Returns the first value of the given type in the variable registry
- *
- * @return mixed
+ * BSInput
+ * @var object
*/
- public function getType($class)
- {
- $class = 'BS' . $class;
- foreach ($this AS $object)
- {
- if ($object instanceof $class)
- {
- return $object;
- }
- }
- }
+ public static $input;
- // ###################################################################
/**
- * Returns all the objects in the registry by iterating over it
- *
- * @return array
+ * BSTemplate
+ * @var object
*/
- public function allObjects()
- {
- $registry = array();
- foreach ($this AS $key => $value)
- {
- $registry[$key] = $value;
- }
- return $registry;
- }
+ public static $template;
}
?>
\ No newline at end of file
*/
public function escape($str, $force = true)
{
- $db = BSApp::registry()->getType('Db');
+ $db = BSApp::$db;
if ($this->magicquotes AND !$force)
{
if ($db)
{
$this->fileName = $fileName;
- BSApp::required_modules(array('Input'));
+ if (!BSApp::$input instanceof BSInput)
+ {
+ throw new Exception('BSApp::$input is not an instance of BSInput');
+ }
$methods = get_class_methods($this);
foreach ($methods AS $name)
}
natsort($this->steps);
- $this->_runStep(BSApp::registry()->getType('Input')->inputClean('step', TYPE_UINT));
+ $this->_runStep(BSApp::$input->inputClean('step', TYPE_UINT));
}
// ###################################################################
* @access public
*/
private $charset = 'utf-8'; // should we be using iso-8859-1 ?
+
+ /**
+ * Constructor
+ */
+ public function __construct()
+ {
+ if (!BSApp::$input instanceof BSInput)
+ {
+ throw new Exception('BSApp::$input is not an instance of BSInput');
+ }
+ }
// ###################################################################
/**
throw new Exception('You need to specify an email address');
}
- // load the input sanitizer
- $input = BSApp::registry()->getType('Input');
- if ($input == null)
- {
- BSApp::debug(ISSO . '/Input not loaded, so manually doing so');
- $input = BSApp::load_module('Input');
- }
-
// make sure we have a mailer
// TODO - add support for SMTP
if (!@ini_get('sendmail_path'))
// sort out the to addresses
$address = $this->_fetchFirstLine($address);
- $address = trim($input->unsanitize($address));
+ $address = trim(BSApp::$input->unsanitize($address));
$name = $this->_fetchFirstLine($name);
- $name = trim($input->unsanitize($name));
+ $name = trim(BSApp::$input->unsanitize($name));
$tostring = ($name == null ? $address : "\"$name\" <$address>");
// sanitize the from field
$from = $this->_fetchFirstLine($this->from);
- $from = trim($input->unsanitize($from));
+ $from = trim(BSApp::$input->unsanitize($from));
if (empty($from))
{
throw new Exception('You need to specify a from email address');
// sanitize the from name
$fromName = $this->_fetchFirstLine($this->fromName);
- $fromName = ($fromName == '' ? $from : trim($input->unsanitize($fromName)));
+ $fromName = ($fromName == '' ? $from : trim(BSApp::$input->unsanitize($fromName)));
$fromName = $this->_encodeHeaderValue($this->fromName);
// sanitize the subject
$subject = $this->_fetchFirstLine($this->subject);
- $subject = trim($input->unsanitize($subject));
+ $subject = trim(BSApp::$input->unsanitize($subject));
if (empty($subject))
{
throw new Exception('You need to specify a subject for the message');
// sanitize the body
$bodyText = BSFunctions::convert_line_breaks($this->bodyText, $this->delim);
- $bodyText = trim($input->unsanitize($bodyText, true));
+ $bodyText = trim(BSApp::$input->unsanitize($bodyText, true));
if (empty($bodyText))
{
throw new Exception('You need to specify body text before sending the message');
*/
private $pagenavprocessor = ':undefined:';
+ /**
+ * Constructor
+ */
+ public function __construct()
+ {
+ if (!BSApp::$input instanceof BSInput)
+ {
+ throw new Exception('BSApp::$input is not an instance of BSInput');
+ }
+ }
+
// ###################################################################
/**
* Callback public function for the processing of an indivdual page. Needs
*/
public function processIncomingData()
{
- $input = BSApp::GetType('Input');
- if ($input == null)
- {
- BSApp::debug(ISSO . '/Input not loaded, so manually doing so');
- $input = BSApp::load_module('Input');
- }
-
- $this->page = $input->inputClean($this->pagevar, TYPE_INT);
- $this->perpage = $input->inputClean($this->perpagevar, TYPE_INT);
- $this->pagelinks = $input->clean($this->pagelinks, TYPE_INT);
+ $this->page = BSApp::$input->inputClean($this->pagevar, TYPE_INT);
+ $this->perpage = BSApp::$input->inputClean($this->perpagevar, TYPE_INT);
+ $this->pagelinks = BSApp::$input->clean($this->pagelinks, TYPE_INT);
if ($this->page <= 0)
{
$this->perpage = $this->maxperpage;
}
- $this->perpage = $input->clean($this->perpage, TYPE_INT);
+ $this->perpage = BSApp::$input->clean($this->perpage, TYPE_INT);
}
// ###################################################################
$dbCache = array();
if ($this->dbCacheTable)
{
- $db =& BSApp::registry()->getType('Db');
+ $db =& BSApp::$db;
$cache = $db->query("SELECT * FROM {$this->dbCacheTable} WHERE filename IN ('" . implode("', '", $namearray) . "')");
while ($tpl = $cache->fetchArray())
{
$debugBlock .= "<br /><div style=\"color: red\" align=\"center\"><strong>Uncached Templates:</strong>" . implode(', ', $tpls) . " )</div>\n";
}
- if (BSApp::registry()->getType('Db'))
+ if (BSApp::$db)
{
- $queries = BSApp::registry()->getType('Db')->getHistory();
+ $queries = BSApp::$db->getHistory();
$debugBlock .= "<br />\n" . '<table cellpadding="4" cellspacing="1" border="0" align="center" width="30%" style="background-color: rgb(60, 60, 60); color: white">' . "\n\t" . '<tr><td><strong>Query Debug</strong></td></tr>';