Browse Source

Merge branch 'master' into tests

master
Anton Terekhov 13 years ago
parent
commit
841e38da34
  1. 2
      app/Action.php
  2. 5
      app/AjaxAction.php
  3. 7
      app/PagerAction.php
  4. 2
      app/StaticAction.php
  5. 5
      cache/CacheKey.php
  6. 1
      cache/Cacher.php
  7. 10
      captcha/Captcha.php
  8. 66
      classes/MJException.class.php
  9. 12
      exception/ErrorHandler.php
  10. 2
      redis/RedisDebug.php
  11. 16
      util/profiler/Profiler.php

2
app/Action.php

@ -51,7 +51,7 @@ abstract class Action
protected function getTemplate() protected function getTemplate()
{ {
$class = get_class($this); $class = get_class($this);
$template = ($this->template) ? $this->template : substr($class, 0, -6/*strlen('Action')*/);
$template = ($this->template) ? $this->template : substr($class, 0, -6 /*strlen('Action')*/);
$dir = array_slice(explode('/', Load::getFilePath($class)), -2, 1); $dir = array_slice(explode('/', Load::getFilePath($class)), -2, 1);
return '/actions/' . array_pop($dir) . '/' . $template; return '/actions/' . array_pop($dir) . '/' . $template;
} }

5
app/AjaxAction.php

