コード例 #1
0
ファイル: Error.php プロジェクト: hmc-soft/mvc
 /**
  * Show an error message to the user and log the error if needed.
  * Current 404 errors are not logged. This function ends execution.
  * @param $errNum int the HTTP error code to return, typically 404 for missing page or 500.
  * @param $info string (optional) with the message to log, not displayed in production.
  */
 public static function showError($errNum, $info = null)
 {
     Language::load('Errors');
     ob_get_clean();
     $defError = Language::tr('500_default_error');
     switch ($errNum) {
         case 404:
             Error::error404();
             die;
             break;
         case 500:
         default:
             break;
     }
     if ($info != null) {
         Logger::error('[' . $errNum . '] ' . strip_tags($info));
     }
     $data['title'] = Language::tr('500_title');
     $data['error'] = $info != null ? Config::SITE_ENVIRONMENT() == 'development' ? $defError . '<br/>' . $info : $defError : $defError;
     View::addHeader("HTTP/1.0 500 Internal Server Error");
     View::renderTemplate('header', $data);
     View::render('error/500', $data);
     View::renderTemplate('footer', $data);
     die;
 }
コード例 #2
0
ファイル: Logger.php プロジェクト: hmc-soft/mvc
 /**
  * saves error message from exception
  * @param  numeric $number  error number
  * @param  string $message the error
  * @param  string $file    file originated from
  * @param  numeric $line   line number
  */
 public static function errorHandler($number, $message, $file, $line)
 {
     if (Config::SITE_ENVIRONMENT() == 'development') {
         Error::showError(500, '(' . $number . ') ' . $file . ':' . $line . ' => ' . $message);
         die;
     }
     $msg = "{$message} in {$file} on line {$line}";
     if (self::$logger != null) {
         self::error($number . $msg);
     } else {
         if ($number !== E_NOTICE && $number < 2048) {
             self::errorMessage($msg);
             self::customErrorMsg();
         }
     }
     return 0;
 }
コード例 #3
0
ファイル: Assets.php プロジェクト: hmc-soft/mvc
 /**
  * Output optimized stylesheet.
  * This function will combine multiple stylesheets into a single sheet.
  * It will also perform some basic optimizations to reduce download size.
  * @param $files - array of files to include
  * @param $outputdir - where to store generated file(s), default is typically adequate.
  */
 public static function combine_css($files, $outputdir = 'static/generated/')
 {
     if (\HMC\Config::SITE_ENVIRONMENT() == 'development') {
         Assets::css($files);
         return;
     }
     $ofiles = is_array($files) ? $files : array($files);
     $hashFileName = md5(join($ofiles));
     $dirty = false;
     if (file_exists($outputdir . $hashFileName . '.css')) {
         $hfntime = filemtime($outputdir . $hashFileName . '.css');
         foreach ($ofiles as $vfile) {
             $file = str_replace(\HMC\Config::SITE_URL(), \HMC\Config::SITE_PATH(), $vfile);
             if (!$dirty) {
                 $fmtime = filemtime($file);
                 if ($fmtime > $hfntime) {
                     $dirty = true;
                 }
             }
         }
     } else {
         $dirty = true;
     }
     if ($dirty) {
         $buffer = "";
         foreach ($ofiles as $vfile) {
             $cssFile = str_replace(\HMC\Config::SITE_URL(), \HMC\Config::SITE_PATH(), $vfile);
             $buffer .= "\n" . file_get_contents($cssFile);
         }
         // Remove comments
         $buffer = preg_replace('!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!', '', $buffer);
         // Remove space after colons
         $buffer = str_replace(': ', ':', $buffer);
         // Remove whitespace
         $buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);
         ob_start();
         // Write everything out
         echo $buffer;
         $fc = ob_get_clean();
         file_put_contents(\HMC\Config::SITE_PATH() . $outputdir . $hashFileName . '.css', $fc);
     }
     static::resource(str_replace(':||', '://', str_replace('//', '/', str_replace('://', ':||', \HMC\Config::SITE_URL() . $outputdir . $hashFileName . '.css'))), 'css');
 }