/** * Set the default registry instance to a specified instance. * * @param PPI_Registry $registry An object instance of type PPI_Registry * @return void * @throws PPI_Exception if registry is already initialized. */ public static function setInstance(PPI_Registry $registry) { if (self::$_instance !== null) { throw new PPI_Exception('Registry is already initialized'); } self::$_instance = $registry; }
/** * The default exception handler * * @param object $oException The exception object * @return void */ function ppi_exception_handler($oException) { if (!$oException instanceof Exception) { return false; } $error = array(); foreach (array('code', 'message', 'file', 'line', 'traceString') as $field) { $fieldName = "_{$field}"; if (!property_exists($oException, $fieldName)) { continue; } if ($field == 'traceString') { $error['backtrace'] = $oException->{$fieldName}; } else { $error[$field] = $oException->{$fieldName}; } } try { if (!PPI_Registry::getInstance()->exists('PPI_Config')) { $oException->show_exceptioned_error($error); return; } $oConfig = PPI_Helper::getConfig(); $error['sql'] = PPI_Helper::getRegistry()->get('PPI_Model::PPI_Model_Queries', array()); // email the error with the backtrace information to the developer if (!isset($oConfig->system->log_errors) || $oConfig->system->log_errors != false) { // get the email contents $emailContent = $oException instanceof PPI_Exception ? $oException->getErrorForEmail($error) : ''; $oLog = new PPI_Model_Log(); $oLog->addExceptionLog(array('code' => $oException->_code, 'message' => $oException->_message, 'file' => $oException->_file, 'line' => $oException->_line, 'backtrace' => $error['backtrace'], 'post' => serialize($_POST), 'cookie' => serialize($_COOKIE), 'get' => serialize($_GET), 'session' => serialize($_SESSION), 'content' => $emailContent)); if ($oConfig->system->email_errors) { //@mail($oConfig->system->developer_email, 'PHP Exception For '.getHostname(), $emailContent); //include CORECLASSPATH.'mail.php'; //$mail = new Mail(); //$mail->send(); } // write the error to the php error log writeErrorToLog($error['message'] . ' in file: ' . $error['file'] . ' on line: ' . $error['line']); $oException->show_exceptioned_error($error); } } catch (PPI_Exception $e) { writeErrorToLog($e->getMessage()); } catch (Exception $e) { writeErrorToLog($e->getMessage()); } catch (PDOException $e) { writeErrorToLog($e->getMessage()); } $oException->show_exceptioned_error($error); // @todo This should go to an internal error page which doesn't use framework components and show the error code // ppi_show_exceptioned_error($error); }
/** * Get the registry object * * @return object */ static function getRegistry() { return PPI_Registry::getInstance(); }
/** * Check if the database has been installed */ function is_db_installed() { $config = PPI_Registry::getInstance()->get('config'); $oUser = new PPI_Model_User(); $rows = $oUser->query('SELECT ' . $config->system->defaultUserTable . ' FROM ' . $config->system->defaultUserTable . ' LIMIT 1'); return count($rows) > 0; }
/** * Call the dispatch process. Running the dispatcher and dispatching * * @return $this Fluent interface */ function dispatch() { // Fire up the default dispatcher if ($this->_dispatcher === null) { $this->_dispatcher = new PPI_Dispatch_Standard(array('router' => $this->_router)); } $dispatch = new PPI_Dispatch($this->_dispatcher); PPI_Registry::getInstance()->set('PPI_Dispatch', $dispatch); $dispatch->dispatch(); return $this; }