Merge branch 'master' into tests
This commit is contained in:
@ -11,21 +11,21 @@
|
|||||||
|
|
||||||
abstract class Action
|
abstract class Action
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $template;
|
protected $template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var PHPView
|
* @var PHPView
|
||||||
*/
|
*/
|
||||||
protected $view;
|
protected $view;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->view = FrontController::getInstance()->getView();
|
$this->view = FrontController::getInstance()->getView();
|
||||||
$this->extractParams();
|
$this->extractParams();
|
||||||
$this->execute();
|
$this->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function extractParams()
|
protected function extractParams()
|
||||||
{
|
{
|
||||||
foreach (Env::getParam() as $name => $value) {
|
foreach (Env::getParam() as $name => $value) {
|
||||||
@ -34,12 +34,12 @@ abstract class Action
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected function execute();
|
abstract protected function execute();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redirect
|
* Redirect
|
||||||
*
|
*
|
||||||
* @param mixed $url
|
* @param mixed $url
|
||||||
*/
|
*/
|
||||||
protected function redirect($url = null)
|
protected function redirect($url = null)
|
||||||
@ -47,15 +47,15 @@ abstract class Action
|
|||||||
header('Location: ' . (($url) ? $url : Env::getRequestUri()));
|
header('Location: ' . (($url) ? $url : Env::getRequestUri()));
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetch()
|
public function fetch()
|
||||||
{
|
{
|
||||||
$this->view->assignObject($this);
|
$this->view->assignObject($this);
|
||||||
|
@ -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()
|
||||||
|
@ -11,18 +11,18 @@
|
|||||||
|
|
||||||
class ErrorAction extends Action
|
class ErrorAction extends Action
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ErrorException
|
* @var ErrorException
|
||||||
*/
|
*/
|
||||||
public $exception;
|
public $exception;
|
||||||
|
|
||||||
public function __construct($exception)
|
public function __construct($exception)
|
||||||
{
|
{
|
||||||
$this->exception = $exception;
|
$this->exception = $exception;
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function execute()
|
protected function execute()
|
||||||
{
|
{
|
||||||
$this->template = 500;
|
$this->template = 500;
|
||||||
@ -38,12 +38,12 @@ class ErrorAction extends Action
|
|||||||
$this->logError();
|
$this->logError();
|
||||||
$this->sendHTTPCode();
|
$this->sendHTTPCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getTemplate()
|
protected function getTemplate()
|
||||||
{
|
{
|
||||||
return '/actions/' . $this->template;
|
return '/actions/' . $this->template;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function sendHttpCode()
|
protected function sendHttpCode()
|
||||||
{
|
{
|
||||||
if (headers_sent()) {
|
if (headers_sent()) {
|
||||||
@ -67,7 +67,7 @@ class ErrorAction extends Action
|
|||||||
if ($ex instanceof ErrorException) {
|
if ($ex instanceof ErrorException) {
|
||||||
$error = $ex->getSeverity();
|
$error = $ex->getSeverity();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($error) {
|
switch ($error) {
|
||||||
case E_NOTICE:
|
case E_NOTICE:
|
||||||
$error = 'Notice';
|
$error = 'Notice';
|
||||||
|
@ -15,20 +15,20 @@ class FrontController
|
|||||||
* @var Router
|
* @var Router
|
||||||
*/
|
*/
|
||||||
protected $router;
|
protected $router;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $view = 'PHPView';
|
protected $view = 'PHPView';
|
||||||
|
|
||||||
protected $base_url = '';
|
protected $base_url = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var FrontController
|
* @var FrontController
|
||||||
*/
|
*/
|
||||||
protected static $instance;
|
protected static $instance;
|
||||||
|
|
||||||
|
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
ErrorHandler::init();
|
ErrorHandler::init();
|
||||||
@ -37,7 +37,7 @@ class FrontController
|
|||||||
}
|
}
|
||||||
$this->router = new Router();
|
$this->router = new Router();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refuse cloning
|
* Refuse cloning
|
||||||
*/
|
*/
|
||||||
@ -53,7 +53,7 @@ class FrontController
|
|||||||
}
|
}
|
||||||
return self::$instance;
|
return self::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $view
|
* @param string $view
|
||||||
* @return FrontController
|
* @return FrontController
|
||||||
@ -63,9 +63,9 @@ class FrontController
|
|||||||
$this->view = $view;
|
$this->view = $view;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return iView
|
* @return iView
|
||||||
*/
|
*/
|
||||||
public function getView($view = null)
|
public function getView($view = null)
|
||||||
@ -73,7 +73,7 @@ class FrontController
|
|||||||
$view = ($view) ? $view : $this->view;
|
$view = ($view) ? $view : $this->view;
|
||||||
return new $view(Config::get($view));
|
return new $view(Config::get($view));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $url
|
* @param string $url
|
||||||
*/
|
*/
|
||||||
@ -82,12 +82,12 @@ class FrontController
|
|||||||
$this->base_url = rtrim($url, '/');
|
$this->base_url = rtrim($url, '/');
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBaseUrl()
|
public function getBaseUrl()
|
||||||
{
|
{
|
||||||
return $this->base_url;
|
return $this->base_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Router
|
* @return Router
|
||||||
*/
|
*/
|
||||||
@ -95,7 +95,7 @@ class FrontController
|
|||||||
{
|
{
|
||||||
return $this->router;
|
return $this->router;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@ -104,18 +104,18 @@ class FrontController
|
|||||||
if (!$route) {
|
if (!$route) {
|
||||||
throw new Error404Exception('Route for "' . $request . '" not found');
|
throw new Error404Exception('Route for "' . $request . '" not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$action_class = $route->getAction();
|
$action_class = $route->getAction();
|
||||||
if (!class_exists($action_class)) {
|
if (!class_exists($action_class)) {
|
||||||
throw new GeneralException('Action class "' . $action_class . '" not found.');
|
throw new GeneralException('Action class "' . $action_class . '" not found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$action = new $action_class();
|
$action = new $action_class();
|
||||||
$layout_class = $route->getLayout();
|
$layout_class = $route->getLayout();
|
||||||
if (!class_exists($layout_class)) {
|
if (!class_exists($layout_class)) {
|
||||||
throw new GeneralException('Layout class "' . $layout_class . '" not found.');
|
throw new GeneralException('Layout class "' . $layout_class . '" not found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$layout = new $layout_class();
|
$layout = new $layout_class();
|
||||||
$html = $layout->fetch($action);
|
$html = $layout->fetch($action);
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
|
@ -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)
|
||||||
@ -45,10 +48,10 @@ class PagerAction extends Action
|
|||||||
{
|
{
|
||||||
return (int) $this->limit;
|
return (int) $this->limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,13 +11,13 @@
|
|||||||
|
|
||||||
abstract class StaticAction extends Action
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetch()
|
public function fetch()
|
||||||
{
|
{
|
||||||
return $this->view->fetch($this->getTemplate());
|
return $this->view->fetch($this->getTemplate());
|
||||||
|
7
cache/CacheKey.php
vendored
7
cache/CacheKey.php
vendored
@ -16,11 +16,12 @@ class CacheKey
|
|||||||
* @var Cacher
|
* @var Cacher
|
||||||
*/
|
*/
|
||||||
protected $cacher;
|
protected $cacher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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;
|
||||||
}
|
}
|
||||||
|
7
cache/Cacher.php
vendored
7
cache/Cacher.php
vendored
@ -11,15 +11,14 @@
|
|||||||
|
|
||||||
class Cacher
|
class Cacher
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialized cachers
|
* Initialized cachers
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
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])) {
|
||||||
|
@ -11,47 +11,49 @@
|
|||||||
|
|
||||||
class Captcha
|
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)
|
||||||
{
|
{
|
||||||
$font = dirname(__FILE__) . '/poh.ttf';
|
$font = dirname(__FILE__) . '/poh.ttf';
|
||||||
|
|
||||||
$image = imagecreatetruecolor($this->width, $this->height);
|
$image = imagecreatetruecolor($this->width, $this->height);
|
||||||
// белый фон
|
// белый фон
|
||||||
$background = imagecolorallocate($image, 255, 255, 255);
|
$background = imagecolorallocate($image, 255, 255, 255);
|
||||||
imagefilledrectangle($image, 0, 0, $this->width, $this->height, $background);
|
imagefilledrectangle($image, 0, 0, $this->width, $this->height, $background);
|
||||||
|
|
||||||
// основная магия тут
|
// основная магия тут
|
||||||
if (Session::get('_ctoken') == $token && Session::get('_ccode')) {
|
if (Session::get('_ctoken') == $token && Session::get('_ccode')) {
|
||||||
|
|
||||||
$code = Session::get('_ccode');
|
$code = Session::get('_ccode');
|
||||||
|
|
||||||
$color = imagecolorallocate($image, 81, 81, 81);
|
$color = imagecolorallocate($image, 81, 81, 81);
|
||||||
|
|
||||||
for ($j = 0; $j < 5; $j++) {
|
for ($j = 0; $j < 5; $j++) {
|
||||||
imageellipse($image, rand(-$this->width, $this->width * 2),
|
imageellipse($image, rand(-$this->width, $this->width * 2),
|
||||||
rand(-$this->height, $this->height * 2),
|
rand(-$this->height, $this->height * 2),
|
||||||
$this->width, $this->width, $color);
|
$this->width, $this->width, $color);
|
||||||
}
|
}
|
||||||
|
|
||||||
$letters = preg_split("//u", strtoupper($code));
|
$letters = preg_split("//u", strtoupper($code));
|
||||||
$length = count($letters);
|
$length = count($letters);
|
||||||
$step = floor($this->width / $length);
|
$step = floor($this->width / $length);
|
||||||
$i = 2;
|
$i = 2;
|
||||||
|
|
||||||
foreach ($letters as $key => $letter) {
|
foreach ($letters as $key => $letter) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||||
header("Content-Type: image/jpg");
|
header("Content-Type: image/jpg");
|
||||||
@ -59,7 +61,7 @@ class Captcha
|
|||||||
imagedestroy($image);
|
imagedestroy($image);
|
||||||
return ob_get_clean();
|
return ob_get_clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getToken()
|
public function getToken()
|
||||||
{
|
{
|
||||||
$token = md5(microtime() . uniqid());
|
$token = md5(microtime() . uniqid());
|
||||||
@ -68,10 +70,10 @@ class Captcha
|
|||||||
Session::set('_ccode', $code);
|
Session::set('_ccode', $code);
|
||||||
return $token;
|
return $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
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');
|
||||||
|
@ -11,11 +11,11 @@
|
|||||||
|
|
||||||
class CaptchaImageAction
|
class CaptchaImageAction
|
||||||
{
|
{
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$captcha = new Captcha();
|
$captcha = new Captcha();
|
||||||
echo $captcha->getImage(Env::Get('ctoken'));
|
echo $captcha->getImage(Env::Get('ctoken'));
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,9 +13,9 @@ class CaptchaValidator extends Validator
|
|||||||
{
|
{
|
||||||
|
|
||||||
const WRONG_CODE = 'is_empty';
|
const WRONG_CODE = 'is_empty';
|
||||||
|
|
||||||
protected $templates = array(self::WRONG_CODE => 'Entered code wrong');
|
protected $templates = array(self::WRONG_CODE => 'Entered code wrong');
|
||||||
|
|
||||||
public function isValid($value, $context = null)
|
public function isValid($value, $context = null)
|
||||||
{
|
{
|
||||||
if (!$context || !isset($context['ctoken']) || !isset($context['ccode'])) {
|
if (!$context || !isset($context['ctoken']) || !isset($context['ccode'])) {
|
||||||
|
@ -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>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -11,39 +11,39 @@
|
|||||||
|
|
||||||
class ErrorHandler
|
class ErrorHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
static public function init()
|
static public function init()
|
||||||
{
|
{
|
||||||
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);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static protected function getSource($file, $hiline)
|
static protected function getSource($file, $hiline)
|
||||||
{
|
{
|
||||||
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return implode('', $code);
|
return implode('', $code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static protected function wrapArray($array, $name)
|
static protected function wrapArray($array, $name)
|
||||||
{
|
{
|
||||||
if (!$array) {
|
if (!$array) {
|
||||||
@ -60,12 +60,12 @@ class ErrorHandler
|
|||||||
$text .= '</tbody></table>';
|
$text .= '</tbody></table>';
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
static protected function wrapTrace($trace)
|
static protected function wrapTrace($trace)
|
||||||
{
|
{
|
||||||
return '<code>' . nl2br($trace) . '</code>';
|
return '<code>' . nl2br($trace) . '</code>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Exception $exception
|
* @param Exception $exception
|
||||||
*/
|
*/
|
||||||
@ -73,22 +73,22 @@ class ErrorHandler
|
|||||||
{
|
{
|
||||||
ob_clean();
|
ob_clean();
|
||||||
$class = get_class($exception);
|
$class = get_class($exception);
|
||||||
|
|
||||||
$method = Env::Server('REQUEST_METHOD', '');
|
$method = Env::Server('REQUEST_METHOD', '');
|
||||||
$uri = Env::getRequestUri();
|
$uri = Env::getRequestUri();
|
||||||
$source = self::getSource($exception->getFile(), $exception->getLine());
|
$source = self::getSource($exception->getFile(), $exception->getLine());
|
||||||
$time = date('r', Env::Server('REQUEST_TIME', time()));
|
$time = date('r', Env::Server('REQUEST_TIME', time()));
|
||||||
|
|
||||||
$trace = nl2br($exception->getTraceAsString());
|
$trace = nl2br($exception->getTraceAsString());
|
||||||
|
|
||||||
$get = self::wrapArray(Env::Get(), 'GET');
|
$get = self::wrapArray(Env::Get(), 'GET');
|
||||||
$post = self::wrapArray(Env::Post(), 'POST');
|
$post = self::wrapArray(Env::Post(), 'POST');
|
||||||
$session = self::wrapArray(Session::get(), 'SESSION');
|
$session = self::wrapArray(Session::get(), 'SESSION');
|
||||||
$files = self::wrapArray(Env::Files(), 'FILES');
|
$files = self::wrapArray(Env::Files(), 'FILES');
|
||||||
$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>
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user