Browse Source

Merge branch 'ajax_action'

master
Anton Terekhov 12 years ago
parent
commit
c65ce706a9
  1. 2
      Config.php
  2. 2
      Load.php
  3. 2
      Registry.php
  4. 2
      app/Action.php
  5. 29
      app/AjaxAction.php
  6. 10
      app/CliController.php
  7. 43
      app/ErrorAction.php
  8. 17
      app/FrontController.php
  9. 2
      app/PagerAction.php
  10. 2
      app/StaticAction.php
  11. 3
      app/router/Route.php
  12. 21
      app/router/Router.php
  13. 5
      cache/Cache.php
  14. 5
      cache/CacheKey.php
  15. 8
      cache/Cacher.php
  16. 11
      cache/MemcacheCache.php
  17. 2
      captcha/Captcha.php
  18. 2
      captcha/CaptchaImageAction.php
  19. 2
      captcha/CaptchaValidator.php
  20. 2
      classes/Env.class.php
  21. 6
      classes/Format.class.php
  22. 3
      classes/User.class.php
  23. 9
      exception/Error404Exception.php
  24. 39
      exception/ErrorHTTPException.php
  25. 3
      exception/ErrorHandler.php
  26. 2
      exception/GeneralException.php
  27. 34
      form/Form.php
  28. 51
      form/FormField.php
  29. 2
      form/FormViewHelper.php
  30. 5
      i18n/I18N.php
  31. 2
      layout/Error.layout.php
  32. 8
      layout/Layout.php
  33. 3
      logger/FileLogger.php
  34. 2
      mail/Mailer.php
  35. 2
      model/Db.php
  36. 2
      model/DbDriver.php
  37. 2
      model/DbExpr.php
  38. 2
      model/DbStatement.php
  39. 2
      model/Model.php
  40. 1
      model/MongoStatement.php
  41. 2
      model/MySQLiDriver.php
  42. 2
      model/MySQLiStatement.php
  43. 2
      redis/RedisDebug.php
  44. 5
      redis/RedisManager.php
  45. 3
      redis/redis.php
  46. 2
      session/Session.model.php
  47. 2
      session/Session.php
  48. 5
      tests/LoadTest.php
  49. 15
      tests/app/Action_TestCase.php
  50. 48
      tests/app/AjaxActionTest.php
  51. 1
      tests/app/CliControllerTest.php
  52. 41
      tests/app/ErrorActionTest.php
  53. 66
      tests/app/FrontControllerTest.php
  54. 11
      tests/exception/Error404ExceptionTest.php
  55. 106
      tests/exception/ErrorHTTPExceptionTest.php
  56. 2
      tests/form/FormFieldTest.php
  57. 6
      tests/view/helpers/BreadcrumbVeiwHelperTest.php
  58. 4
      tests/view/helpers/GetViewHelperTest.php
  59. 3
      tests/view/helpers/HeadViewHelperTest.php
  60. 32
      tests/view/helpers/MsgViewHelperTest.php
  61. 4
      tests/view/helpers/TitleViewHelperTest.php
  62. 16
      util/AutoloadBuilder.php
  63. 2
      util/profiler/CommandProfiler.php
  64. 11
      util/profiler/Profiler.php
  65. 2
      validator/EmailValidator.php
  66. 2
      validator/EqualValidator.php
  67. 2
      validator/NotEmptyValidator.php
  68. 2
      validator/RegexValidator.php
  69. 2
      validator/Validator.php
  70. 2
      validator/iValidator.php
  71. 16
      view/PHPView.php
  72. 2
      view/helpers/BreadcrumbViewHelper.php
  73. 4
      view/helpers/GetViewHelper.php
  74. 2
      view/helpers/HeadViewHelper.php
  75. 40
      view/helpers/MsgViewHelper.php
  76. 2
      view/helpers/TitleViewHelper.php
  77. 2
      view/helpers/ViewHelper.php
  78. 2
      view/iView.php

2
Config.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage Model
* @since 2010-02-17
* @version SVN: $Id$
* @filesource $URL$
*/
class Config extends Registry

2
Load.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage Load
* @since 2010-02-24
* @version SVN: $Id$
* @filesource $URL$
*/
class Load

2
Registry.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage Model
* @since 2010-02-17
* @version SVN: $Id$
* @filesource $URL$
*/
class Registry extends ArrayObject

2
app/Action.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage app
* @since 2010-02-25
* @version SVN: $Id$
* @filesource $URL$
*/
abstract class Action

29
app/AjaxAction.php