@ -12,11 +12,12 @@
*/ */
/** /**
* базовый класс для всей экшенов выполняющихся по аякс-запросу
*/
* базовый класс для всей экшенов выполняющихся по аякс-запросу
*/
abstract class AjaxAction extends Action abstract class AjaxAction extends Action
{ {
public $data = 1; public $data = 1;
protected $encode = true; protected $encode = true;
function __construct() function __construct()

7
app/PagerAction.php

@ -11,9 +11,12 @@
class PagerAction extends Action class PagerAction extends Action
{ {
public $page = 1;
public $page = 1;
public $last_page = 1; public $last_page = 1;
protected $offset = 0; protected $offset = 0;
protected $limit; protected $limit;
public function __construct($limit = 20) public function __construct($limit = 20)
@ -48,7 +51,7 @@ class PagerAction extends Action
protected function getTemplate() protected function getTemplate()
{ {
$template = ($this->template) ? $this->template : substr(get_class($this), 0, -6/*strlen('Action')*/);
$template = ($this->template) ? $this->template : substr(get_class($this), 0, -6 /*strlen('Action')*/);
return '/actions/' . $template; return '/actions/' . $template;
} }
} }

2
app/StaticAction.php

@ -14,7 +14,7 @@ abstract class StaticAction extends Action
protected function getTemplate() protected function getTemplate()
{ {
$template = ($this->template) ? $this->template : substr(get_class($this), 0, -6/*strlen('Action')*/);
$template = ($this->template) ? $this->template : substr(get_class($this), 0, -6 /*strlen('Action')*/);
return '/static/' . $template; return '/static/' . $template;
} }

5
cache/CacheKey.php

@ -21,6 +21,7 @@ class CacheKey
* @var CacheKey * @var CacheKey
*/ */
protected $key; protected $key;
protected $expire = 0; protected $expire = 0;
/** /**
@ -32,11 +33,11 @@ class CacheKey
*/ */
public function __construct($cacher, $key, $params = array(), $expire = 0) public function __construct($cacher, $key, $params = array(), $expire = 0)
{ {
$this->cacher = $cacher;
$this->cacher = $cacher;
$this->key = $key; $this->key = $key;
if ($params) { if ($params) {
$params = (is_array($params)) ? implode('|', $params) : $params; $params = (is_array($params)) ? implode('|', $params) : $params;
$this->key = $key . '_' . $params;
$this->key = $key . '_' . $params;
} }
$this->expire = $expire; $this->expire = $expire;
} }

1
cache/Cacher.php

@ -19,7 +19,6 @@ class Cacher
*/ */
static protected $caches = array(); static protected $caches = array();
static public function get($cacher, $config = null) static public function get($cacher, $config = null)
{ {
if (!isset(self::$caches[$cacher])) { if (!isset(self::$caches[$cacher])) {

10
captcha/Captcha.php

@ -13,8 +13,10 @@ class Captcha
{ {
protected $font_size = 38; protected $font_size = 38;
protected $width = 200;
protected $height = 70;
protected $width = 200;
protected $height = 70;
public function getImage($token) public function getImage($token)
@ -48,7 +50,7 @@ class Captcha
imagettftext($image, $this->font_size, 0, imagettftext($image, $this->font_size, 0,
rand($i + 2, $i + 4), ($this->font_size + $this->height) / 2, rand($i + 2, $i + 4), ($this->font_size + $this->height) / 2,
$color, $font, $letter); $color, $font, $letter);
$i = $i + $step ;
$i = $i + $step;
} }
} }
@ -71,7 +73,7 @@ class Captcha
public function checkCode($token, $code) public function checkCode($token, $code)
{ {
if (Session::get('_ctoken') == $token && Session::get('_ccode') == strtoupper($code)){
if (Session::get('_ctoken') == $token && Session::get('_ccode') == strtoupper($code)) {
// Housekeeping // Housekeeping
Session::del('_ccode'); Session::del('_ccode');
Session::del('_ctoken'); Session::del('_ctoken');

66
classes/MJException.class.php

@ -1,66 +0,0 @@
<?php
/**
* Обработчик эксепшенов
*
* @copyright NetMonsters <team@netmonsters.ru>
* @link
* @package Majestic
* @subpackage Core
* @since
* @version SVN: $Id$
* @filesource $URL$
*/
class MJException extends Exception
{
private $line_range = 6;
public function terminate()
{
if (!DEBUG_ENABLE) {
trigger_error($this->getMessage());
throw new StaticPageException(500);
}
$return = "<b>MJ Error:</b> ";
$return .= str_replace("\n", "<br/>\n", $this->getMessage())."<br>\n";
$trace = $this->getTrace();
$file = reset($trace);
//смещение в трейсе, указаное при вызове эксепшена (2й параметр). Нужно для более инофрмативного вывода
if ($shift = abs($this->getCode())) {
while($shift--) {
$file = next($trace);
}
}
if ($fp = fopen($file['file'], 'r')) {
$error_line = $file['line'];
$start = $error_line - $this->line_range;
$end = $error_line + $this->line_range;
$i = 1;
$return .= "<pre style=\"background-color:#e4e4e4\">";
while ($line = fgets($fp, 4096) and $i<=$end) {
$line = htmlspecialchars($line);
if ($i >= $start && $i <= $end) {
if ($i == $error_line) $return .= '<div style="background-color:#cccccc">'.$i.' '.$line.'</div>';
else $return .= $i.' '.$line;
}
$i++;
}
$return .= "</pre>";
fclose($fp);
}
$return .= '<table border="1" cellpadding="2" cellspacing="0"> <caption><b>Backtrace</b></caption>';
$return .= "\n<tr><td><b>".$this->getFile().'</b></td><td><b>'.$this->getLine().'</b></td></tr>';
foreach($trace as $row) {
if (isset($row['file'])) { //throwing exception from __call method will not return file and line
$return .= "\n<tr".($file['file'] == $row['file'] ? ' style="background-color:#ffcccc"': '')."><td>".$row['file'].'</td><td>'.$row['line'].'</td></tr>';
}
}
return $return . '</table>';
}
}
?>

12
exception/ErrorHandler.php

@ -17,7 +17,7 @@ class ErrorHandler
set_error_handler(array('ErrorHandler', 'error_handler')); set_error_handler(array('ErrorHandler', 'error_handler'));
} }
static public function error_handler($errno, $errstr, $errfile, $errline )
static public function error_handler($errno, $errstr, $errfile, $errline)
{ {
ob_clean(); ob_clean();
throw new ErrorException($errstr, 0, $errno, $errfile, $errline); throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
@ -28,16 +28,16 @@ class ErrorHandler
{ {
$code = array(); $code = array();
$i = 0; $i = 0;
foreach(file($file) as $line) {
foreach (file($file) as $line) {
$i++; $i++;
if($i >= $hiline - 10 && $i <= $hiline + 10) {
if ($i >= $hiline - 10 && $i <= $hiline + 10) {
if ($i == $hiline) { if ($i == $hiline) {
$code[] = '<tr class="error"><th>' . $i . '</th><td><span class="specific">' . htmlentities($line, ENT_QUOTES, 'UTF-8') . '</span></td></tr>'; $code[] = '<tr class="error"><th>' . $i . '</th><td><span class="specific">' . htmlentities($line, ENT_QUOTES, 'UTF-8') . '</span></td></tr>';
}else{
} else {
$code[] = '<tr><th>' . $i . '</th><td>' . htmlentities($line, ENT_QUOTES, 'UTF-8') . '</td></tr>'; $code[] = '<tr><th>' . $i . '</th><td>' . htmlentities($line, ENT_QUOTES, 'UTF-8') . '</td></tr>';
} }
} }
if($i > $hiline + 10) {
if ($i > $hiline + 10) {
break; break;
} }
} }
@ -88,7 +88,7 @@ class ErrorHandler
$cookies = self::wrapArray(Env::Cookie(), 'COOKIE'); $cookies = self::wrapArray(Env::Cookie(), 'COOKIE');
$server = self::wrapArray(Env::Server(), 'SERVER'); $server = self::wrapArray(Env::Server(), 'SERVER');
$message =<<<EOD
$message = <<<EOD
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>

2
redis/RedisDebug.php

@ -16,7 +16,7 @@ class RedisDebug
public function __construct($redis) public function __construct($redis)
{ {
if (!is_a($redis, 'Redis')) { if (!is_a($redis, 'Redis')) {
throw new MJException();
throw new GeneralException();
} }
$this->redis = $redis; $this->redis = $redis;
} }

16
util/profiler/Profiler.php

@ -101,4 +101,20 @@ class Profiler
} }
FB::table('Queries: ' . count($this->queries) . ' [' . round($queriesTime * 1000, 2) . ' ms]', $table); FB::table('Queries: ' . count($this->queries) . ' [' . round($queriesTime * 1000, 2) . ' ms]', $table);
} }
public function getCli()
{
$this->end = microtime(true);
$queriesTime = 0;
$temp = str_pad(PHP_EOL, 60, '-', STR_PAD_LEFT);
foreach ($this->queries as $query) {
$temp .= sprintf('%-25s[% 10sms] %s', '(' . $query->getType() .')', round($query->getElapsed() * 1000, 2), $query->getCommand()) . PHP_EOL;
$queriesTime += $query->getElapsed();
}
$html = str_pad(PHP_EOL, 60, '-', STR_PAD_LEFT);
$html .= 'Elapsed time: ' . round(($this->end - $this->start) * 1000, 2) . 'ms.' . PHP_EOL
. 'Queries: ' . count($this->queries) . ' [' . round($queriesTime * 1000, 2) . ' ms] ' . PHP_EOL;
$html .= $temp;
return $html;
}
} }
Loading…
Cancel
Save