PageRenderTime 25ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/osCommerce/OM/Core/Site/Shop/Module/Service/Debug.php

http://github.com/osCommerce/oscommerce
PHP | 83 lines | 60 code | 17 blank | 6 comment | 31 complexity | cf7cc03578e0f26a086c3aaa8882b3ac MD5 | raw file
  1. <?php
  2. /**
  3. * osCommerce Online Merchant
  4. *
  5. * @copyright Copyright (c) 2011 osCommerce; http://www.oscommerce.com
  6. * @license BSD License; http://www.oscommerce.com/bsdlicense.txt
  7. */
  8. namespace osCommerce\OM\Core\Site\Shop\Module\Service;
  9. use osCommerce\OM\Core\Registry;
  10. use osCommerce\OM\Core\OSCOM;
  11. class Debug implements \osCommerce\OM\Core\Site\Shop\ServiceInterface {
  12. public static function start() {
  13. $OSCOM_Language = Registry::get('Language');
  14. $OSCOM_MessageStack = Registry::get('MessageStack');
  15. if ( SERVICE_DEBUG_CHECK_LOCALE == '1' ) {
  16. $setlocale = setlocale(LC_TIME, explode(',', $OSCOM_Language->getLocale()));
  17. if ( ($setlocale === false) || ($setlocale === null) ) {
  18. $OSCOM_MessageStack->add('debug', 'Error: Locale does not exist: ' . $OSCOM_Language->getLocale(), 'error');
  19. }
  20. }
  21. if ( (SERVICE_DEBUG_CHECK_INSTALLATION_MODULE == '1') && file_exists(OSCOM::BASE_DIRECTORY . 'Core/Site/Setup') ) {
  22. $OSCOM_MessageStack->add('debug', sprintf(OSCOM::getDef('warning_install_directory_exists'), OSCOM::BASE_DIRECTORY . 'Core/Site/Setup'), 'warning');
  23. }
  24. if ( (SERVICE_DEBUG_CHECK_CONFIGURATION == '1') && is_writeable(OSCOM::BASE_DIRECTORY . 'Config/settings.ini') ) {
  25. $OSCOM_MessageStack->add('debug', sprintf(OSCOM::getDef('warning_config_file_writeable'), OSCOM::BASE_DIRECTORY . 'Config//settings.ini'), 'warning');
  26. }
  27. if ( (SERVICE_DEBUG_CHECK_SESSION_DIRECTORY == '1') && (OSCOM::getConfig('store_sessions') == '') ) {
  28. if ( !is_dir(OSCOM_Registry::get('Session')->getSavePath()) ) {
  29. $OSCOM_MessageStack->add('debug', sprintf(OSCOM::getDef('warning_session_directory_non_existent'), OSCOM_Registry::get('Session')->getSavePath()), 'warning');
  30. } elseif ( !is_writeable(OSCOM_Registry::get('Session')->getSavePath()) ) {
  31. $OSCOM_MessageStack->add('debug', sprintf(OSCOM::getDef('warning_session_directory_not_writeable'), OSCOM_Registry::get('Session')->getSavePath()), 'warning');
  32. }
  33. }
  34. if ( (SERVICE_DEBUG_CHECK_SESSION_AUTOSTART == '1') && (bool)ini_get('session.auto_start') ) {
  35. $OSCOM_MessageStack->add('debug', OSCOM::getDef('warning_session_auto_start'), 'warning');
  36. }
  37. if ( (SERVICE_DEBUG_CHECK_DOWNLOAD_DIRECTORY == '1') && (DOWNLOAD_ENABLED == '1') ) {
  38. if ( !is_dir(DIR_FS_DOWNLOAD) ) {
  39. $OSCOM_MessageStack->add('debug', sprintf(OSCOM::getDef('warning_download_directory_non_existent'), DIR_FS_DOWNLOAD), 'warning');
  40. }
  41. }
  42. return true;
  43. }
  44. public static function stop() {
  45. $OSCOM_MessageStack = Registry::get('MessageStack');
  46. $OSCOM_Template = Registry::get('Template');
  47. $time_start = explode(' ', OSCOM_TIMESTAMP_START);
  48. $time_end = explode(' ', microtime());
  49. $parse_time = number_format(($time_end[1] + $time_end[0] - ($time_start[1] + $time_start[0])), 3);
  50. if ( strlen(SERVICE_DEBUG_EXECUTION_TIME_LOG) > 0 ) {
  51. if ( !error_log(strftime('%c') . ' - ' . $_SERVER['REQUEST_URI'] . ' (' . $parse_time . 's)' . "\n", 3, SERVICE_DEBUG_EXECUTION_TIME_LOG)) {
  52. if ( !file_exists(SERVICE_DEBUG_EXECUTION_TIME_LOG) || !is_writable(SERVICE_DEBUG_EXECUTION_TIME_LOG) ) {
  53. $OSCOM_MessageStack->add('debug', 'Error: Execution time log file not writeable: ' . SERVICE_DEBUG_EXECUTION_TIME_LOG, 'error');
  54. }
  55. }
  56. }
  57. if ( SERVICE_DEBUG_EXECUTION_DISPLAY == '1' ) {
  58. $OSCOM_MessageStack->add('debug', 'Execution Time: ' . $parse_time . 's', 'warning');
  59. }
  60. if ( $OSCOM_Template->showDebugMessages() && $OSCOM_MessageStack->exists('debug') ) {
  61. echo $OSCOM_MessageStack->get('debug');
  62. }
  63. return true;
  64. }
  65. }
  66. ?>