diff --git a/Config.php b/Config.php index c496673..4d094bf 100644 --- a/Config.php +++ b/Config.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage Model * @since 2010-02-17 - * @version SVN: $Id$ - * @filesource $URL$ */ class Config extends Registry diff --git a/Load.php b/Load.php index 51b160a..a765c2b 100644 --- a/Load.php +++ b/Load.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage Load * @since 2010-02-24 - * @version SVN: $Id$ - * @filesource $URL$ */ class Load diff --git a/Registry.php b/Registry.php index 6c4b853..69727c3 100644 --- a/Registry.php +++ b/Registry.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage Model * @since 2010-02-17 - * @version SVN: $Id$ - * @filesource $URL$ */ class Registry extends ArrayObject diff --git a/app/Action.php b/app/Action.php index eeebd3a..1ad7056 100644 --- a/app/Action.php +++ b/app/Action.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage app * @since 2010-02-25 - * @version SVN: $Id$ - * @filesource $URL$ */ abstract class Action diff --git a/app/AjaxAction.php b/app/AjaxAction.php index c91affe..f007350 100644 --- a/app/AjaxAction.php +++ b/app/AjaxAction.php @@ -3,22 +3,28 @@ * AjaxAction * * @copyright NetMonsters - * @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"); - header("Content-type: text/html; 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()); } } diff --git a/app/CliController.php b/app/CliController.php index 9b25702..768a69e 100644 --- a/app/CliController.php +++ b/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(); diff --git a/app/ErrorAction.php b/app/ErrorAction.php index ed24c53..f85a8d6 100644 --- a/app/ErrorAction.php +++ b/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,22 +50,19 @@ class ErrorAction extends Action protected function sendHttpCode() { - if (headers_sent()) { - return; - } switch ($this->template) { case 404: - header('HTTP/1.0 404 Not Found'); - break; + case 'HTTP': + header($this->exception->getHTTPHeader()); + break; default: header('HTTP/1.0 500 Internal Server Error'); } } - + protected function logError() { if ($this->template == 500) { - $error = 0; $ex = $this->exception; if ($ex instanceof ErrorException) { @@ -83,7 +84,7 @@ class ErrorAction extends Action break; } $message = 'PHP ' . $error . ': ' . $ex->getMessage() . ' in ' . $ex->getFile() - . ' on line ' . $ex->getLine(); + . ' on line ' . $ex->getLine(); error_log($message); } } @@ -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 false; + return $this->ajax_error; + } + + /** + * Set if exception was thrown from AjaxAction subclass + */ + public function setAjaxError() + { + $this->ajax_error = true; } } \ No newline at end of file diff --git a/app/FrontController.php b/app/FrontController.php index cb31776..43bbec9 100644 --- a/app/FrontController.php +++ b/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,7 +131,11 @@ class FrontController } catch (Exception $e) { if (Config::get('DEBUG')) { if (!headers_sent()) { - header('HTTP/1.0 500 Internal Server Error'); + if ($e instanceof ErrorHTTPException) { + header($e->getHTTPHeader()); + } else { + header('HTTP/1.0 500 Internal Server Error'); + } } return ErrorHandler::showDebug($e); } @@ -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); } } } \ No newline at end of file diff --git a/app/PagerAction.php b/app/PagerAction.php index cd150d9..a277882 100644 --- a/app/PagerAction.php +++ b/app/PagerAction.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage app * @since 2010-03-07 - * @version SVN: $Id$ - * @filesource $URL$ */ class PagerAction extends Action diff --git a/app/StaticAction.php b/app/StaticAction.php index eff6f75..b1bfa96 100644 --- a/app/StaticAction.php +++ b/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 diff --git a/app/router/Route.php b/app/router/Route.php index 7f42f31..92a59c8 100644 --- a/app/router/Route.php +++ b/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) { diff --git a/app/router/Router.php b/app/router/Router.php index f79f588..0a296c2 100644 --- a/app/router/Router.php +++ b/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; diff --git a/cache/Cache.php b/cache/Cache.php index b2196ea..bc97f36 100644 --- a/cache/Cache.php +++ b/cache/Cache.php @@ -5,78 +5,75 @@ * @package Majestic * @subpackage Cache * @since 2010-03-04 - * @version SVN: $Id$ - * @filesource $URL$ */ abstract class Cache { - + /** * Add an item to the cache - * + * * @param string $key * @param mixed $value * @param int $expire * @return bool */ abstract public function add($key, $value, $expire = 0); - + /** * Decrement item's value - * + * * @param string $key * @param int $decrement * @return bool */ abstract public function decrement($key, $decrement = 1); - + /** * Delete item from the cache - * + * * @param string $key - * @param int $value * @return bool */ abstract public function del($key); - + /** * Flush all existing items - * + * * @return bool */ abstract public function flush(); - + /** * Retrieve item from the cache - * + * * @param mixed $key * @return mixed */ abstract public function get($key); - + /** * Increment item's value - * + * * @param string $key * @param int $increment * @return bool */ abstract public function increment($key, $increment = 1); - + /** * Replace value of the existing item - * + * * @param string $key - * @param mixed $var + * @param mixed $value * @param int $expire * @return bool */ abstract public function replace($key, $value, $expire = 0); - + /** * Store data in the cache - * + * * @param string $key * @param mixed $value * @param int $expire diff --git a/cache/CacheKey.php b/cache/CacheKey.php index 8121026..61678f0 100644 --- a/cache/CacheKey.php +++ b/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) { diff --git a/cache/Cacher.php b/cache/Cacher.php index b662c57..889d6b1 100644 --- a/cache/Cacher.php +++ b/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])) { diff --git a/cache/MemcacheCache.php b/cache/MemcacheCache.php index 4b2e61f..91430e3 100644 --- a/cache/MemcacheCache.php +++ b/cache/MemcacheCache.php @@ -5,37 +5,37 @@ * @package Majestic * @subpackage Cache * @since 2010-03-04 - * @version SVN: $Id$ - * @filesource $URL$ */ class MemcacheCache extends Cache { - + /** * @var Memcache */ protected $connection = null; - + + /** + * @var null|string + */ protected $key_salt = null; - + /** * One hour to live default - * + * * @var int */ protected $expire = 3600; - - + public function __construct($config) { $this->connection = new Memcache(); - + if (isset($config['key_salt'])) { $this->key_salt = $config['key_salt']; unset($config['key_salt']); } - + $required = array('hostname', 'port'); foreach ($config as $c) { foreach ($required as $option) { @@ -46,10 +46,10 @@ class MemcacheCache extends Cache $this->connection->addServer($c['hostname'], $c['port']); } } - + /** * Add an item to the cache - * + * * @param string $key * @param mixed $value * @param int $expire @@ -59,10 +59,10 @@ class MemcacheCache extends Cache { return $this->connection->add($this->getKey($key), $value, null, $this->getExpire($expire)); } - + /** * Decrement item's value - * + * * @param string $key * @param int $decrement * @return bool @@ -71,32 +71,32 @@ class MemcacheCache extends Cache { return $this->connection->decrement($this->getKey($key), $decrement); } - + /** * Delete item from the cache - * + * * @param string $key - * @param int $value + * @internal param int $value * @return bool */ public function del($key) { return $this->connection->delete($this->getKey($key), 0); } - + /** * Flush all existing items - * + * * @return bool */ public function flush() { return $this->connection->flush(); } - + /** * Retrieve item from the cache - * + * * @param string $key * @return mixed */ @@ -104,10 +104,10 @@ class MemcacheCache extends Cache { return $this->connection->get($this->getKey($key)); } - + /** * Increment item's value - * + * * @param string $key * @param int $increment * @return bool @@ -116,23 +116,24 @@ class MemcacheCache extends Cache { return $this->connection->increment($this->getKey($key), $increment); } - + /** * 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) { return $this->connection->replace($this->getKey($key), $value, null, $this->getExpire($expire)); } - + /** * Store data in the cache - * + * * @param string $key * @param mixed $value * @param int $expire @@ -142,7 +143,7 @@ class MemcacheCache extends Cache { return $this->connection->set($this->getKey($key), $value, null, $this->getExpire($expire)); } - + /** * @param string $key * @return string @@ -151,7 +152,7 @@ class MemcacheCache extends Cache { return md5($this->key_salt . $key); } - + public function getExpire($expire) { return ($expire > 0) ? $expire : $this->expire; diff --git a/captcha/Captcha.php b/captcha/Captcha.php index d843c20..6f949be 100644 --- a/captcha/Captcha.php +++ b/captcha/Captcha.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage captcha * @since 2010-04-24 - * @version SVN: $Id$ - * @filesource $URL$ */ class Captcha diff --git a/captcha/CaptchaImageAction.php b/captcha/CaptchaImageAction.php index b551295..c3d42dc 100644 --- a/captcha/CaptchaImageAction.php +++ b/captcha/CaptchaImageAction.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage captcha * @since 2010-04-24 - * @version SVN: $Id$ - * @filesource $URL$ */ class CaptchaImageAction diff --git a/captcha/CaptchaValidator.php b/captcha/CaptchaValidator.php index 4638655..6a75182 100644 --- a/captcha/CaptchaValidator.php +++ b/captcha/CaptchaValidator.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage validator * @since 2010-04-26 - * @version SVN: $Id$ - * @filesource $URL$ */ class CaptchaValidator extends Validator diff --git a/classes/Env.class.php b/classes/Env.class.php index 062c6fd..1b04117 100644 --- a/classes/Env.class.php +++ b/classes/Env.class.php @@ -7,8 +7,6 @@ * @package Majestic * @subpackage env * @since - * @version SVN: $Id$ - * @filesource $URL$ */ class Env diff --git a/classes/Format.class.php b/classes/Format.class.php index 215ef30..b1d7c5c 100644 --- a/classes/Format.class.php +++ b/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 ))); -?> \ No newline at end of file diff --git a/classes/User.class.php b/classes/User.class.php index c5b9229..b7b506a 100644 --- a/classes/User.class.php +++ b/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); } } -?> \ No newline at end of file diff --git a/exception/Error404Exception.php b/exception/Error404Exception.php index b6690fe..454b500 100644 --- a/exception/Error404Exception.php +++ b/exception/Error404Exception.php @@ -5,8 +5,11 @@ * @package Majestic * @subpackage exception * @since 2010-02-26 - * @version SVN: $Id$ - * @filesource $URL$ */ -class Error404Exception extends GeneralException {} \ No newline at end of file +class Error404Exception extends ErrorHTTPException { + function __construct($message = '', $code = null, Exception $previous = NULL ) + { + parent::__construct($message, 404, $previous); + } +} \ No newline at end of file diff --git a/exception/ErrorHTTPException.php b/exception/ErrorHTTPException.php new file mode 100644 index 0000000..0a52257 --- /dev/null +++ b/exception/ErrorHTTPException.php @@ -0,0 +1,39 @@ + + * @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]; + } +} \ No newline at end of file diff --git a/exception/ErrorHandler.php b/exception/ErrorHandler.php index 954f8dc..d38714b 100644 --- a/exception/ErrorHandler.php +++ b/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) { diff --git a/exception/GeneralException.php b/exception/GeneralException.php index 41c3bd3..07faa1b 100644 --- a/exception/GeneralException.php +++ b/exception/GeneralException.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage exception * @since 2010-02-26 - * @version SVN: $Id$ - * @filesource $URL$ */ class GeneralException extends Exception {} \ No newline at end of file diff --git a/form/Form.php b/form/Form.php index c867b0d..fd061b9 100644 --- a/form/Form.php +++ b/form/Form.php @@ -5,29 +5,37 @@ * @package Majestic * @subpackage form * @since 2010-04-24 - * @version SVN: $Id$ - * @filesource $URL$ */ abstract class Form { const SUCCESS = 'success'; - const ERROR = 'error'; - + + const ERROR = 'error'; + + /** + * @var FormField[] + */ protected $fields = array(); - protected $messages = array(self::SUCCESS => 'Form data valid', - self::ERROR => 'Form data invalid'); - + + /** + * @var array + */ + protected $messages = array( + self::SUCCESS => 'Form data valid', + self::ERROR => 'Form data invalid'); + protected $valid = true; - + public function __construct() { $this->init(); } - + /** * @param string $name + * @param bool|string $message * @return FormField */ protected function addField($name, $message = false) @@ -35,13 +43,13 @@ abstract class Form $this->fields[$name] = new FormField($message); return $this->fields[$name]; } - + public function isValid($data) { if (!is_array($data)) { throw new InitializationException(__CLASS__ . '::' . __METHOD__ . ' expects an array'); } - + foreach ($this->fields as $field_name => $field) { if (isset($data[$field_name])) { $this->valid &= $field->isValid($data[$field_name], $data); @@ -54,7 +62,7 @@ abstract class Form } return $this->valid; } - + public function getMessages() { $messages = array(); @@ -65,7 +73,7 @@ abstract class Form } return $messages; } - + public function getValue($key) { if (isset($this->fields[$key])) { @@ -73,7 +81,10 @@ abstract class Form } return false; } - + + /** + * @return array + */ public function getValues() { $values = array(); @@ -84,7 +95,10 @@ abstract class Form } return $values; } - + + /** + * @return array + */ public function getSourceValues() { $values = array(); @@ -93,35 +107,49 @@ 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; return $this; } - + protected function fillHelperData() { $data['messages'] = $this->getMessages(); $data['values'] = $this->getSourceValues(); Session::set(get_class($this), $data); } - + abstract protected function init(); } \ No newline at end of file diff --git a/form/FormField.php b/form/FormField.php index 0e93d03..99683b6 100644 --- a/form/FormField.php +++ b/form/FormField.php @@ -1,61 +1,101 @@ - * @link http://netmonsters.ru + * @link http://netmonsters.ru * @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(); - + /** * Used instead message of validator if defined. - * + * * @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) { @@ -63,7 +103,12 @@ class FormField } return $this; } - + + /** + * @param string|iValidator $validator + * @return FormField + * @throws InitializationException + */ public function addValidator($validator) { if ($validator instanceof iValidator) { @@ -77,7 +122,7 @@ class FormField $this->validators[$name] = $validator; return $this; } - + public function addFilters($filters) { foreach ($filters as $filter) { @@ -85,10 +130,10 @@ class FormField } return $this; } - + public function addFilter($filter) { - if ($filter instanceof iFilter) { + if ($filter instanceof iFilter) { $name = get_class($filter); } elseif (is_string($filter)) { $name = $filter . 'Filter'; @@ -99,7 +144,7 @@ class FormField $this->filters[$name] = $filter; return $this; } - + public function getValue() { $value = $this->value; @@ -110,10 +155,10 @@ class FormField } return $value; } - + /** * $value & $key for array_walk_recursive - * + * * @param mixed $value * @param mixed $key */ @@ -123,24 +168,24 @@ class FormField $value = $filter->filter($value); } } - + public function getSourceValue() { return $this->value; } - + public function isValid($value, $context = null) { $this->value = $value; // filtered value here $value = $this->getValue(); - + $valid = true; - + if ((($value === '') || ($value === null)) && !$this->isRequired()) { return $valid; } - + foreach ($this->validators as $validator) { if (is_array($value)) { foreach ($value as $val) { @@ -158,14 +203,14 @@ class FormField } elseif ($validator->isValid($value, $context)) { continue; } - + $valid = false; $this->message = ($this->default_message) ? $this->default_message : $validator->getMessage(); break; } return $valid; } - + public function getMessage() { return $this->message; diff --git a/form/FormViewHelper.php b/form/FormViewHelper.php index 60dcb77..f55b515 100644 --- a/form/FormViewHelper.php +++ b/form/FormViewHelper.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage Form * @since 2010-04-25 - * @version SVN: $Id$ - * @filesource $URL$ */ class FormViewHelper extends ViewHelper diff --git a/i18n/I18N.php b/i18n/I18N.php index 1867436..eceb123 100644 --- a/i18n/I18N.php +++ b/i18n/I18N.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage Model * @since 2010-02-23 - * @version SVN: $Id$ - * @filesource $URL$ */ class I18N @@ -20,10 +18,11 @@ class I18N static protected $lang = ''; static protected $locale = ''; - - + + /** - * @param mixed $lang default language set + * @throws InitializationException + * @internal mixed $lang default language set */ static public function init() { diff --git a/layout/Error.layout.php b/layout/Error.layout.php index 62ed7ce..f773cfb 100644 --- a/layout/Error.layout.php +++ b/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 diff --git a/layout/Layout.php b/layout/Layout.php index 9c5eaae..a85dd10 100644 --- a/layout/Layout.php +++ b/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) { @@ -64,7 +64,11 @@ abstract class Layout $this->execute(); 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')*/); diff --git a/logger/FileLogger.php b/logger/FileLogger.php index c14c52f..ec16515 100644 --- a/logger/FileLogger.php +++ b/logger/FileLogger.php @@ -13,6 +13,9 @@ class FileLogger extends Logger protected $file_path = ''; + /** + * @var resource + */ protected $handler = null; protected function __construct() diff --git a/mail/Mailer.php b/mail/Mailer.php index 61e2a2e..97e7bd4 100644 --- a/mail/Mailer.php +++ b/mail/Mailer.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage mail * @since 2010-04-25 - * @version SVN: $Id$ - * @filesource $URL$ */ class Mailer diff --git a/model/Db.php b/model/Db.php index 933b011..df0ec5b 100644 --- a/model/Db.php +++ b/model/Db.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage db * @since 2010-02-16 - * @version SVN: $Id$ - * @filesource $URL$ */ class Db diff --git a/model/DbDriver.php b/model/DbDriver.php index f8f6f0e..8042b0f 100644 --- a/model/DbDriver.php +++ b/model/DbDriver.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage db * @since 2010-02-16 - * @version SVN: $Id$ - * @filesource $URL$ */ abstract class DbDriver diff --git a/model/DbExpr.php b/model/DbExpr.php index 413d44d..1d5e84f 100644 --- a/model/DbExpr.php +++ b/model/DbExpr.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage db * @since 2010-02-19 - * @version SVN: $Id$ - * @filesource $URL$ */ class DbExpr diff --git a/model/DbStatement.php b/model/DbStatement.php index 9ee5feb..6dbbf2c 100644 --- a/model/DbStatement.php +++ b/model/DbStatement.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage db * @since 2010-02-19 - * @version SVN: $Id$ - * @filesource $URL$ */ abstract class DbStatement diff --git a/model/Model.php b/model/Model.php index 7af41aa..f063d17 100644 --- a/model/Model.php +++ b/model/Model.php @@ -8,8 +8,6 @@ * @package Majestic * @subpackage Model * @since 2010-02-16 - * @version SVN: $Id$ - * @filesource $URL$ */ abstract class Model diff --git a/model/MongoStatement.php b/model/MongoStatement.php index 221e49c..91dd585 100644 --- a/model/MongoStatement.php +++ b/model/MongoStatement.php @@ -131,6 +131,7 @@ class MongoStatement extends DbStatement /** * @param MongoDbCommand $request + * @throws GeneralException * @return bool */ protected function driverExecute($request) diff --git a/model/MySQLiDriver.php b/model/MySQLiDriver.php index 179815e..dc44478 100644 --- a/model/MySQLiDriver.php +++ b/model/MySQLiDriver.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage db * @since 2010-02-17 - * @version SVN: $Id$ - * @filesource $URL$ */ /** diff --git a/model/MySQLiStatement.php b/model/MySQLiStatement.php index 5700d80..420f050 100644 --- a/model/MySQLiStatement.php +++ b/model/MySQLiStatement.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage db * @since 2010-02-19 - * @version SVN: $Id$ - * @filesource $URL$ */ /** diff --git a/redis/RedisDebug.php b/redis/RedisDebug.php index 692f0ea..bfa7d26 100644 --- a/redis/RedisDebug.php +++ b/redis/RedisDebug.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage Redis * @since 2011-07-29 - * @version SVN: $Id$ - * @filesource $URL$ */ class RedisDebug diff --git a/redis/RedisManager.php b/redis/RedisManager.php index ae5f3db..4c8479f 100644 --- a/redis/RedisManager.php +++ b/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) diff --git a/redis/redis.php b/redis/redis.php index a6bffbf..94a8842 100644 --- a/redis/redis.php +++ b/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 diff --git a/session/Session.model.php b/session/Session.model.php index 769be5e..72e1f73 100644 --- a/session/Session.model.php +++ b/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 diff --git a/session/Session.php b/session/Session.php index b2546fd..9af7724 100644 --- a/session/Session.php +++ b/session/Session.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage session * @since 2010-03-14 - * @version SVN: $Id$ - * @filesource $URL$ */ class Session diff --git a/tests/LoadTest.php b/tests/LoadTest.php index 34f3097..a70e8cb 100644 --- a/tests/LoadTest.php +++ b/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() diff --git a/tests/app/Action_TestCase.php b/tests/app/Action_TestCase.php index d552117..92e61b9 100644 --- a/tests/app/Action_TestCase.php +++ b/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) + { + + } } \ No newline at end of file diff --git a/tests/app/AjaxActionTest.php b/tests/app/AjaxActionTest.php index b8c7c82..9cdce66 100644 --- a/tests/app/AjaxActionTest.php +++ b/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']); } } \ No newline at end of file diff --git a/tests/app/CliControllerTest.php b/tests/app/CliControllerTest.php index 7e6f719..bfbabfb 100644 --- a/tests/app/CliControllerTest.php +++ b/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'; diff --git a/tests/app/ErrorActionTest.php b/tests/app/ErrorActionTest.php index 15a8896..22fa903 100644 --- a/tests/app/ErrorActionTest.php +++ b/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,10 +27,9 @@ class ErrorActionTest extends Action_TestCase $this->log = ini_get('error_log'); ini_set('error_log', '/dev/null'); - set_exit_overload(function() - { - return false; - }); + 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) diff --git a/tests/app/FrontControllerTest.php b/tests/app/FrontControllerTest.php index 426cdfa..1d13571 100644 --- a/tests/app/FrontControllerTest.php +++ b/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,10 +26,9 @@ 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 { - + public function run(PHPUnit_Framework_TestResult $result = NULL) { $this->setPreserveGlobalState(false); @@ -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() + { + } } \ No newline at end of file diff --git a/tests/exception/Error404ExceptionTest.php b/tests/exception/Error404ExceptionTest.php index 1c53fff..8b2a1bf 100644 --- a/tests/exception/Error404ExceptionTest.php +++ b/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')); + } } \ No newline at end of file diff --git a/tests/exception/ErrorHTTPExceptionTest.php b/tests/exception/ErrorHTTPExceptionTest.php new file mode 100644 index 0000000..5aa418b --- /dev/null +++ b/tests/exception/ErrorHTTPExceptionTest.php @@ -0,0 +1,106 @@ + + * @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(); + } + } +} + diff --git a/tests/form/FormFieldTest.php b/tests/form/FormFieldTest.php index 07e932d..3c9baba 100644 --- a/tests/form/FormFieldTest.php +++ b/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'; diff --git a/tests/view/helpers/BreadcrumbVeiwHelperTest.php b/tests/view/helpers/BreadcrumbVeiwHelperTest.php index db4351b..d490280 100644 --- a/tests/view/helpers/BreadcrumbVeiwHelperTest.php +++ b/tests/view/helpers/BreadcrumbVeiwHelperTest.php @@ -16,45 +16,47 @@ require_once dirname(__FILE__) . '/../../../view/helpers/BreadcrumbViewHelper.ph class BreadcrumbViewHelperTest extends PHPUnit_Framework_TestCase { - + + /** + * @var BreadcrumbViewHelper + */ public $helper; - + public function setUp() { Registry::set('BreadcrumbViewHelper', array()); $this->helper = new BreadcrumbViewHelper(new PHPView('any')); } - + public function testTitle() { - $this->helper->breadcrumb('Guest page', 'guest.php'); + $this->helper->breadcrumb('Guest page', 'guest.php'); $result = Registry::get('BreadcrumbViewHelper'); - $this->assertSame(array('Guest page' => 'guest.php'), Registry::get('BreadcrumbViewHelper')); - + $this->assertSame(array('Guest page' => 'guest.php'), Registry::get('BreadcrumbViewHelper')); + $this->helper->prepend('Leave message', 'feedback.php'); - $this->assertSame(array('Leave message' => 'feedback.php', 'Guest page' => 'guest.php'), Registry::get('BreadcrumbViewHelper')); - + $this->assertSame(array('Leave message' => 'feedback.php', 'Guest page' => 'guest.php'), Registry::get('BreadcrumbViewHelper')); + $this->helper->append('Home page', 'home.php'); - $this->assertSame(array('Leave message' => 'feedback.php', 'Guest page' => 'guest.php', 'Home page' => 'home.php'), Registry::get('BreadcrumbViewHelper')); + $this->assertSame(array('Leave message' => 'feedback.php', 'Guest page' => 'guest.php', 'Home page' => 'home.php'), Registry::get('BreadcrumbViewHelper')); } - + public function testToString() { $this->helper->prepend('Home page', 'home.php'); - $this->helper->breadcrumb('Guest page', 'guest.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('Home page > Guest page > Leave message', $result); - + $this->helper->setSeparator('-'); $result = $this->helper->__toString(); $this->assertSame('Home page-Guest page-Leave message', $result); - + $this->helper->append('Last page', ''); $result = $this->helper->__toString(); $this->assertSame('Home page-Guest page-Leave message-Last page', $result); - } } diff --git a/tests/view/helpers/GetViewHelperTest.php b/tests/view/helpers/GetViewHelperTest.php index dac3f28..5449c74 100644 --- a/tests/view/helpers/GetViewHelperTest.php +++ b/tests/view/helpers/GetViewHelperTest.php @@ -18,14 +18,17 @@ require_once dirname(__FILE__) . '/../../../view/helpers/GetViewHelper.php'; class GetViewHelperTest extends PHPUnit_Framework_TestCase { - + + /** + * @var GetViewHelper + */ public $helper; - + public function setUp() { $this->helper = new GetViewHelper(new PHPView('any')); } - + /** * @TODO: GetViewHelper: initialize GetViewHelper::$get with empty array() */ @@ -34,7 +37,7 @@ class GetViewHelperTest extends PHPUnit_Framework_TestCase $this->setExpectedException('PHPUnit_Framework_Error'); $this->helper->get(null); } - + /** * @TODO: GetViewHelper: check $_GET not null */ @@ -43,7 +46,7 @@ class GetViewHelperTest extends PHPUnit_Framework_TestCase $this->setExpectedException('PHPUnit_Framework_Error'); $result = $this->helper->get('param'); } - + public function testGetWithSingleParam() { $_GET['a'] = 'b'; @@ -59,7 +62,7 @@ class GetViewHelperTest extends PHPUnit_Framework_TestCase $result = $this->helper->get(array('a')); $this->assertSame('?b=a', $result); } - + public function testGetWithArray() { $_GET['a'] = array('one' => 1, 'two' => 2); @@ -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&a[two]=2&b=c+d+e&c[five]=six+seven', $result); } - } diff --git a/tests/view/helpers/HeadViewHelperTest.php b/tests/view/helpers/HeadViewHelperTest.php index e75e52a..6887af9 100644 --- a/tests/view/helpers/HeadViewHelperTest.php +++ b/tests/view/helpers/HeadViewHelperTest.php @@ -16,32 +16,35 @@ require_once dirname(__FILE__) . '/../../../view/helpers/HeadViewHelper.php'; class HeadViewHelperTest extends PHPUnit_Framework_TestCase { - + + /** + * @var HeadViewHelper + */ public $helper; - + public function setUp() { Registry::set('HeadViewHelper', array()); $this->helper = new HeadViewHelper(null); } - + public function testHead() { - $this->helper->head(''); + $this->helper->head(''); $result = Registry::get('HeadViewHelper'); $this->assertSame(array(''), Registry::get('HeadViewHelper')); - - $this->helper->head(''); + + $this->helper->head(''); $this->assertSame(array('', ''), Registry::get('HeadViewHelper')); } - + public function testToString() { - $this->helper->head(''); - $this->helper->head(''); - + $this->helper->head(''); + $this->helper->head(''); + $result = $this->helper->__toString(); - + $this->assertSame("\n \n", $result); } } diff --git a/tests/view/helpers/MsgViewHelperTest.php b/tests/view/helpers/MsgViewHelperTest.php index 1c83619..d813937 100644 --- a/tests/view/helpers/MsgViewHelperTest.php +++ b/tests/view/helpers/MsgViewHelperTest.php @@ -19,25 +19,25 @@ require_once dirname(__FILE__) . '/../../../exception/GeneralException.php'; class MsgViewHelperTest extends PHPUnit_Framework_TestCase { - + /** + * @var MsgViewHelper + */ public $helper; - + public function setUp() { Session::del('MsgViewHelper'); $this->helper = new MsgViewHelper(new PHPView(array('path' => 'any'))); } - + public function testMsg() { - $this->helper->msg('new message from test', 'success'); + $this->helper->msg('new message from test', 'success'); $this->assertSame(array('message' => 'new message from test', 'type' => 'success'), Session::get('MsgViewHelper')); - - $this->assertSame($this->helper, $this->helper->msg('error message', 'error')); - $this->assertSame(array('message' => 'error message', 'type' => 'error'), Session::get('MsgViewHelper')); - + $this->assertSame($this->helper, $this->helper->msg('error message', 'error')); + $this->assertSame(array('message' => 'error message', 'type' => 'error'), Session::get('MsgViewHelper')); } public function testWrongType() @@ -45,31 +45,57 @@ class MsgViewHelperTest extends PHPUnit_Framework_TestCase $this->setExpectedException('GeneralException', 'Unknown message type'); $this->helper->msg('some message', 'wrong'); } - + public function testSuccess() { $this->helper->success('success message'); $this->assertSame(array('message' => 'success message', 'type' => 'success'), Session::get('MsgViewHelper')); } - + public function testError() { $this->helper->error('error message'); $this->assertSame(array('message' => 'error message', 'type' => 'error'), Session::get('MsgViewHelper')); $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'); $result = $this->helper->__toString(); $this->assertSame('
yeah
', $result); } - + public function testToStringEmpty() { $result = $this->helper->__toString(); $this->assertEmpty($result); } - + + public function testToStringWithPrefix() + { + $this->helper->success('yeah'); + $result = $this->helper->withPrefix('prefix')->__toString(); + $this->assertSame('
yeah
', $result); + } + + public function testToStringEmptyWithPrefix() + { + $result = $this->helper->withPrefix('prefix')->__toString(); + $this->assertEmpty($result); + } } diff --git a/tests/view/helpers/TitleViewHelperTest.php b/tests/view/helpers/TitleViewHelperTest.php index 4f040f3..03538c9 100644 --- a/tests/view/helpers/TitleViewHelperTest.php +++ b/tests/view/helpers/TitleViewHelperTest.php @@ -16,32 +16,34 @@ require_once dirname(__FILE__) . '/../../../view/helpers/TitleViewHelper.php'; class TitleViewHelperTest extends PHPUnit_Framework_TestCase { - + /** + * @var TitleViewHelper + */ public $helper; - + public function setUp() { Registry::set('TitleViewHelper', array()); $this->helper = new TitleViewHelper('view'); } - + public function testTitle() { - $this->helper->title('one'); + $this->helper->title('one'); $result = Registry::get('TitleViewHelper'); $this->assertSame(array('one'), Registry::get('TitleViewHelper')); - - $this->helper->title('two'); + + $this->helper->title('two'); $this->assertSame(array('one', 'two'), Registry::get('TitleViewHelper')); } - + public function testSeparator() { - $this->helper->title('one'); - $this->helper->title('two'); - + $this->helper->title('one'); + $this->helper->title('two'); + $this->assertSame('one - two', $this->helper->__toString()); $this->helper->setSeparator('='); - $this->assertSame('one=two', $this->helper->__toString()); + $this->assertSame('one=two', $this->helper->__toString()); } } diff --git a/util/AutoloadBuilder.php b/util/AutoloadBuilder.php index 1d1dad7..8adfaf6 100644 --- a/util/AutoloadBuilder.php +++ b/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 = "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(); } } } diff --git a/util/profiler/CommandProfiler.php b/util/profiler/CommandProfiler.php index 6837692..21f97be 100644 --- a/util/profiler/CommandProfiler.php +++ b/util/profiler/CommandProfiler.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage util * @since 2010-03-09 - * @version SVN: $Id$ - * @filesource $URL$ */ class CommandProfiler diff --git a/util/profiler/Profiler.php b/util/profiler/Profiler.php index dbce47b..e72fb8a 100644 --- a/util/profiler/Profiler.php +++ b/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; diff --git a/validator/EmailValidator.php b/validator/EmailValidator.php index fc83b6c..78c0731 100644 --- a/validator/EmailValidator.php +++ b/validator/EmailValidator.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage validator * @since 2010-04-26 - * @version SVN: $Id$ - * @filesource $URL$ */ class EmailValidator extends RegexValidator diff --git a/validator/EqualValidator.php b/validator/EqualValidator.php index feda85a..961672f 100644 --- a/validator/EqualValidator.php +++ b/validator/EqualValidator.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage validator * @since 2010-04-26 - * @version SVN: $Id$ - * @filesource $URL$ */ class EqualValidator extends Validator diff --git a/validator/NotEmptyValidator.php b/validator/NotEmptyValidator.php index a9e62b6..13bded2 100644 --- a/validator/NotEmptyValidator.php +++ b/validator/NotEmptyValidator.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage validator * @since 2010-04-26 - * @version SVN: $Id$ - * @filesource $URL$ */ class NotEmptyValidator extends Validator diff --git a/validator/RegexValidator.php b/validator/RegexValidator.php index 4bf322d..a198db4 100644 --- a/validator/RegexValidator.php +++ b/validator/RegexValidator.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage validator * @since 2010-04-26 - * @version SVN: $Id$ - * @filesource $URL$ */ class RegexValidator extends Validator diff --git a/validator/Validator.php b/validator/Validator.php index b50c132..3f875b9 100644 --- a/validator/Validator.php +++ b/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 diff --git a/validator/iValidator.php b/validator/iValidator.php index 66bae7c..2130ad6 100644 --- a/validator/iValidator.php +++ b/validator/iValidator.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage validator * @since 2010-04-25 - * @version SVN: $Id$ - * @filesource $URL$ */ interface iValidator diff --git a/view/PHPView.php b/view/PHPView.php index 9ae33be..877f7de 100644 --- a/view/PHPView.php +++ b/view/PHPView.php @@ -5,22 +5,30 @@ * @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 $path = ''; + protected $variables = array(); - protected $helpers = array(); + + protected $helpers = array(); + protected $extension = '.phtml'; - protected $template = ''; - + + protected $template = ''; + public function __construct($config) { if (!isset($config['path'])) { @@ -28,17 +36,17 @@ class PHPView implements iView } $this->setPath($config['path']); } - + public function getPath() { return $this->path; } - + public function setPath($path) { $this->path = $path; } - + /** * @param Action $object */ @@ -48,7 +56,7 @@ class PHPView implements iView $this->assign($name, $value); } } - + /** * @param string $name * @param mixed $value @@ -57,7 +65,7 @@ class PHPView implements iView { $this->variables[$name] = $value; } - + /** * @param string $name * @param mixed $value @@ -70,7 +78,7 @@ class PHPView implements iView $this->variables[$name] = $value; } } - + /** * @param string $name * @param mixed $value @@ -83,7 +91,7 @@ class PHPView implements iView $this->variables[$name] = $value; } } - + public function fetch($template) { $this->template = $this->getTemplatePath($template); @@ -92,20 +100,20 @@ 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(); } - + public function escape($var) { return htmlentities($var, ENT_QUOTES, 'UTF-8'); } - + /** * Helpers call - * + * * @param mixed $name * @param mixed $args * @return ViewHelper @@ -115,7 +123,7 @@ class PHPView implements iView $helper = $this->getHelper($name); return call_user_func_array(array($helper, $name), $args); } - + protected function getHelper($name) { if (!isset($this->helpers[$name])) { @@ -127,7 +135,7 @@ class PHPView implements iView } return $this->helpers[$name]; } - + protected function getTemplatePath($template) { return $this->path . $template . $this->extension; diff --git a/view/helpers/BreadcrumbViewHelper.php b/view/helpers/BreadcrumbViewHelper.php index 04df5be..defa0ba 100644 --- a/view/helpers/BreadcrumbViewHelper.php +++ b/view/helpers/BreadcrumbViewHelper.php @@ -5,15 +5,13 @@ * @package Majestic * @subpackage View * @since 2010-03-16 - * @version SVN: $Id$ - * @filesource $URL$ */ class BreadcrumbViewHelper extends ViewHelper { - + protected $separator = ' > '; - + public function breadcrumb($text = false, $href = false) { if ($text) { @@ -21,22 +19,22 @@ class BreadcrumbViewHelper extends ViewHelper } return $this; } - + public function prepend($text, $href) { Registry::set(__CLASS__, array($text => $href) + Registry::get(__CLASS__, array())); } - + public function append($text, $href) { Registry::set(__CLASS__, Registry::get(__CLASS__, array()) + array($text => $href)); } - + public function setSeparator($sep) { $this->separator = $sep; } - + public function __toString() { $data = array(); diff --git a/view/helpers/GetViewHelper.php b/view/helpers/GetViewHelper.php index 78cb75a..430d342 100644 --- a/view/helpers/GetViewHelper.php +++ b/view/helpers/GetViewHelper.php @@ -5,15 +5,13 @@ * @package Majestic * @subpackage View * @since 2010-03-09 - * @version SVN: $Id$ - * @filesource $URL$ */ class GetViewHelper extends ViewHelper { - + protected $get; - + public function get($replace) { $get = $this->getSanitizedRequest(); @@ -29,7 +27,7 @@ class GetViewHelper extends ViewHelper } return '?' . $this->view->escape(implode('&', $get)); } - + protected function getSanitizedRequest() { if ($this->get === null) { @@ -40,10 +38,10 @@ class GetViewHelper extends ViewHelper } return $this->get; } - + 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); diff --git a/view/helpers/HeadViewHelper.php b/view/helpers/HeadViewHelper.php index ffbb444..761383d 100644 --- a/view/helpers/HeadViewHelper.php +++ b/view/helpers/HeadViewHelper.php @@ -5,13 +5,11 @@ * @package Majestic * @subpackage View * @since 2010-03-16 - * @version SVN: $Id$ - * @filesource $URL$ */ class HeadViewHelper extends ViewHelper { - + public function head($string = false) { if ($string) { @@ -21,7 +19,7 @@ class HeadViewHelper extends ViewHelper } return $this; } - + public function __toString() { return implode("\n ", Registry::get(__CLASS__, array())) . "\n"; diff --git a/view/helpers/MsgViewHelper.php b/view/helpers/MsgViewHelper.php index b548ff7..0a2b89f 100644 --- a/view/helpers/MsgViewHelper.php +++ b/view/helpers/MsgViewHelper.php @@ -5,45 +5,69 @@ * @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() { $msg = Session::get(__CLASS__, false); if ($msg) { Session::del(__CLASS__); - return '
' . $this->view->escape($msg['message']) . '
'; + return '
' . $this->view->escape($msg['message']) . '
'; } return ''; } diff --git a/view/helpers/TitleViewHelper.php b/view/helpers/TitleViewHelper.php index 812230d..d69dca2 100644 --- a/view/helpers/TitleViewHelper.php +++ b/view/helpers/TitleViewHelper.php @@ -5,15 +5,13 @@ * @package Majestic * @subpackage View * @since 2010-03-16 - * @version SVN: $Id$ - * @filesource $URL$ */ class TitleViewHelper extends ViewHelper { - + protected $separator = ' - '; - + public function title($string = false) { if ($string) { @@ -23,12 +21,12 @@ class TitleViewHelper extends ViewHelper } return $this; } - + public function setSeparator($sep) { $this->separator = $sep; } - + public function __toString() { return implode($this->separator, Registry::get(__CLASS__, array())); diff --git a/view/helpers/ViewHelper.php b/view/helpers/ViewHelper.php index 177666d..a092228 100644 --- a/view/helpers/ViewHelper.php +++ b/view/helpers/ViewHelper.php @@ -5,18 +5,16 @@ * @package Majestic * @subpackage View * @since 2010-03-09 - * @version SVN: $Id$ - * @filesource $URL$ */ abstract class ViewHelper { - + /** * @var PHPView */ protected $view = null; - + public function __construct($view) { $this->view = $view; diff --git a/view/iView.php b/view/iView.php index b471c03..82c9733 100644 --- a/view/iView.php +++ b/view/iView.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage View * @since 2010-02-25 - * @version SVN: $Id$ - * @filesource $URL$ */ interface iView