set_magic_quotes_runtime(0);
// some debug info that's always useful
- BSLoader::GetRegister()->debug('magic_quotes_gpc = ' . $this->magicquotes);
- BSLoader::GetRegister()->debug('register_globals = ' . ini_get('register_globals'));
+ BSRegister::Instance()->debug('magic_quotes_gpc = ' . $this->magicquotes);
+ BSRegister::Instance()->debug('register_globals = ' . ini_get('register_globals'));
$this->sanitizeInputData();
trigger_error('No external hosts are allowed to POST to this application');
exit;
}
- BSLoader::GetRegister()->debug('remote post check = ok');
+ BSRegister::Instance()->debug('remote post check = ok');
}
else
{
- BSLoader::GetRegister()->debug('remote post check = FAILED');
+ BSRegister::Instance()->debug('remote post check = FAILED');
}
}
}
+++ /dev/null
-<?php
-/*=====================================================================*\
-|| ###################################################################
-|| # Blue Static ISSO Framework [#]issoversion[#]
-|| # Copyright ©2002-[#]year[#] Blue Static
-|| #
-|| # This program is free software; you can redistribute it and/or modify
-|| # it under the terms of the GNU General Public License as published by
-|| # the Free Software Foundation; version [#]gpl[#] of the License.
-|| #
-|| # This program is distributed in the hope that it will be useful, but
-|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-|| # more details.
-|| #
-|| # You should have received a copy of the GNU General Public License along
-|| # with this program; if not, write to the Free Software Foundation, Inc.,
-|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-|| ###################################################################
-\*=====================================================================*/
-
-/**
-* System loader (Loader.php)
-*
-* @package ISSO
-*/
-
-// we need PHP5 to run
-if (!function_exists('stripos'))
-{
- trigger_error('You need PHP version 5.0.0 or newer to run ISSO', E_USER_ERROR);
- exit;
-}
-
-// get rid of register_globals
-if ((bool)ini_get('register_globals') === true)
-{
- $superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
- foreach ($superglobals AS $global)
- {
- if (is_array(${$global}))
- {
- foreach (${$global} AS $_key => $_val)
- {
- if (isset(${$_key}))
- {
- unset(${$_key});
- }
- }
- }
- }
-}
-
-/**
-* System Loader
-*
-* This class contains static methods that are used to create new registers and
-* load modules.
-*
-* @author Blue Static
-* @copyright Copyright ©2002 - [#]year[#], Blue Static
-* @version $Revision$
-* @package ISSO
-*
-*/
-class BSLoader
-{
- /**
- * Singleton instance
- * @var object
- */
- private static $instance;
-
- /**
- * Array of all the registers
- * @var array
- */
- private $registers = array();
-
- /**
- * The main register
- * @var object
- */
- private $main;
-
- // ###################################################################
- /**
- * Constructor
- */
- private function __construct() {}
-
- // ###################################################################
- /**
- * Returns the shared instance of the BSLoader singleton class.
- *
- * @return object The BSLoader shared instance
- */
- private static function SharedInstance()
- {
- if (!self::$instance)
- {
- self::$instance = new BSLoader;
- set_error_handler(array(self::$instance, 'errorHandler'));
- }
- return self::$instance;
- }
-
- // ###################################################################
- /**
- * Creates a new BSRegister instance and returns it.
- *
- * @return object New register
- */
- public static function NewRegister()
- {
- require_once('ISSO/Register.php');
-
- self::SharedInstance()->registers[] = $return = new BSRegister();
-
- return $return;
- }
-
- // ###################################################################
- /**
- * Returns the array of all the registers
- *
- * @return array The array of all the registers
- */
- public static function GetAllRegisters()
- {
- return self::SharedInstance()->registers;
- }
-
- // ###################################################################
- /**
- * Sets the main register
- *
- * @param object New main register
- */
- public static function SetRegister($register)
- {
- if (get_class($register) != 'BSRegister')
- {
- trigger_error('BSLoader::SetRegister() was not passed a BSRegister object');
- return;
- }
-
- self::SharedInstance()->main = $register;
- }
-
- // ###################################################################
- /**
- * Gets the main register if no argument is passed, or an arbitrary
- * one if the index of a register is passed.
- *
- * @param integer Register index
- *
- * @return object Specified register
- */
- public static function &GetRegister($index = null)
- {
- if (is_null($index))
- {
- if (!isset(self::SharedInstance()->main))
- {
- trigger_error('Cannot fetch the main register because it has not been set with BSLoader::SetRegister()');
- return;
- }
- return self::SharedInstance()->main;
- }
- else
- {
- if (!isset(self::SharedInstance()->registers["$index"]))
- {
- trigger_error('Invalid register index passed to BSLoader::GetRegister()');
- return;
- }
- return self::SharedInstance()->registers["$index"];
- }
- }
-
- // ###################################################################
- /**
- * Determines if there's a main register set. If not, returns FALSE.
- *
- * @return bool Is there a main register set?
- */
- public static function HasRegister()
- {
- return (isset(self::SharedInstance()->main) AND self::SharedInstance()->main instanceof BSRegister);
- }
-
- // ###################################################################
- /**
- * Loads the specified module.
- *
- * @param string Module name
- *
- * @return object Instantiated module
- */
- public static function LoadModule($name)
- {
- @include_once("ISSO/$name.php");
-
- $class = "BS$name";
-
- if (!class_exists($class))
- {
- trigger_error('Specifed module does not conform to the ISSO specification, or the class is missing');
- return;
- }
-
- return new $class;
- }
-
- // ###################################################################
- /**
- * Prints an ISSO message
- *
- * @param string The title of the message
- * @param string The content of the message
- * @param integer Type of message to be printed
- * @param bool Return the output?
- * @param bool Show the debug stack?
- * @param integer Message width
- *
- * @return mixed Output or null
- */
- public static function Message($title, $message, $type, $return = false, $stack = true, $width = 500)
- {
- switch ($type)
- {
- // Message
- case 1:
- $prefix = 'Message';
- $color = '#669900';
- $font = '#000000';
- break;
-
- // Warning
- case 2:
- $prefix = 'Warning';
- $color = '#003399';
- $font = '#FFFFFF';
- break;
-
- case 3:
- $prefix = 'Error';
- $color = '#990000';
- $font = '#EFEFEF';
- break;
- }
-
- echo "\n<br />\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" width=\"$width\" style=\"background-color: $color; color: black; font-family: Verdana, sans-serif; font-size: 12px;\">";
- echo "\n<tr style=\"color: $font; text-align: left\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
- echo "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td>$message</td>\n</tr>";
- if ($stack AND self::HasRegister() AND self::GetRegister()->getDebug())
- {
- echo "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td><strong>Debug Stack:</strong> <pre>";
- debug_print_backtrace();
- echo "</pre></td>\n</tr>";
- }
- echo "\n</table>\n<br />\n";
- }
-
- // ###################################################################
- /**
- * Custom error handler for ISSO; only handle E_WARNING, E_NOTICE,
- * E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
- *
- * @param integer Error number
- * @param string Error message string
- * @param string File that contains the error
- * @param string The line number of the error
- * @param string The active symbol table at which point the error occurred
- */
- private function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
- {
- $level = ini_get('error_reporting');
-
- switch ($errno)
- {
- // So we don't need to specify the error type in trigger_error(), all E_USER_NOTICEs
- // are fatal and automatically kill the script
- case E_USER_NOTICE:
- $title = 'Fatal';
- $mode = 3;
- break;
-
- // A non-fatal but important warning
- case E_WARNING:
- $title = 'Warning';
- $mode = 2;
- if (!($level & E_WARNING))
- {
- return;
- }
- break;
-
- // A non-fatal notice that should all but be ignored unless in dev environments
- case E_NOTICE:
- case E_STRICT:
- $title = 'Notice';
- $mode = 1;
- if (!($level & E_NOTICE))
- {
- return;
- }
- break;
-
- case E_USER_WARNING:
- case E_USER_NOTICE:
- default:
- trigger_error('The only error types supported are E_USER_NOTICE (fatal), E_WARNING, and E_NOTICE');
- break;
- }
-
- $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
-
- $errstr = str_replace(array(getcwd(), dirname(getcwd())), '', $errstr);
-
- self::Message($title, $errstr, $mode);
-
- if ($errno == E_USER_NOTICE)
- {
- exit;
- }
- }
-
- // ###################################################################
- /**
- * Creates a table that explains the error reporting levels and their
- * state
- */
- public static function ExplainErrorReporting()
- {
- $levels = array(
- 'E_ERROR' => E_ERROR,
- 'E_WARNING' => E_WARNING,
- 'E_PARSE' => E_PARSE,
- 'E_NOTICE' => E_NOTICE,
- 'E_CORE_ERROR' => E_CORE_ERROR,
- 'E_CORE_WARNING' => E_CORE_WARNING,
- 'E_COMPILE_ERROR' => E_COMPILE_ERROR,
- 'E_COMPILE_WARNING' => E_COMPILE_WARNING,
- 'E_USER_ERROR' => E_USER_ERROR,
- 'E_USER_WARNING' => E_USER_WARNING,
- 'E_USER_NOTICE' => E_USER_NOTICE,
- 'E_ALL' => E_ALL,
- 'E_STRICT' => E_STRICT
- );
-
- $table = '<table cellspacing="0" cellpadding="2" border="0">';
-
- foreach ($levels AS $name => $value)
- {
- $table .= '
- <tr>
- <td>' . $name . '</td>
- <td>' . (ini_get('error_reporting') & $value) . '</td>
- </tr>';
- }
-
- $table .= '
- </table>';
-
- self::Message('Error Reporting', $table, 1);
- }
-}
-
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
-?>
\ No newline at end of file
* @package ISSO
*/
+// we need PHP5 to run
+if (!function_exists('stripos'))
+{
+ trigger_error('You need PHP version 5.0.0 or newer to run ISSO', E_USER_ERROR);
+ exit;
+}
+
+// get rid of register_globals
+if ((bool)ini_get('register_globals') === true)
+{
+ $superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
+ foreach ($superglobals AS $global)
+ {
+ if (is_array(${$global}))
+ {
+ foreach (${$global} AS $_key => $_val)
+ {
+ if (isset(${$_key}))
+ {
+ unset(${$_key});
+ }
+ }
+ }
+ }
+}
+
require_once('ISSO/Functions.php');
/**
*
* This is an ISSO registry class. It holds all of the ISSO system variables as well
* as serving as an object registry that is avaliable in the global scope to prevent
-* globalization of variables.
+* globalization of variables. There can only be one instance of this existing
+* at any given time.
*
* @author Blue Static
* @copyright Copyright ©2002 - [#]year[#], Blue Static
*/
class BSRegister
{
+ /**
+ * Instance of this class
+ * @var object
+ */
+ private static $instance;
+
/**
* Application name
* @var string
*/
private $debugInfo = array();
+ // ###################################################################
+ /**
+ * Constructor: set the error handler
+ */
+ private function __construct()
+ {
+ set_error_handler(array(self::$instance, '_errorHandler'));
+ }
+
+ // ###################################################################
+ /**
+ * Returns the single instance of the register
+ *
+ * @param string A string param
+ *
+ * @return object BSRegister instance
+ */
+ public static function Instance()
+ {
+ if (self::$instance == null)
+ {
+ self::$instance = new BSRegister();
+ }
+ return self::$instance;
+ }
+
// ###################################################################
/**
* Sets the application name
$this->debugInfo[] = $msg;
}
}
+
+ // ###################################################################
+ /**
+ * Loads the specified module.
+ *
+ * @param string Module name
+ *
+ * @return object Instantiated module
+ */
+ public static function LoadModule($name)
+ {
+ @include_once("ISSO/$name.php");
+
+ $class = "BS$name";
+
+ if (!class_exists($class))
+ {
+ trigger_error('Specifed module does not conform to the ISSO specification, or the class is missing');
+ return;
+ }
+
+ return new $class;
+ }
+
+ // ###################################################################
+ /**
+ * Prints an ISSO message
+ *
+ * @param string The title of the message
+ * @param string The content of the message
+ * @param integer Type of message to be printed
+ * @param bool Return the output?
+ * @param bool Show the debug stack?
+ * @param integer Message width
+ *
+ * @return mixed Output or null
+ */
+ public static function Message($title, $message, $type, $return = false, $stack = true, $width = 500)
+ {
+ switch ($type)
+ {
+ // Message
+ case 1:
+ $prefix = 'Message';
+ $color = '#669900';
+ $font = '#000000';
+ break;
+
+ // Warning
+ case 2:
+ $prefix = 'Warning';
+ $color = '#003399';
+ $font = '#FFFFFF';
+ break;
+
+ case 3:
+ $prefix = 'Error';
+ $color = '#990000';
+ $font = '#EFEFEF';
+ break;
+ }
+
+ echo "\n<br />\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" width=\"$width\" style=\"background-color: $color; color: black; font-family: Verdana, sans-serif; font-size: 12px;\">";
+ echo "\n<tr style=\"color: $font; text-align: left\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
+ echo "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td>$message</td>\n</tr>";
+ if ($stack AND self::Instance()->getDebug())
+ {
+ echo "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td><strong>Debug Stack:</strong> <pre>";
+ debug_print_backtrace();
+ echo "</pre></td>\n</tr>";
+ }
+ echo "\n</table>\n<br />\n";
+ }
+
+ // ###################################################################
+ /**
+ * Custom error handler for ISSO; only handle E_WARNING, E_NOTICE,
+ * E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
+ *
+ * @param integer Error number
+ * @param string Error message string
+ * @param string File that contains the error
+ * @param string The line number of the error
+ * @param string The active symbol table at which point the error occurred
+ */
+ private function _errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
+ {
+ $level = ini_get('error_reporting');
+
+ switch ($errno)
+ {
+ // So we don't need to specify the error type in trigger_error(), all E_USER_NOTICEs
+ // are fatal and automatically kill the script
+ case E_USER_NOTICE:
+ $title = 'Fatal';
+ $mode = 3;
+ break;
+
+ // A non-fatal but important warning
+ case E_WARNING:
+ $title = 'Warning';
+ $mode = 2;
+ if (!($level & E_WARNING))
+ {
+ return;
+ }
+ break;
+
+ // A non-fatal notice that should all but be ignored unless in dev environments
+ case E_NOTICE:
+ case E_STRICT:
+ $title = 'Notice';
+ $mode = 1;
+ if (!($level & E_NOTICE))
+ {
+ return;
+ }
+ break;
+
+ case E_USER_WARNING:
+ case E_USER_NOTICE:
+ default:
+ trigger_error('The only error types supported are E_USER_NOTICE (fatal), E_WARNING, and E_NOTICE');
+ break;
+ }
+
+ $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
+
+ $errstr = str_replace(array(getcwd(), dirname(getcwd())), '', $errstr);
+
+ self::Message($title, $errstr, $mode);
+
+ if ($errno == E_USER_NOTICE)
+ {
+ exit;
+ }
+ }
+
+ // ###################################################################
+ /**
+ * Creates a table that explains the error reporting levels and their
+ * state
+ */
+ public static function ExplainErrorReporting()
+ {
+ $levels = array(
+ 'E_ERROR' => E_ERROR,
+ 'E_WARNING' => E_WARNING,
+ 'E_PARSE' => E_PARSE,
+ 'E_NOTICE' => E_NOTICE,
+ 'E_CORE_ERROR' => E_CORE_ERROR,
+ 'E_CORE_WARNING' => E_CORE_WARNING,
+ 'E_COMPILE_ERROR' => E_COMPILE_ERROR,
+ 'E_COMPILE_WARNING' => E_COMPILE_WARNING,
+ 'E_USER_ERROR' => E_USER_ERROR,
+ 'E_USER_WARNING' => E_USER_WARNING,
+ 'E_USER_NOTICE' => E_USER_NOTICE,
+ 'E_ALL' => E_ALL,
+ 'E_STRICT' => E_STRICT
+ );
+
+ $table = '<table cellspacing="0" cellpadding="2" border="0">';
+
+ foreach ($levels AS $name => $value)
+ {
+ $table .= '
+ <tr>
+ <td>' . $name . '</td>
+ <td>' . (ini_get('error_reporting') & $value) . '</td>
+ </tr>';
+ }
+
+ $table .= '
+ </table>';
+
+ self::Message('Error Reporting', $table, 1);
+ }
}
/*=====================================================================*\
$test = new GroupTest('All Tests');
-$test->addTestFile('LoaderTest.php');
$test->addTestFile('RegisterTest.php');
$test->addTestFile('FunctionsTest.php');
<?php
// load piggy
-require_once('./../Loader.php');
+require_once('./../Register.php');
/**
* Functions Test Suite
+++ /dev/null
-<?php
-
-// load piggy
-require_once('./../Loader.php');
-
-/**
-* Loader Test Suite
-*
-* @author Blue Static
-* @copyright Copyright ©2002 - [#]year[#], Blue Static
-* @version $Revision$
-* @package ISSO Tests
-*
-*/
-class LoaderTest extends UnitTestCase
-{
- protected $instance;
-
- public function testNewRegister()
- {
- $this->instance = BSLoader::NewRegister();
-
- $this->assertEqual(get_class($this->instance), 'BSRegister');
- }
-
- public function testGetAllRegisters()
- {
- $this->assertIsA(BSLoader::GetAllRegisters(), 'array', 'Register array is not an array');
- $this->assertEqual(sizeof(BSLoader::GetAllRegisters()), 1, 'Register array is wrong size');
- }
-
- public function testSetGetRegister()
- {
- BSLoader::SetRegister($this->instance);
-
- $this->assertReference(BSLoader::GetRegister(), $this->instance);
- }
-
- public function testRegisterAfterMakeNew()
- {
- BSLoader::NewRegister();
-
- $this->assertEqual(get_class(BSLoader::GetRegister(1)), 'BSRegister', 'Failed to get arbitrary register');
- $this->assertEqual(sizeof(BSLoader::GetAllRegisters()), 2, 'Sizeof register array is wrong');
- $this->assertReference($this->instance, BSLoader::GetRegister(), 'Main register does not match instance');
- }
-
- public function testLoadModule()
- {
- $this->assertEqual(get_class(BSLoader::LoadModule('Input')), 'BSInput');
- }
-
- public function testLoadBadModule()
- {
- BSLoader::LoadModule('nonExistentModule');
- $this->assertError();
- }
-}
-
-?>
\ No newline at end of file
<?php
// piggy
-require_once('./../Loader.php');
+require_once('./../Register.php');
/**
* Register Test Suite
public function setUp()
{
- $this->fixture = BSLoader::NewRegister();
+ $this->fixture = BSRegister::Instance();
+ }
+
+ public function testNewRegister()
+ {
+ $this->assertTrue($this->fixture instanceof BSRegister);
+ $this->assertReference($this->fixture, BSRegister::Instance());
+ }
+
+ public function testLoadModule()
+ {
+ $this->assertTrue(BSRegister::LoadModule('Input') instanceof BSInput);
+ }
+
+ public function testLoadBadModule()
+ {
+ BSRegister::LoadModule('nonExistentModule');
+ $this->assertError();
}
public function testSetGetAppPath()
public function testGetAll()
{
- $new = BSLoader::NewRegister();
- $new->register('test', 1);
- $this->assertIsA($new->getAll(), 'array');
- $this->assertEqual(sizeof($new->getAll()), 1);
+ $this->fixture->register('test', 1);
+ $this->assertIsA($this->fixture->getAll(), 'array');
+ $this->assertEqual(sizeof($this->fixture->getAll()), 2);
}
public function testOverWriteRegister()