@ -3,22 +3,28 @@
* AjaxAction
*
* @copyright NetMonsters <team@netmonsters.ru>
* @link
* @link http://netmonsters.ru
* @package Majestic
* @subpackage face
* @since
* @version SVN: $Id$
* @filesource $URL$
* @subpackage app
* @since 2011-04-27
*/
/**
* базовый класс для всей экшенов выполняющихся по аякс-запросу
* Base class for all ajax Actions
*/
abstract class AjaxAction extends Action
{
public $data = 1;
/**
* Data to output
* @var mixed
*/
public $data = false;
protected $encode = true;
/**
* Use json_encode
* @var bool
*/
protected $json_encode = true;
function __construct()
{
@ -28,10 +34,13 @@ abstract class AjaxAction extends Action
function fetch()
{
// header("Content-type: application/json; charset=utf-8");
if ($this->json_encode === true) {
header("Content-type: application/json; charset=utf-8");
} else {
header("Content-type: text/html; charset=utf-8");
}
header("Cache-Control: no-store, no-cache, must-revalidate");
$this->view->assign('data', $this->encode ? json_encode($this->data) : $this->data);
$this->view->assign('data', $this->json_encode ? json_encode($this->data) : $this->data);
return $this->view->fetch($this->getTemplate());
}
}

10
app/CliController.php

@ -28,6 +28,13 @@ class CliController
}
/**
* Refuse cloning
*/
private function __clone()
{
}
/**
* @static
* @return CliController
*/
@ -58,7 +65,8 @@ class CliController
echo $profile;
}
}
} catch (Exception $e) {
}
catch (Exception $e) {
$code = $e->getCode();
if ($e instanceof ErrorException) {
$code = $e->getSeverity();

43
app/ErrorAction.php

@ -5,18 +5,18 @@
* @package Majestic
* @subpackage app
* @since 2010-02-25
* @version SVN: $Id$
* @filesource $URL$
*/
class ErrorAction extends Action
{
/**
* @var ErrorException
* @var ErrorException|ErrorHTTPException
*/
public $exception;
protected $ajax_error = false;
public function __construct($exception)
{
$this->exception = $exception;
@ -27,18 +27,22 @@ class ErrorAction extends Action
{
$this->template = 500;
if ($this->exception instanceof Error404Exception) {
if ($this->isAjaxActionError()) {
if (!headers_sent()) {
header('HTTP/1.0 404 Not Found');
die();
}
}
$this->template = 404;
} elseif ($this->exception instanceof ErrorHTTPException) {
$this->template = 'HTTP';
}
$this->logError();
$this->sendHTTPCode();
}
public function fetch()
{
if ($this->isAjaxActionError()) {
return $this->exception->getMessage();
}
return parent::fetch();
}
protected function getTemplate()
{
return '/actions/' . $this->template;
@ -46,12 +50,10 @@ class ErrorAction extends Action
protected function sendHttpCode()
{
if (headers_sent()) {
return;
}
switch ($this->template) {
case 404:
header('HTTP/1.0 404 Not Found');
case 'HTTP':
header($this->exception->getHTTPHeader());
break;
default:
header('HTTP/1.0 500 Internal Server Error');
@ -61,7 +63,6 @@ class ErrorAction extends Action
protected function logError()
{
if ($this->template == 500) {
$error = 0;
$ex = $this->exception;
if ($ex instanceof ErrorException) {
@ -94,12 +95,14 @@ class ErrorAction extends Action
*/
protected function isAjaxActionError()
{
$trace = $this->exception->getTrace();
foreach ($trace as $line) {
if (isset($line['class']) && $line['class'] === 'AjaxAction') {
return true;
}
return $this->ajax_error;
}
return false;
/**
* Set if exception was thrown from AjaxAction subclass
*/
public function setAjaxError()
{
$this->ajax_error = true;
}
}

17
app/FrontController.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage app
* @since 2010-02-24
* @version SVN: $Id$
* @filesource $URL$
*/
class FrontController
@ -65,6 +63,7 @@ class FrontController
/**
*
* @param null $view
* @return iView
*/
public function getView($view = null)
@ -75,6 +74,7 @@ class FrontController
/**
* @param string $url
* @return FrontController
*/
public function setBaseUrl($url)
{
@ -115,6 +115,9 @@ class FrontController
throw new GeneralException('Layout class "' . $layout_class . '" not found.');
}
/**
* @var Layout $layout
*/
$layout = new $layout_class();
$html = $layout->fetch($action);
if (Config::get('PROFILER')) {
@ -128,8 +131,12 @@ class FrontController
} catch (Exception $e) {
if (Config::get('DEBUG')) {
if (!headers_sent()) {
if ($e instanceof ErrorHTTPException) {
header($e->getHTTPHeader());
} else {
header('HTTP/1.0 500 Internal Server Error');
}
}
return ErrorHandler::showDebug($e);
}
$layout_class = $this->getRouter()->getErrorLayout();
@ -139,7 +146,11 @@ class FrontController
*/
$layout = new $layout_class();
$layout->setException($e);
return $layout->fetch(new ErrorAction($e));
$error_action = new ErrorAction($e);
if (isset($action_class) && is_subclass_of($action_class, 'AjaxAction')) {
$error_action->setAjaxError();
}
return $layout->fetch($error_action);
}
}
}

2
app/PagerAction.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage app
* @since 2010-03-07
* @version SVN: $Id$
* @filesource $URL$
*/
class PagerAction extends Action

2
app/StaticAction.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage app
* @since 2010-02-25
* @version SVN: $Id$
* @filesource $URL$
*/
abstract class StaticAction extends Action

3
app/router/Route.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage app
* @since 2010-02-25
* @version SVN: $Id$
* @filesource $URL$
*/
class Route
@ -27,6 +25,7 @@ class Route
/**
* @param array $request
* @return bool
*/
public function match($request)
{

21
app/router/Router.php

@ -5,15 +5,18 @@
* @package Majestic
* @subpackage app
* @since 2010-02-25
* @version SVN: $Id$
* @filesource $URL$
*/
class Router
{
/**
* @var Route[]
*/
protected $routes = array();
/**
* @var string
*/
protected $route_name;
protected $default_layout = 'Default';
@ -33,6 +36,10 @@ class Router
$this->routes[$name] = new Route($route, $action, $params, $layout);
}
/**
* @param $request
* @return bool|Route
*/
public function route($request)
{
$req = explode('/', trim($request, '/'));
@ -48,6 +55,10 @@ class Router
return false;
}
/**
* Set default layout name
* @param string $layout
*/
public function setDefaultLayout($layout = 'Default')
{
$this->default_layout = $layout;
@ -71,6 +82,10 @@ class Router
return $this->error_layout . 'Layout';
}
/**
* Return current router name
* @return string
*/
public function getRouteName()
{
return $this->route_name;

5
cache/Cache.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage Cache
* @since 2010-03-04
* @version SVN: $Id$
* @filesource $URL$
*/
abstract class Cache
@ -35,7 +33,6 @@ abstract class Cache
* Delete item from the cache
*
* @param string $key
* @param int $value
* @return bool
*/
abstract public function del($key);
@ -68,7 +65,7 @@ abstract class Cache
* Replace value of the existing item
*
* @param string $key
* @param mixed $var
* @param mixed $value
* @param int $expire
* @return bool
*/

5
cache/CacheKey.php

@ -5,15 +5,13 @@
* @package Majestic
* @subpackage Cache
* @since 2010-03-10
* @version SVN: $Id$
* @filesource $URL$
*/
class CacheKey
{
/**
* @var Cacher
* @var Cache
*/
protected $cacher;
@ -62,6 +60,7 @@ class CacheKey
/**
* @param mixed $value
* @return bool
*/
public function set($value)
{

8
cache/Cacher.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage Cache
* @since 2010-03-04
* @version SVN: $Id$
* @filesource $URL$
*/
class Cacher
@ -19,6 +17,12 @@ class Cacher
*/
static protected $caches = array();
/**
* @param $cacher
* @param null|string $config
* @return Cache
* @throws InitializationException
*/
static public function get($cacher, $config = null)
{
if (!isset(self::$caches[$cacher])) {

11
cache/MemcacheCache.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage Cache
* @since 2010-03-04
* @version SVN: $Id$
* @filesource $URL$
*/
class MemcacheCache extends Cache
@ -17,6 +15,9 @@ class MemcacheCache extends Cache
*/
protected $connection = null;
/**
* @var null|string
*/
protected $key_salt = null;
/**
@ -26,7 +27,6 @@ class MemcacheCache extends Cache
*/
protected $expire = 3600;
public function __construct($config)
{
$this->connection = new Memcache();
@ -76,7 +76,7 @@ class MemcacheCache extends Cache
* Delete item from the cache
*
* @param string $key
* @param int $value
* @internal param int $value
* @return bool
*/
public function del($key)
@ -121,8 +121,9 @@ class MemcacheCache extends Cache
* Replace value of the existing item
*
* @param string $key
* @param mixed $var
* @param mixed $value
* @param int $expire
* @internal param mixed $var
* @return bool
*/
public function replace($key, $value, $expire = 0)

2
captcha/Captcha.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage captcha
* @since 2010-04-24
* @version SVN: $Id$
* @filesource $URL$
*/
class Captcha

2
captcha/CaptchaImageAction.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage captcha
* @since 2010-04-24
* @version SVN: $Id$
* @filesource $URL$
*/
class CaptchaImageAction

2
captcha/CaptchaValidator.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage validator
* @since 2010-04-26
* @version SVN: $Id$
* @filesource $URL$
*/
class CaptchaValidator extends Validator

2
classes/Env.class.php

@ -7,8 +7,6 @@
* @package Majestic
* @subpackage env
* @since
* @version SVN: $Id$
* @filesource $URL$
*/
class Env

6
classes/Format.class.php

@ -7,8 +7,6 @@
* @package Majestic
* @subpackage Core
* @since 24.12.2008
* @version SVN: $Id$
* @filesource $URL$
*/
/**
@ -47,6 +45,7 @@ class Format
* @param mixed $int
* @param bool $currency - показывать валюту
* @param bool $show_decimals - показывать или нет дробную часть
* @return string
*/
static public function int2money($int = 0, $currency = false, $show_decimals = true)
{
@ -169,7 +168,7 @@ class Format
* Преобразует дату в таймстамп.
*
* @param mixed $time
* @return TimeFormat
* @return int|bool
*/
static public function date2int($time)
{
@ -228,4 +227,3 @@ class Format
* Оффсет с учетом летнего/зимнего времени
*/
Format::setTimezoneOffset(date('Z') - ((date('I') ? 60*60 : 0 )));
?>

3
classes/User.class.php

@ -7,8 +7,6 @@
* @package Majestic
* @subpackage Decorator
* @since
* @version SVN: $Id$
* @filesource $URL$
*/
class User
{
@ -116,4 +114,3 @@ class User
return $model->getById($id);
}
}
?>

9
exception/Error404Exception.php

@ -5,8 +5,11 @@
* @package Majestic
* @subpackage exception
* @since 2010-02-26
* @version SVN: $Id$
* @filesource $URL$
*/
class Error404Exception extends GeneralException {}
class Error404Exception extends ErrorHTTPException {
function __construct($message = '', $code = null, Exception $previous = NULL )
{
parent::__construct($message, 404, $previous);
}
}

39
exception/ErrorHTTPException.php

@ -0,0 +1,39 @@
<?php
/**
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage exception
* @since 2012-11-11
*/
class ErrorHTTPException extends GeneralException
{
protected $http_headers;
public function __construct($message = "", $code = 0, Exception $previous = null)
{
$this->http_headers = array(
400 => 'HTTP/1.0 400 Bad Request',
402 => 'HTTP/1.0 402 Payment Required',
403 => 'HTTP/1.0 403 Forbidden',
404 => 'HTTP/1.0 404 Not Found',
410 => 'HTTP/1.0 410 Gone',
500 => 'HTTP/1.0 500 Internal Server Error',
501 => 'HTTP/1.0 501 Not Implemented',
503 => 'HTTP/1.0 503 Service Unavailable',
);
if ($code === 200) {
throw new GeneralException('Can\'t send 200 via ErrorHTTPException', 0, $this);
} elseif (!array_key_exists($code, $this->http_headers)) {
throw new GeneralException('Incorrect HTTP code ' . $code . '.', 0, $this);
}
parent::__construct($message, $code, $previous);
}
public function getHTTPHeader()
{
return $this->http_headers[$this->code];
}
}

3
exception/ErrorHandler.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage exception
* @since 2010-02-26
* @version SVN: $Id$
* @filesource $URL$
*/
class ErrorHandler
@ -73,6 +71,7 @@ class ErrorHandler
/**
* @param Exception $exception
* @return string
*/
static public function showDebug($exception)
{

2
exception/GeneralException.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage exception
* @since 2010-02-26
* @version SVN: $Id$
* @filesource $URL$
*/
class GeneralException extends Exception {}

34
form/Form.php

@ -5,18 +5,25 @@
* @package Majestic
* @subpackage form
* @since 2010-04-24
* @version SVN: $Id$
* @filesource $URL$
*/
abstract class Form
{
const SUCCESS = 'success';
const ERROR = 'error';
/**
* @var FormField[]
*/
protected $fields = array();
protected $messages = array(self::SUCCESS => 'Form data valid',
/**
* @var array
*/
protected $messages = array(
self::SUCCESS => 'Form data valid',
self::ERROR => 'Form data invalid');
protected $valid = true;
@ -28,6 +35,7 @@ abstract class Form
/**
* @param string $name
* @param bool|string $message
* @return FormField
*/
protected function addField($name, $message = false)
@ -74,6 +82,9 @@ abstract class Form
return false;
}
/**
* @return array
*/
public function getValues()
{
$values = array();
@ -85,6 +96,9 @@ abstract class Form
return $values;
}
/**
* @return array
*/
public function getSourceValues()
{
$values = array();
@ -94,22 +108,36 @@ abstract class Form
return $values;
}
/**
* @return string
*/
public function getMessageType()
{
return ($this->valid) ? self::SUCCESS : self::ERROR;
}
/**
* @return string
*/
public function getMessage()
{
return $this->messages[$this->getMessageType()];
}
/**
* @param string $message
* @return Form
*/
public function setSuccessMessage($message)
{
$this->messages[self::SUCCESS] = (string) $message;
return $this;
}
/**
* @param string $message
* @return Form
*/
public function setErrorMessage($message)
{
$this->messages[self::ERROR] = (string) $message;

51
form/FormField.php

@ -5,14 +5,18 @@
* @package Majestic
* @subpackage form
* @since 2010-04-25
* @version SVN: $Id$
* @filesource $URL$
*/
class FormField
{
/**
* @var iValidator[]
*/
protected $validators = array();
/**
* @var iFilter[]
*/
protected $filters = array();
/**
@ -21,41 +25,77 @@ class FormField
* @var string
*/
protected $default_message = false;
/**
* @var string
*/
protected $message = false;
/**
* @var mixed
*/
protected $value;
/* Flags */
/**
* @var bool
*/
protected $required = true;
/**
* @var bool
*/
protected $ignored = false;
/**
* @param bool|string $default_message
*/
public function __construct($default_message = false)
{
$this->default_message = $default_message;
}
/**
* @param bool $flag
* @return FormField
*/
public function setRequired($flag)
{
$this->required = (bool) $flag;
return $this;
}
/**
* @return bool
*/
public function isRequired()
{
return $this->required;
}
/**
* @param bool $flag
* @return FormField
*/
public function setIgnored($flag)
{
$this->ignored = (bool) $flag;
return $this;
}
/**
* @return bool
*/
public function isIgnored()
{
return $this->ignored;
}
/**
* @param string[]|iValidator[] $validators
* @return FormField
*/
public function addValidators($validators)
{
foreach ($validators as $validator) {
@ -64,6 +104,11 @@ class FormField
return $this;
}
/**
* @param string|iValidator $validator
* @return FormField
* @throws InitializationException
*/
public function addValidator($validator)
{
if ($validator instanceof iValidator) {

2
form/FormViewHelper.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage Form
* @since 2010-04-25
* @version SVN: $Id$
* @filesource $URL$
*/
class FormViewHelper extends ViewHelper

5
i18n/I18N.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage Model
* @since 2010-02-23
* @version SVN: $Id$
* @filesource $URL$
*/
class I18N
@ -23,7 +21,8 @@ class I18N
/**
* @param mixed $lang default language set
* @throws InitializationException
* @internal mixed $lang default language set
*/
static public function init()
{

2
layout/Error.layout.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage Layout
* @since 2010-02-25
* @version SVN: $Id$
* @filesource $URL$
*/
class ErrorLayout extends Layout

8
layout/Layout.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage Layout
* @since 2010-02-25
* @version SVN: $Id$
* @filesource $URL$
*/
abstract class Layout
@ -56,7 +54,9 @@ abstract class Layout
abstract protected function execute();
/**
* Execute Action, insert action's result html into layout template and return Layout html
* @param Action $action
* @return string
*/
public function fetch($action)
{
@ -65,6 +65,10 @@ abstract class Layout
return $this->view->fetch($this->getTemplate());
}
/**
* Return content of template
* @return string
*/
protected function getTemplate()
{
$template = ($this->template) ? $this->template : substr(get_class($this), 0, -6/*strlen('Layout')*/);

3
logger/FileLogger.php

@ -13,6 +13,9 @@ class FileLogger extends Logger
protected $file_path = '';
/**
* @var resource
*/
protected $handler = null;
protected function __construct()

2
mail/Mailer.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage mail
* @since 2010-04-25
* @version SVN: $Id$
* @filesource $URL$
*/
class Mailer

2
model/Db.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage db
* @since 2010-02-16
* @version SVN: $Id$
* @filesource $URL$
*/
class Db

2
model/DbDriver.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage db
* @since 2010-02-16
* @version SVN: $Id$
* @filesource $URL$
*/
abstract class DbDriver

2
model/DbExpr.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage db
* @since 2010-02-19
* @version SVN: $Id$
* @filesource $URL$
*/
class DbExpr

2
model/DbStatement.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage db
* @since 2010-02-19
* @version SVN: $Id$
* @filesource $URL$
*/
abstract class DbStatement

2
model/Model.php

@ -8,8 +8,6 @@
* @package Majestic
* @subpackage Model
* @since 2010-02-16
* @version SVN: $Id$
* @filesource $URL$
*/
abstract class Model

1
model/MongoStatement.php

@ -131,6 +131,7 @@ class MongoStatement extends DbStatement
/**
* @param MongoDbCommand $request
* @throws GeneralException
* @return bool
*/
protected function driverExecute($request)

2
model/MySQLiDriver.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage db
* @since 2010-02-17
* @version SVN: $Id$
* @filesource $URL$
*/
/**

2
model/MySQLiStatement.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage db
* @since 2010-02-19
* @version SVN: $Id$
* @filesource $URL$
*/
/**

2
redis/RedisDebug.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage Redis
* @since 2011-07-29
* @version SVN: $Id$
* @filesource $URL$
*/
class RedisDebug

5
redis/RedisManager.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage Redis
* @since 2010-07-17
* @version SVN: $Id$
* @filesource $URL$
*/
class RedisManager
@ -15,7 +13,7 @@ class RedisManager
/**
* Redis connections
*
* @var array
* @var Redis[]
*/
static protected $connections = array();
@ -25,6 +23,7 @@ class RedisManager
* @param string $name connection name. If not set 'default' will be used.
* @param array $config Configuration array.
*
* @throws GeneralException
* @return Redis
*/
static public function connect($name = 'default', $config = null)

3
redis/redis.php

@ -15,7 +15,8 @@
* @see https://github.com/nicolasff/phpredis
*
* @method bool connect() connect(string $host, int $port = 6379, float $timeout = 0) Connect to redis
* @method bool pconnect() connect(string $host, int $port = 6379, float $timeout = 0, string $persistent_id) Connect to redis with reusing connection
* @method bool pconnect() pconnect(string $host, int $port = 6379, float $timeout = 0, string $persistent_id) Connect to redis with reusing connection
* @method bool select() select(int $dbindex) Switches to a given database
* @method void close() Close connection to redis
* @method bool setOption() setOption(mixed $name, mixed $value) Set client option
* @method mixed getOption() getOption(mixed $name) Get client option

2
session/Session.model.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage Session
* @since 2010-02-28
* @version SVN: $Id$
* @filesource $URL$
*/
class SessionModel extends SqlModel

2
session/Session.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage session
* @since 2010-03-14
* @version SVN: $Id$
* @filesource $URL$
*/
class Session

5
tests/LoadTest.php

@ -150,12 +150,11 @@ class LoadTest extends PHPUnit_Framework_TestCase
$this->setConstants();
Load::setAutoloadFrom(self::$file);
$autoload = require(self::$file);
$this->setExpectedException('PHPUnit_Framework_Error');
$this->assertNotEmpty(Load::getFilePath('anton'));
$this->setExpectedException('PHPUnit_Framework_Error', 'Undefined index');
$this->assertNotEmpty(Load::getFilePath('ClassDontExist'));
}
/**
* @TODO: Load::autoload() needs self::$autoload = require(self::$file); after self::buildAutoload();
* @runInSeparateProcess
*/
public function testDebugAutoload()

15
tests/app/Action_TestCase.php

@ -17,6 +17,7 @@ require_once dirname(__FILE__) . '/../../classes/Env.class.php';
require_once dirname(__FILE__) . '/../../exception/ErrorHandler.php';
require_once dirname(__FILE__) . '/../../app/FrontController.php';
require_once dirname(__FILE__) . '/../../app/Action.php';
require_once dirname(__FILE__) . '/../../view/iView.php';
class Action_TestCase extends PHPUnit_Framework_TestCase
{
@ -42,7 +43,7 @@ class Action_TestCase extends PHPUnit_Framework_TestCase
}
}
class SomeView
class SomeView implements iView
{
private $result = array();
public function fetch($template)
@ -53,7 +54,17 @@ class SomeView
public function assignObject() {}
public function assign($name, $value) {
public function assign($name, $value = null) {
$this->result[$name] = $value;
}
public function prepend($name, $value)
{
}
public function append($name, $value)
{
}
}

48
tests/app/AjaxActionTest.php

@ -5,7 +5,7 @@
* @link http://netmonsters.ru
* @package Majestic
* @subpackage UnitTests
* @since 2011-11-1
* @since 2011-11-01
*
* Unit tests for AjaxAction class
*/
@ -21,10 +21,9 @@ class AjaxActionTest extends Action_TestCase
*/
public function testConstruct()
{
Config::set('DEBUG', false);
Env::setParams(array('ajax' => 'AjaxTemplate', 'param2' => 'value2'));
$action = $this->getMockForAbstractClass('AjaxAction' );
$action = $this->getMockForAbstractClass('AjaxAction');
$this->assertAttributeEquals('ajax', 'template', $action);
}
@ -33,11 +32,10 @@ class AjaxActionTest extends Action_TestCase
*/
public function testFetchWithEncode()
{
Config::set('DEBUG', false);
$controller = FrontController::getInstance();
$controller->setView('SomeView');
$action = $this->getMockForAbstractClass('AjaxAction' );
$action = $this->getMockForAbstractClass('AjaxAction');
$action->data = array('var' => 'val');
$result = $action->fetch();
$this->assertSame('/actions//ajax', $result['template']);
@ -49,15 +47,47 @@ class AjaxActionTest extends Action_TestCase
*/
public function testFetchNoEncode()
{
Config::set('DEBUG', false);
Env::setParams(array('encode' => false));
Env::setParams(array('json_encode' => false));
$controller = FrontController::getInstance();
$controller->setView('SomeView');
$action = $this->getMockForAbstractClass('AjaxAction' );
$action = $this->getMockForAbstractClass('AjaxAction');
$action->data = array('var' => 'val');
$result = $action->fetch();
$this->assertSame('/actions//ajax', $result['template']);
$this->assertSame( $action->data, $result['data']);
$this->assertSame('Array', (string) $result['data']);
$action->data = 'stringvalue';
$result = $action->fetch();
$this->assertSame('/actions//ajax', $result['template']);
$this->assertSame('stringvalue', (string) $result['data']);
}
/**
* @runInSeparateProcess
*/
public function testFetchWithEncodeDefault()
{
Config::set('DEBUG', false);
$controller = FrontController::getInstance();
$controller->setView('SomeView');
$action = $this->getMockForAbstractClass('AjaxAction');
$result = $action->fetch();
$this->assertSame('/actions//ajax', $result['template']);
$this->assertSame('false', (string) $result['data']);
}
/**
* @runInSeparateProcess
*/
public function testFetchNoEncodeDefault()
{
Config::set('DEBUG', false);
Env::setParams(array('json_encode' => false));
$controller = FrontController::getInstance();
$controller->setView('SomeView');
$action = $this->getMockForAbstractClass('AjaxAction');
$result = $action->fetch();
$this->assertSame('/actions//ajax', $result['template']);
$this->assertSame('', (string) $result['data']);
}
}

1
tests/app/CliControllerTest.php

@ -10,6 +10,7 @@
require_once __DIR__ . '/../../util/profiler/Profiler.php';
require_once __DIR__ . '/../../exception/GeneralException.php';
require_once __DIR__ . '/../../exception/ErrorHTTPException.php';
require_once __DIR__ . '/../../exception/Error404Exception.php';
require_once __DIR__ . '/../../exception/ErrorHandler.php';
require_once __DIR__ . '/../../app/CliController.php';

41
tests/app/ErrorActionTest.php

@ -12,6 +12,9 @@
require_once dirname(__FILE__) . '/Action_TestCase.php';
require_once dirname(__FILE__) . '/../../app/ErrorAction.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
require_once dirname(__FILE__) . '/../../exception/ErrorHTTPException.php';
require_once dirname(__FILE__) . '/../../exception/Error404Exception.php';
class ErrorActionTest extends Action_TestCase
{
@ -24,8 +27,7 @@ class ErrorActionTest extends Action_TestCase
$this->log = ini_get('error_log');
ini_set('error_log', '/dev/null');
set_exit_overload(function()
{
set_exit_overload(function () {
return false;
});
}
@ -96,13 +98,15 @@ class ErrorActionTest extends Action_TestCase
public function testError404WithAjax()
{
$this->setConstants(false);
$exception = $this->getMock('Error404Exception', array('getMessage', 'getFile', 'getLine', 'getTrace'));
$exception->expects($this->once())
->method('getTrace')
->will($this->returnValue(array('one' => array('class' => 'AjaxAction'))));
$exception = new Error404Exception('Some message');
$controller = FrontController::getInstance();
$controller->setView('SomeView');
$action = new ErrorAction($exception);
$action->setAjaxError();
$this->assertSame($exception, $action->exception);
$result = $action->fetch();
$this->assertSame('Some message', $result);
}
/**
@ -111,13 +115,30 @@ class ErrorActionTest extends Action_TestCase
public function testError404NoAjax()
{
$this->setConstants(false);
$exception = $this->getMock('Error404Exception', array('getMessage', 'getFile', 'getLine', 'getTrace'));
$exception->expects($this->once())
->method('getTrace')
->will($this->returnValue(array('one' => array('class' => 'Action'))));
$exception = new Error404Exception('Some message');
$controller = FrontController::getInstance();
$controller->setView('SomeView');
$action = new ErrorAction($exception);
$this->assertSame($exception, $action->exception);
$result = $action->fetch();
$this->assertSame('/actions/404', $result['template']);
}
/**
* @runInSeparateProcess
*/
public function testErrorHTTP()
{
$this->setConstants(false);
$exception = new ErrorHTTPException('Some message', 410);
$controller = FrontController::getInstance();
$controller->setView('SomeView');
$action = new ErrorAction($exception);
$this->assertSame($exception, $action->exception);
$result = $action->fetch();
$this->assertSame('/actions/HTTP', $result['template']);
}
private function setConstants($val = false)

66
tests/app/FrontControllerTest.php

@ -17,6 +17,7 @@ require_once dirname(__FILE__) . '/../../Config.php';
require_once dirname(__FILE__) . '/../../util/FirePHPCore-0.3.2/lib/FirePHPCore/fb.php';
require_once dirname(__FILE__) . '/../../util/profiler/Profiler.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
require_once dirname(__FILE__) . '/../../exception/ErrorHTTPException.php';
require_once dirname(__FILE__) . '/../../exception/Error404Exception.php';
require_once dirname(__FILE__) . '/../../exception/ErrorHandler.php';
require_once dirname(__FILE__) . '/../../app/router/Route.php';
@ -25,7 +26,6 @@ require_once dirname(__FILE__) . '/../../app/FrontController.php';
require_once dirname(__FILE__) . '/../../app/Action.php';
require_once dirname(__FILE__) . '/../../app/AjaxAction.php';
class FrontControllerTest extends PHPUnit_Framework_TestCase
{
@ -47,7 +47,7 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
$this->getMock('ErrorLayout', array('fetch', 'setException'), array(), 'ErrorLayoutMock');
}
if (!class_exists('ErrorActionMock')) {
$this->getMock('ErrorAction', array(), array(), 'ErrorActionMock', false);
$this->getMock('ErrorAction', array('setAjaxError'), array(), 'ErrorActionMock', false);
}
set_new_overload(array($this, 'newCallback'));
}
@ -132,6 +132,8 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
{
$this->setConstants(false);
$controller = FrontController::getInstance();
$result = $controller->execute();
$controller = FrontController::getInstance();
$this->assertNull($controller->execute());
}
@ -192,6 +194,24 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
$result = $controller->execute();
$this->assertNull($result);
}
/**
* @runInSeparateProcess
*/
public function testExecuteWithLayoutProfiler()
{
Config::set('PROFILER', true);
$this->getMock('userAction');
$this->getMock('DefaultLayout', array('fetch'), array(), 'DefaultLayoutMock');
$_SERVER['REQUEST_URI'] = '/user/account/213';
$this->setConstants(true);
$controller = FrontController::getInstance();
$router = $controller->getRouter();
$router->add('user', 'user/account/:id', 'user');
$result = $controller->execute();
$this->assertNull($result);
}
/**
* @runInSeparateProcess
*/
@ -208,6 +228,38 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
$this->assertNull($result);
}
/**
* @runInSeparateProcess
*/
public function testExecuteWithAjaxActionError()
{
$this->getMock('userAction');
$_SERVER['REQUEST_URI'] = '/user/account/213';
$this->setConstants(false);
$controller = FrontController::getInstance();
$router = $controller->getRouter();
$router->add('user', 'user/account/:id', 'NewAjax');
$result = $controller->execute();
$this->assertNull($result);
}
/**
* @runInSeparateProcess
*/
public function testExecuteWithAjaxActionProfiler()
{
Config::set('PROFILER', true);
$this->getMock('userAction');
$this->getMock('DefaultLayout', array('fetch'), array(), 'DefaultLayoutMock');
$_SERVER['REQUEST_URI'] = '/user/account/213';
$this->setConstants(true);
$controller = FrontController::getInstance();
$router = $controller->getRouter();
$router->add('user', 'user/account/:id', 'NewAjax');
$result = $controller->execute();
$this->assertNull($result);
}
private function setConstants($val = false)
{
@ -236,6 +288,12 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
}
}
class NewAjaxAction extends AjaxAction{
protected function execute() {}
/**
* Used in testExecuteWithAjaxAction
*/
class NewAjaxAction extends AjaxAction
{
protected function execute()
{
}
}

11
tests/exception/Error404ExceptionTest.php

@ -11,20 +11,27 @@
*/
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
require_once dirname(__FILE__) . '/../../exception/ErrorHTTPException.php';
require_once dirname(__FILE__) . '/../../exception/Error404Exception.php';
class Error404ExceptionTest extends PHPUnit_Framework_TestCase
{
public function testError404Exception()
{
$this->setExpectedException('Error404Exception');
$this->setExpectedException('Error404Exception', 404);
throw new Error404Exception();
}
public function testError404ExceptionMessage()
{
$this->setExpectedException('Error404Exception', 'Error404Exception message', 10);
$this->setExpectedException('Error404Exception', 'Error404Exception message', 404);
throw new Error404Exception('Error404Exception message', 10);
}
public function testError404ExceptionWithPrevious()
{
$this->setExpectedException('Error404Exception', 'Error404Exception message', 404);
throw new Error404Exception('Error404Exception message', 10, new ErrorException('Error message'));
}
}

106
tests/exception/ErrorHTTPExceptionTest.php

@ -0,0 +1,106 @@
<?php
/*
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage UnitTests
* @since 2011-10-11
*
* Unit tests for Error404Exception class
*/
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
require_once dirname(__FILE__) . '/../../exception/ErrorHTTPException.php';
require_once dirname(__FILE__) . '/../../exception/Error404Exception.php';
class ErrorHTTPExceptionTest extends PHPUnit_Framework_TestCase
{
public function testErrorHTTPException()
{
$this->setExpectedException('ErrorHTTPException', 404);
throw new ErrorHTTPException('Some error occurred', 400);
}
public function testErrorHTTPExceptionMessage()
{
$this->setExpectedException('ErrorHTTPException', 'ErrorHTTPException message', 410);
throw new ErrorHTTPException('ErrorHTTPException message', 410);
}
public function testErrorHTTPExceptionWithPrevious()
{
$this->setExpectedException('ErrorHTTPException', 'ErrorHTTPException message', 500);
throw new ErrorHTTPException('ErrorHTTPException message', 500, new ErrorException('Error message'));
}
/**
* @dataProvider providerHTTPCode
*/
public function testGetHTTPHeader($message, $code, $header)
{
try {
throw new ErrorHTTPException($message, $code, new ErrorException('Error message'));
}
catch (ErrorHTTPException $e) {
$this->assertSame($header, $e->getHTTPHeader());
$this->assertSame($message, $e->getMessage());
$this->assertSame($code, $e->getCode());
$this->assertEquals(new ErrorException('Error message'), $e->getPrevious());
}
}
public function providerHTTPCode()
{
return array(
array('ErrorHTTPException message for 400', 400, 'HTTP/1.0 400 Bad Request'),
array('ErrorHTTPException message for 402', 402, 'HTTP/1.0 402 Payment Required'),
array('ErrorHTTPException message for 403', 403, 'HTTP/1.0 403 Forbidden'),
array('ErrorHTTPException message for 404', 404, 'HTTP/1.0 404 Not Found'),
array('ErrorHTTPException message for 410', 410, 'HTTP/1.0 410 Gone'),
array('ErrorHTTPException message for 500', 500, 'HTTP/1.0 500 Internal Server Error'),
array('ErrorHTTPException message for 501', 501, 'HTTP/1.0 501 Not Implemented'),
array('ErrorHTTPException message for 503', 503, 'HTTP/1.0 503 Service Unavailable'),
);
}
public function testErrorHTTPException200()
{
try {
throw new ErrorHTTPException('ErrorHTTPException message', 200, new ErrorException('Error message'));
}
catch (ErrorHTTPException $e) {
$this->fail();
}
catch (GeneralException $e) {
$this->assertSame('Can\'t send 200 via ErrorHTTPException', $e->getMessage());
}
}
public function testErrorHTTPExceptionBadCode()
{
try {
throw new ErrorHTTPException('ErrorHTTPException message', 100, new ErrorException('Error message'));
}
catch (ErrorHTTPException $e) {
$this->fail();
}
catch (GeneralException $e) {
$this->assertSame('Incorrect HTTP code 100.', $e->getMessage());
}
}
public function testErrorHTTPExceptionGoodCode()
{
try {
throw new ErrorHTTPException('ErrorHTTPException message', 400, new ErrorException('Error message'));
}
catch (ErrorHTTPException $e) {
$this->assertSame(400, $e->getCode());
}
catch (GeneralException $e) {
$this->fail();
}
}
}

2
tests/form/FormFieldTest.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage form
* @since 2010-04-25
* @version SVN: $Id$
* @filesource $URL$
*/
require_once dirname(__FILE__) . '/../../validator/iValidator.php';

6
tests/view/helpers/BreadcrumbVeiwHelperTest.php

@ -17,6 +17,9 @@ require_once dirname(__FILE__) . '/../../../view/helpers/BreadcrumbViewHelper.ph
class BreadcrumbViewHelperTest extends PHPUnit_Framework_TestCase
{
/**
* @var BreadcrumbViewHelper
*/
public $helper;
public function setUp()
@ -43,7 +46,7 @@ class BreadcrumbViewHelperTest extends PHPUnit_Framework_TestCase
$this->helper->prepend('Home page', 'home.php');
$this->helper->breadcrumb('Guest page', 'guest.php');
$this->helper->append('Leave message', 'feedback.php');
$this->assertSame(array('Home page' => 'home.php', 'Guest page' => 'guest.php', 'Leave message'=> 'feedback.php'), Registry::get('BreadcrumbViewHelper'));
$this->assertSame(array('Home page' => 'home.php', 'Guest page' => 'guest.php', 'Leave message' => 'feedback.php'), Registry::get('BreadcrumbViewHelper'));
$result = $this->helper->__toString();
$this->assertSame('<a href="home.php">Home page</a> &gt; <a href="guest.php">Guest page</a> &gt; <a href="feedback.php">Leave message</a>', $result);
@ -55,6 +58,5 @@ class BreadcrumbViewHelperTest extends PHPUnit_Framework_TestCase
$this->helper->append('Last page', '');
$result = $this->helper->__toString();
$this->assertSame('<a href="home.php">Home page</a>-<a href="guest.php">Guest page</a>-<a href="feedback.php">Leave message</a>-Last page', $result);
}
}

4
tests/view/helpers/GetViewHelperTest.php

@ -19,6 +19,9 @@ require_once dirname(__FILE__) . '/../../../view/helpers/GetViewHelper.php';
class GetViewHelperTest extends PHPUnit_Framework_TestCase
{
/**
* @var GetViewHelper
*/
public $helper;
public function setUp()
@ -77,5 +80,4 @@ class GetViewHelperTest extends PHPUnit_Framework_TestCase
$result = $this->helper->get(array('b' => 'c d e', 'c' => array('five' => 'six seven')));
$this->assertSame('?a[one]=1&amp;a[two]=2&amp;b=c+d+e&amp;c[five]=six+seven', $result);
}
}

3
tests/view/helpers/HeadViewHelperTest.php

@ -17,6 +17,9 @@ require_once dirname(__FILE__) . '/../../../view/helpers/HeadViewHelper.php';
class HeadViewHelperTest extends PHPUnit_Framework_TestCase
{
/**
* @var HeadViewHelper
*/
public $helper;
public function setUp()

32
tests/view/helpers/MsgViewHelperTest.php

@ -19,7 +19,9 @@ require_once dirname(__FILE__) . '/../../../exception/GeneralException.php';
class MsgViewHelperTest extends PHPUnit_Framework_TestCase
{
/**
* @var MsgViewHelper
*/
public $helper;
public function setUp()
@ -36,8 +38,6 @@ class MsgViewHelperTest extends PHPUnit_Framework_TestCase
$this->assertSame($this->helper, $this->helper->msg('error message', 'error'));
$this->assertSame(array('message' => 'error message', 'type' => 'error'), Session::get('MsgViewHelper'));
}
public function testWrongType()
@ -59,6 +59,20 @@ class MsgViewHelperTest extends PHPUnit_Framework_TestCase
$this->assertNull(Session::get('test'));
}
public function testInfo()
{
$this->helper->info('info message');
$this->assertSame(array('message' => 'info message', 'type' => 'info'), Session::get('MsgViewHelper'));
$this->assertNull(Session::get('test'));
}
public function testWarning()
{
$this->helper->warning('warning message');
$this->assertSame(array('message' => 'warning message', 'type' => 'warning'), Session::get('MsgViewHelper'));
$this->assertNull(Session::get('test'));
}
public function testToString()
{
$this->helper->success('yeah');
@ -72,4 +86,16 @@ class MsgViewHelperTest extends PHPUnit_Framework_TestCase
$this->assertEmpty($result);
}
public function testToStringWithPrefix()
{
$this->helper->success('yeah');
$result = $this->helper->withPrefix('prefix')->__toString();
$this->assertSame('<div class="prefixsuccess">yeah</div>', $result);
}
public function testToStringEmptyWithPrefix()
{
$result = $this->helper->withPrefix('prefix')->__toString();
$this->assertEmpty($result);
}
}

4
tests/view/helpers/TitleViewHelperTest.php

@ -16,7 +16,9 @@ require_once dirname(__FILE__) . '/../../../view/helpers/TitleViewHelper.php';
class TitleViewHelperTest extends PHPUnit_Framework_TestCase
{
/**
* @var TitleViewHelper
*/
public $helper;
public function setUp()

16
util/AutoloadBuilder.php

@ -7,8 +7,6 @@
* @package Majestic
* @subpackage util
* @since 2010-02-24
* @version SVN: $Id$
* @filesource $URL$
*/
/**
@ -24,7 +22,7 @@ class AutoloadBuilder
protected $handler;
protected $regex = '/(class|interface) ([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/';
protected $regex = '/\n(abstract |final )?(class|interface) ([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/';
public function __construct($autoload, $dirs = array(), $exclude = array())
{
@ -36,7 +34,7 @@ class AutoloadBuilder
public function build()
{
$array_string = "<?php\n// This file is autogenerated by \n// " . __FILE__ . " script.\nreturn array(\n";
// for dublicates check
// for duplicates check
$classes = array();
foreach ($this->dirs as $dir) {
$iterator = new RecursiveIteratorIterator(
@ -45,7 +43,9 @@ class AutoloadBuilder
);
foreach ($iterator as $file) {
/**
* @var SplFileInfo $file
*/
if ($this->isExcluded($file->getRealPath())) {
continue;
}
@ -62,11 +62,11 @@ class AutoloadBuilder
if (preg_match_all($this->regex, $content, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
if (array_key_exists($match[2], $classes)) {
if (array_key_exists($match[3], $classes)) {
continue;
}
$array_string .= "'{$match[2]}'=>'" . $relative_path . "',\n";
$classes[$match[2]] = $file->getRealPath();
$array_string .= "'{$match[3]}'=>'" . $relative_path . "',\n";
$classes[$match[3]] = $file->getRealPath();
}
}
}

2
util/profiler/CommandProfiler.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage util
* @since 2010-03-09
* @version SVN: $Id$
* @filesource $URL$
*/
class CommandProfiler

11
util/profiler/Profiler.php

@ -5,17 +5,24 @@
* @package Majestic
* @subpackage util
* @since 2010-03-09
* @version SVN: $Id$
* @filesource $URL$
*/
class Profiler
{
/**
* @var int
*/
protected $start = null;
/**
* @var int
*/
protected $end = null;
/**
* @var CommandProfiler[]
*/
protected $queries = array();
static protected $instance = null;

2
validator/EmailValidator.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage validator
* @since 2010-04-26
* @version SVN: $Id$
* @filesource $URL$
*/
class EmailValidator extends RegexValidator

2
validator/EqualValidator.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage validator
* @since 2010-04-26
* @version SVN: $Id$
* @filesource $URL$
*/
class EqualValidator extends Validator

2
validator/NotEmptyValidator.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage validator
* @since 2010-04-26
* @version SVN: $Id$
* @filesource $URL$
*/
class NotEmptyValidator extends Validator

2
validator/RegexValidator.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage validator
* @since 2010-04-26
* @version SVN: $Id$
* @filesource $URL$
*/
class RegexValidator extends Validator

2
validator/Validator.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage validator
* @since 2010-04-24
* @version SVN: $Id$
* @filesource $URL$
*/
abstract class Validator implements iValidator

2
validator/iValidator.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage validator
* @since 2010-04-25
* @version SVN: $Id$
* @filesource $URL$
*/
interface iValidator

16
view/PHPView.php

@ -5,20 +5,28 @@
* @package Majestic
* @subpackage View
* @since 2010-02-25
* @version SVN: $Id$
* @filesource $URL$
*/
/**
* @method ViewHelperGet get()
* @method BreadcrumbViewHelper breadcrumb() breadcrumb(string $text = false, string $href = false) Append next link to breadcrumb
* @method GetViewHelper get() get(array $replace) Replace some HTTP GET parameters with $replace
* @method HeadViewHelper head() head(string $string = false) Append another string to HEAD section of Layout
* @method MsgViewHelper msg() msg(string $msg = null, string $type = null) Set a message to display for user in Layout
* @method TitleViewHelper title() title(string $string = false) Append another section for TITLE of Layout
* @method FormViewHelper form() form(string $form = null) Get form values from session
*
*/
class PHPView implements iView
{
protected $path = '';
protected $variables = array();
protected $helpers = array();
protected $extension = '.phtml';
protected $template = '';
public function __construct($config)
@ -92,7 +100,7 @@ class PHPView implements iView
ob_start();
if (!is_readable($this->template)) {
ob_clean();
throw new GeneralException('Template "' . $this->template .'" not found.');
throw new GeneralException('Template "' . $this->template . '" not found.');
}
include($this->template);
return ob_get_clean();

2
view/helpers/BreadcrumbViewHelper.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage View
* @since 2010-03-16
* @version SVN: $Id$
* @filesource $URL$
*/
class BreadcrumbViewHelper extends ViewHelper

4
view/helpers/GetViewHelper.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage View
* @since 2010-03-09
* @version SVN: $Id$
* @filesource $URL$
*/
class GetViewHelper extends ViewHelper
@ -43,7 +41,7 @@ class GetViewHelper extends ViewHelper
protected function impl($name, $value)
{
if (is_array($value)){
if (is_array($value)) {
$result = array();
foreach ($value as $key => $val) {
$result[] = $name . '[' . $key . ']=' . urlencode($val);

2
view/helpers/HeadViewHelper.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage View
* @since 2010-03-16
* @version SVN: $Id$
* @filesource $URL$
*/
class HeadViewHelper extends ViewHelper

40
view/helpers/MsgViewHelper.php

@ -5,37 +5,61 @@
* @package Majestic
* @subpackage View
* @since 2010-03-09
* @version SVN: $Id$
* @filesource $URL$
*/
class MsgViewHelper extends ViewHelper
{
const SUCCESS = 'success';
const ERROR = 'error';
protected $get;
const INFO = 'info';
const WARNING = 'warning';
protected $css_prefix = '';
public function msg($msg = null, $type = null)
{
if ($msg && $type) {
if (!in_array($type, array(self::SUCCESS, self::ERROR))) {
if (!in_array($type, array(self::SUCCESS, self::ERROR, self::INFO, self::WARNING))) {
throw new GeneralException('Unknown message type: "' . $type . '"');
}
Session::set(__CLASS__, array('message' => $msg, 'type' => $type));
$this->set($msg, $type);
}
return $this;
}
public function success($msg)
{
Session::set(__CLASS__, array('message' => $msg, 'type' => self::SUCCESS));
$this->set($msg, self::SUCCESS);
}
public function error($msg)
{
Session::set(__CLASS__, array('message' => $msg, 'type' => self::ERROR));
$this->set($msg, self::ERROR);
}
public function info($msg)
{
$this->set($msg, self::INFO);
}
public function warning($msg)
{
$this->set($msg, self::WARNING);
}
protected function set($msg, $type)
{
Session::set(__CLASS__, array('message' => $msg, 'type' => $type));
}
public function withPrefix($css_prefix)
{
$this->css_prefix = $css_prefix;
return $this;
}
public function __toString()
@ -43,7 +67,7 @@ class MsgViewHelper extends ViewHelper
$msg = Session::get(__CLASS__, false);
if ($msg) {
Session::del(__CLASS__);
return '<div class="' . $msg['type'] . '">' . $this->view->escape($msg['message']) . '</div>';
return '<div class="' . $this->css_prefix . $msg['type'] . '">' . $this->view->escape($msg['message']) . '</div>';
}
return '';
}

2
view/helpers/TitleViewHelper.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage View
* @since 2010-03-16
* @version SVN: $Id$
* @filesource $URL$
*/
class TitleViewHelper extends ViewHelper

2
view/helpers/ViewHelper.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage View
* @since 2010-03-09
* @version SVN: $Id$
* @filesource $URL$
*/
abstract class ViewHelper

2
view/iView.php

@ -5,8 +5,6 @@
* @package Majestic
* @subpackage View
* @since 2010-02-25
* @version SVN: $Id$
* @filesource $URL$
*/
interface iView

Loading…
Cancel
Save