X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fclass_BaseFrameworkSystem.php;h=5237b802b1faedba51b31d9a45f985d39f5aead9;hp=9e7f247b4bf131264ce6c8e6a7dc0d0ae20a9b55;hb=2644a1716fe8801811a383d13d56f16a3796bc17;hpb=0d566e56ff27dcbf25a90d513950bbf26fe71422 diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 9e7f247b..5237b802 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -83,6 +83,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $iteratorInstance = null; + /** + * Instance of the list + */ + private $listInstance = null; + /** * The real class name */ @@ -101,7 +106,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { /*********************** * Exception codes.... * ***********************/ - + // @todo Try to clean these constants up const EXCEPTION_IS_NULL_POINTER = 0x001; const EXCEPTION_IS_NO_OBJECT = 0x002; const EXCEPTION_IS_NO_ARRAY = 0x003; @@ -128,7 +133,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { const EXCEPTION_WRITE_PROTECED_PATH = 0x018; const EXCEPTION_DIR_POINTER_INVALID = 0x019; const EXCEPTION_FILE_POINTER_INVALID = 0x01a; - const EXCEPTION_INVALID_DIRECTORY_POINTER = 0x01b; + const EXCEPTION_INVALID_RESOURCE = 0x01b; const EXCEPTION_UNEXPECTED_OBJECT = 0x01c; const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d; const EXCEPTION_GETTER_IS_MISSING = 0x01e; @@ -171,10 +176,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Set real class $this->setRealClass($className); - // Initialize the class if class Registry is there - if ((class_exists('Registry')) && (Registry::isInitialized() === false)) { - // Initialize the registry automatically - $this->initInstance(); + // Set configuration instance if no registry + if (!$this instanceof Register) { + // Because registries doesn't need to be configured + $this->setConfigInstance(FrameworkConfiguration::getInstance()); } // END - if } @@ -245,16 +250,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { return null; } - /** - * Private initializer for this class - * - * @return void - */ - private final function initInstance () { - // Set configuration instance - $this->setConfigInstance(FrameworkConfiguration::getInstance()); - } - /** * Setter for database result instance * @@ -388,7 +383,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput */ public final function getDebugInstance () { + // Get debug instance $debugInstance = Registry::getRegistry()->getInstance('debug'); + + // Return it return $debugInstance; } @@ -429,13 +427,8 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return $dbInstance The database layer instance */ public final function getDatabaseInstance () { - // Default is invalid db instance - $dbInstance = null; - - // Is the registry there and initialized? - if ((class_exists('Registry')) && (Registry::isInitialized() === true)) { - $dbInstance = Registry::getRegistry()->getInstance('db_instance'); - } // END - if + // Get instance + $dbInstance = Registry::getRegistry()->getInstance('db_instance'); // Return instance return $dbInstance; @@ -1130,6 +1123,65 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { public final function getIteratorInstance () { return $this->iteratorInstance; } + + /** + * "Getter" as a time() replacement but with milliseconds. You should use this + * method instead of the encapsulated getimeofday() function. + * + * @return $milliTime Timestamp with milliseconds + */ + public function getMilliTime () { + // Get the time of day as float + $milliTime = gettimeofday(true); + + // Return it + return $milliTime; + } + + /** + * Idles (sleeps) for given milliseconds + * + * @return $hasSlept Wether it goes fine + */ + public function idle ($milliSeconds) { + // Sleep is fine by default + $hasSlept = true; + + // Idle so long with found function + if (function_exists('time_sleep_until')) { + // Get current time and add idle time + $sleepUntil = $this->getMilliTime() + abs($milliSeconds) / 1000; + + // New PHP 5.1.0 function found + $hasSlept = time_sleep_until($sleepUntil); + } else { + // My Sun Station doesn't have that function even with latest PHP + // package. :( + usleep($milliSeconds * 1000); + } + + // Return result + return $hasSlept; + } + + /** + * Setter for the list instance + * + * @param $listInstance A list of Listable + * @return void + */ + protected final function setListInstance (Listable $listInstance) { + $this->listInstance = $listInstance; + } + + /** + * Getter for the list instance + * + * @return $listInstance A list of Listable + */ + protected final function getListInstance () { + return $this->listInstance; + } } // [EOF]