From 4f553330644aa8a6fb3cda9fabd65b5a0bfbe754 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Sat, 10 Nov 2012 15:55:11 +0400 Subject: [PATCH 01/21] PHPdoc updated --- app/FrontController.php | 7 +++++-- app/router/Router.php | 21 ++++++++++++++++++--- layout/Layout.php | 8 +++++++- redis/RedisDebug.php | 2 -- redis/RedisManager.php | 3 ++- redis/redis.php | 3 ++- 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/app/FrontController.php b/app/FrontController.php index cb31776..cbf4c65 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')) { 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/layout/Layout.php b/layout/Layout.php index 9c5eaae..ee75ac1 100644 --- a/layout/Layout.php +++ b/layout/Layout.php @@ -56,7 +56,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 +66,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/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..b329f11 100644 --- a/redis/RedisManager.php +++ b/redis/RedisManager.php @@ -15,7 +15,7 @@ class RedisManager /** * Redis connections * - * @var array + * @var Redis[] */ static protected $connections = array(); @@ -25,6 +25,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 From 4fa078d709634f5a4c305ab54b7d3e1f0bcedf3f Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Sat, 10 Nov 2012 16:06:19 +0400 Subject: [PATCH 02/21] Fixes for AjaxAction to send different header Content-type with $this->json_encode == true and $this->json_encode == false . This includes refactoring of $this->encode to $this->json_encode. --- app/AjaxAction.php | 29 +++++++++++++++++++---------- tests/app/AjaxActionTest.php | 2 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/AjaxAction.php b/app/AjaxAction.php index c91affe..bab999e 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 { + /** + * Data to output + * @var mixed + */ public $data = 1; - 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/tests/app/AjaxActionTest.php b/tests/app/AjaxActionTest.php index b8c7c82..f19583a 100644 --- a/tests/app/AjaxActionTest.php +++ b/tests/app/AjaxActionTest.php @@ -51,7 +51,7 @@ class AjaxActionTest extends Action_TestCase { 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' ); From 2aafb3a3943f003322a1fdf92bfd89a015009e3b Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Sun, 11 Nov 2012 13:51:38 +0400 Subject: [PATCH 03/21] New default value for AjaxAction->data, new tests --- app/AjaxAction.php | 2 +- tests/app/Action_TestCase.php | 15 ++++++++++++-- tests/app/AjaxActionTest.php | 46 +++++++++++++++++++++++++++++++++++-------- 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/app/AjaxAction.php b/app/AjaxAction.php index bab999e..f007350 100644 --- a/app/AjaxAction.php +++ b/app/AjaxAction.php @@ -18,7 +18,7 @@ abstract class AjaxAction extends Action * Data to output * @var mixed */ - public $data = 1; + public $data = false; /** * Use json_encode 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 f19583a..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('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 From 618f12224ea1fc7068e447eb7d08591c369b4e04 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Sun, 11 Nov 2012 18:31:57 +0400 Subject: [PATCH 04/21] Revorked Error404Exception . New ErrorHTTPException introduced. --- exception/Error404Exception.php | 9 ++- exception/ErrorHTTPException.php | 39 +++++++++++ tests/app/CliControllerTest.php | 1 + tests/app/FrontControllerTest.php | 1 + tests/exception/Error404ExceptionTest.php | 11 ++- tests/exception/ErrorHTTPExceptionTest.php | 106 +++++++++++++++++++++++++++++ 6 files changed, 162 insertions(+), 5 deletions(-) create mode 100644 exception/ErrorHTTPException.php create mode 100644 tests/exception/ErrorHTTPExceptionTest.php 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/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/FrontControllerTest.php b/tests/app/FrontControllerTest.php index 426cdfa..0385889 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'; 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(); + } + } +} + From e1c3da80198dc386c8484117d10a9f737a2cd265 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Sun, 11 Nov 2012 20:42:48 +0400 Subject: [PATCH 05/21] Reworked AJax action HTTP code and HTTP content. Added new HTTP template to process HTTP code output --- app/ErrorAction.php | 51 +++++++++++++++++++++------------------ app/FrontController.php | 6 ++++- tests/app/ErrorActionTest.php | 45 +++++++++++++++++++++++++--------- tests/app/FrontControllerTest.php | 43 +++++++++++++++++++++++++++++++-- 4 files changed, 106 insertions(+), 39 deletions(-) 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 cbf4c65..4d8f75e 100644 --- a/app/FrontController.php +++ b/app/FrontController.php @@ -142,7 +142,11 @@ class FrontController */ $layout = new $layout_class(); $layout->setException($e); - return $layout->fetch(new ErrorAction($e)); + $error_action = new ErrorAction($e); + if (isset($action) && is_subclass_of($action, 'AjaxAction')) { + $error_action->setAjax(); + } + return $layout->fetch($error_action); } } } \ No newline at end of file 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 0385889..8496bd8 100644 --- a/tests/app/FrontControllerTest.php +++ b/tests/app/FrontControllerTest.php @@ -26,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); @@ -133,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()); } @@ -193,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 */ @@ -209,6 +228,23 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase $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) { @@ -237,6 +273,9 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase } } +/** + * Used in testExecuteWithAjaxAction + */ class NewAjaxAction extends AjaxAction{ protected function execute() {} } \ No newline at end of file From 008eee4c8cf32387a96197e322a8824e788e4f21 Mon Sep 17 00:00:00 2001 From: Anton Grebnev Date: Mon, 12 Nov 2012 13:52:11 +0400 Subject: [PATCH 06/21] fixed ErrorAction::setAjaxError() method call in FrontController --- app/FrontController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/FrontController.php b/app/FrontController.php index 4d8f75e..2de211b 100644 --- a/app/FrontController.php +++ b/app/FrontController.php @@ -144,7 +144,7 @@ class FrontController $layout->setException($e); $error_action = new ErrorAction($e); if (isset($action) && is_subclass_of($action, 'AjaxAction')) { - $error_action->setAjax(); + $error_action->setAjaxError(); } return $layout->fetch($error_action); } From 5cc54e182e2143b78ceee497decb8d4799b51127 Mon Sep 17 00:00:00 2001 From: Alexander Demidov Date: Mon, 12 Nov 2012 19:30:25 +0400 Subject: [PATCH 07/21] Modify FronController with use class_name in is_subclass_of. --- app/FrontController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/FrontController.php b/app/FrontController.php index 2de211b..bd5f13d 100644 --- a/app/FrontController.php +++ b/app/FrontController.php @@ -143,7 +143,7 @@ class FrontController $layout = new $layout_class(); $layout->setException($e); $error_action = new ErrorAction($e); - if (isset($action) && is_subclass_of($action, 'AjaxAction')) { + if (isset($action_class) && is_subclass_of($action_class, 'AjaxAction')) { $error_action->setAjaxError(); } return $layout->fetch($error_action); From 6a2c861a711de73fbc12768a83c08175897dc085 Mon Sep 17 00:00:00 2001 From: Alexander Demidov Date: Tue, 13 Nov 2012 14:03:42 +0400 Subject: [PATCH 08/21] Switch http code header on showDebug with ErrorHTTPException. --- app/FrontController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/FrontController.php b/app/FrontController.php index bd5f13d..43bbec9 100644 --- a/app/FrontController.php +++ b/app/FrontController.php @@ -131,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); } From 2d02f25e2236eeab016305ca5368fffcb69c0949 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Fri, 16 Nov 2012 18:31:15 +0400 Subject: [PATCH 09/21] Some PHPDoc for PHPView --- view/PHPView.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/view/PHPView.php b/view/PHPView.php index 9ae33be..314a862 100644 --- a/view/PHPView.php +++ b/view/PHPView.php @@ -10,7 +10,12 @@ */ /** - * @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 setcion for TITLE of Layout + * */ class PHPView implements iView { From 1e0d1aaa38305f04cb371a94341ea6ac13d1e07a Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Mon, 19 Nov 2012 18:40:04 +0400 Subject: [PATCH 10/21] PHPDocs for cache, Format --- cache/Cache.php | 35 ++++++++++++++-------------- cache/CacheKey.php | 3 ++- cache/Cacher.php | 6 +++++ cache/MemcacheCache.php | 59 +++++++++++++++++++++++++----------------------- classes/Format.class.php | 3 ++- 5 files changed, 58 insertions(+), 48 deletions(-) diff --git a/cache/Cache.php b/cache/Cache.php index b2196ea..f68d10b 100644 --- a/cache/Cache.php +++ b/cache/Cache.php @@ -11,72 +11,71 @@ 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..d7a4aeb 100644 --- a/cache/CacheKey.php +++ b/cache/CacheKey.php @@ -13,7 +13,7 @@ class CacheKey { /** - * @var Cacher + * @var Cache */ protected $cacher; @@ -62,6 +62,7 @@ class CacheKey /** * @param mixed $value + * @return bool */ public function set($value) { diff --git a/cache/Cacher.php b/cache/Cacher.php index b662c57..0d35887 100644 --- a/cache/Cacher.php +++ b/cache/Cacher.php @@ -19,6 +19,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..aa6b5cc 100644 --- a/cache/MemcacheCache.php +++ b/cache/MemcacheCache.php @@ -11,31 +11,33 @@ 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 +48,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 +61,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 +73,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 +106,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 +118,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 +145,7 @@ class MemcacheCache extends Cache { return $this->connection->set($this->getKey($key), $value, null, $this->getExpire($expire)); } - + /** * @param string $key * @return string @@ -151,7 +154,7 @@ class MemcacheCache extends Cache { return md5($this->key_salt . $key); } - + public function getExpire($expire) { return ($expire > 0) ? $expire : $this->expire; diff --git a/classes/Format.class.php b/classes/Format.class.php index 215ef30..fbefc25 100644 --- a/classes/Format.class.php +++ b/classes/Format.class.php @@ -47,6 +47,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 +170,7 @@ class Format * Преобразует дату в таймстамп. * * @param mixed $time - * @return TimeFormat + * @return int|bool */ static public function date2int($time) { From 1354f3d001ae6c94febe6a0d109260a06300e869 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Mon, 19 Nov 2012 19:20:15 +0400 Subject: [PATCH 11/21] PHPDoc, some trailing PHP tags removed --- app/router/Route.php | 1 + classes/Format.class.php | 1 - classes/User.class.php | 1 - exception/ErrorHandler.php | 1 + form/Form.php | 68 ++++++++++++++++++++++--------- form/FormField.php | 99 ++++++++++++++++++++++++++++++++++------------ i18n/I18N.php | 7 ++-- model/MongoStatement.php | 1 + 8 files changed, 129 insertions(+), 50 deletions(-) diff --git a/app/router/Route.php b/app/router/Route.php index 7f42f31..4f2a623 100644 --- a/app/router/Route.php +++ b/app/router/Route.php @@ -27,6 +27,7 @@ class Route /** * @param array $request + * @return bool */ public function match($request) { diff --git a/classes/Format.class.php b/classes/Format.class.php index fbefc25..f5c6b06 100644 --- a/classes/Format.class.php +++ b/classes/Format.class.php @@ -229,4 +229,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..06ff07f 100644 --- a/classes/User.class.php +++ b/classes/User.class.php @@ -116,4 +116,3 @@ class User return $model->getById($id); } } -?> \ No newline at end of file diff --git a/exception/ErrorHandler.php b/exception/ErrorHandler.php index 954f8dc..058f9f6 100644 --- a/exception/ErrorHandler.php +++ b/exception/ErrorHandler.php @@ -73,6 +73,7 @@ class ErrorHandler /** * @param Exception $exception + * @return string */ static public function showDebug($exception) { diff --git a/form/Form.php b/form/Form.php index c867b0d..ea4d233 100644 --- a/form/Form.php +++ b/form/Form.php @@ -13,21 +13,31 @@ 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 +45,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 +64,7 @@ abstract class Form } return $this->valid; } - + public function getMessages() { $messages = array(); @@ -65,7 +75,7 @@ abstract class Form } return $messages; } - + public function getValue($key) { if (isset($this->fields[$key])) { @@ -73,7 +83,10 @@ abstract class Form } return false; } - + + /** + * @return array + */ public function getValues() { $values = array(); @@ -84,7 +97,10 @@ abstract class Form } return $values; } - + + /** + * @return array + */ public function getSourceValues() { $values = array(); @@ -93,35 +109,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..2e8a345 100644 --- a/form/FormField.php +++ b/form/FormField.php @@ -1,7 +1,7 @@ - * @link http://netmonsters.ru + * @link http://netmonsters.ru * @package Majestic * @subpackage form * @since 2010-04-25 @@ -11,51 +11,93 @@ 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 +105,12 @@ class FormField } return $this; } - + + /** + * @param string|iValidator $validator + * @return FormField + * @throws InitializationException + */ public function addValidator($validator) { if ($validator instanceof iValidator) { @@ -77,7 +124,7 @@ class FormField $this->validators[$name] = $validator; return $this; } - + public function addFilters($filters) { foreach ($filters as $filter) { @@ -85,10 +132,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 +146,7 @@ class FormField $this->filters[$name] = $filter; return $this; } - + public function getValue() { $value = $this->value; @@ -110,10 +157,10 @@ class FormField } return $value; } - + /** * $value & $key for array_walk_recursive - * + * * @param mixed $value * @param mixed $key */ @@ -123,24 +170,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 +205,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/i18n/I18N.php b/i18n/I18N.php index 1867436..2dd043a 100644 --- a/i18n/I18N.php +++ b/i18n/I18N.php @@ -20,10 +20,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/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) From fa67637c67253a60793cd5277fe65177aa041bd6 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Mon, 19 Nov 2012 19:25:38 +0400 Subject: [PATCH 12/21] PHPDoc --- logger/FileLogger.php | 3 +++ util/profiler/Profiler.php | 9 +++++++++ 2 files changed, 12 insertions(+) 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/util/profiler/Profiler.php b/util/profiler/Profiler.php index dbce47b..6ad272c 100644 --- a/util/profiler/Profiler.php +++ b/util/profiler/Profiler.php @@ -12,10 +12,19 @@ class Profiler { + /** + * @var int + */ protected $start = null; + /** + * @var int + */ protected $end = null; + /** + * @var CommandProfiler[] + */ protected $queries = array(); static protected $instance = null; From a789ad8966235116445ce41eb68b57255f39e948 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Wed, 21 Nov 2012 14:31:43 +0400 Subject: [PATCH 13/21] More strict test on autoload --- tests/LoadTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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() From 3517a6450cea7b463c93e718ae30a834e853cd87 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Wed, 21 Nov 2012 14:47:35 +0400 Subject: [PATCH 14/21] Test for calling ErrorAction->setAjaxError() for ajax-based actions --- tests/app/FrontControllerTest.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/app/FrontControllerTest.php b/tests/app/FrontControllerTest.php index 8496bd8..1d13571 100644 --- a/tests/app/FrontControllerTest.php +++ b/tests/app/FrontControllerTest.php @@ -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')); } @@ -231,6 +231,21 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase /** * @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); @@ -276,6 +291,9 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase /** * Used in testExecuteWithAjaxAction */ -class NewAjaxAction extends AjaxAction{ - protected function execute() {} +class NewAjaxAction extends AjaxAction +{ + protected function execute() + { + } } \ No newline at end of file From 0d58a907e52918148b6eca16c450d0e4ef730b5a Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Wed, 21 Nov 2012 15:09:13 +0400 Subject: [PATCH 15/21] Refuse cloning of CliController --- app/CliController.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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(); From 07a244ca35f63bcc0ecb12938e39626bb475df9a Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Wed, 21 Nov 2012 15:43:20 +0400 Subject: [PATCH 16/21] Code formatting for ViewHelper & tests --- tests/view/helpers/BreadcrumbVeiwHelperTest.php | 34 +++++++++++++------------ tests/view/helpers/GetViewHelperTest.php | 16 +++++++----- tests/view/helpers/HeadViewHelperTest.php | 25 ++++++++++-------- tests/view/helpers/MsgViewHelperTest.php | 23 ++++++++--------- tests/view/helpers/TitleViewHelperTest.php | 24 +++++++++-------- view/helpers/BreadcrumbViewHelper.php | 12 ++++----- view/helpers/GetViewHelper.php | 10 ++++---- view/helpers/HeadViewHelper.php | 4 +-- view/helpers/MsgViewHelper.php | 6 ++--- view/helpers/TitleViewHelper.php | 8 +++--- view/helpers/ViewHelper.php | 4 +-- 11 files changed, 87 insertions(+), 79 deletions(-) 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..d9405e9 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,13 +45,13 @@ 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'); @@ -65,11 +65,10 @@ class MsgViewHelperTest extends PHPUnit_Framework_TestCase $result = $this->helper->__toString(); $this->assertSame('
yeah
', $result); } - + public function testToStringEmpty() { $result = $this->helper->__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/view/helpers/BreadcrumbViewHelper.php b/view/helpers/BreadcrumbViewHelper.php index 04df5be..10f8122 100644 --- a/view/helpers/BreadcrumbViewHelper.php +++ b/view/helpers/BreadcrumbViewHelper.php @@ -11,9 +11,9 @@ class BreadcrumbViewHelper extends ViewHelper { - + protected $separator = ' > '; - + public function breadcrumb($text = false, $href = false) { if ($text) { @@ -21,22 +21,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..d0d488b 100644 --- a/view/helpers/GetViewHelper.php +++ b/view/helpers/GetViewHelper.php @@ -11,9 +11,9 @@ class GetViewHelper extends ViewHelper { - + protected $get; - + public function get($replace) { $get = $this->getSanitizedRequest(); @@ -29,7 +29,7 @@ class GetViewHelper extends ViewHelper } return '?' . $this->view->escape(implode('&', $get)); } - + protected function getSanitizedRequest() { if ($this->get === null) { @@ -40,10 +40,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..f797056 100644 --- a/view/helpers/HeadViewHelper.php +++ b/view/helpers/HeadViewHelper.php @@ -11,7 +11,7 @@ class HeadViewHelper extends ViewHelper { - + public function head($string = false) { if ($string) { @@ -21,7 +21,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..c45bdc4 100644 --- a/view/helpers/MsgViewHelper.php +++ b/view/helpers/MsgViewHelper.php @@ -11,7 +11,7 @@ class MsgViewHelper extends ViewHelper { - + const SUCCESS = 'success'; const ERROR = 'error'; @@ -27,12 +27,12 @@ class MsgViewHelper extends ViewHelper } return $this; } - + public function success($msg) { Session::set(__CLASS__, array('message' => $msg, 'type' => self::SUCCESS)); } - + public function error($msg) { Session::set(__CLASS__, array('message' => $msg, 'type' => self::ERROR)); diff --git a/view/helpers/TitleViewHelper.php b/view/helpers/TitleViewHelper.php index 812230d..56fd7c7 100644 --- a/view/helpers/TitleViewHelper.php +++ b/view/helpers/TitleViewHelper.php @@ -11,9 +11,9 @@ class TitleViewHelper extends ViewHelper { - + protected $separator = ' - '; - + public function title($string = false) { if ($string) { @@ -23,12 +23,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..59a52cb 100644 --- a/view/helpers/ViewHelper.php +++ b/view/helpers/ViewHelper.php @@ -11,12 +11,12 @@ abstract class ViewHelper { - + /** * @var PHPView */ protected $view = null; - + public function __construct($view) { $this->view = $view; From 706f7a444467d526535cd539656a5d8f10c9db55 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Wed, 21 Nov 2012 15:50:28 +0400 Subject: [PATCH 17/21] typo --- view/PHPView.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/PHPView.php b/view/PHPView.php index 314a862..8c74c9d 100644 --- a/view/PHPView.php +++ b/view/PHPView.php @@ -14,7 +14,7 @@ * @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 setcion for TITLE of Layout + * @method TitleViewHelper title() title(string $string = false) Append another section for TITLE of Layout * */ class PHPView implements iView From e5a0df37fc6971a5b1fd72f7b42d7e7bfbe236b1 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Wed, 21 Nov 2012 17:44:52 +0400 Subject: [PATCH 18/21] Added FormViewHelper @method form() to PHPView --- view/PHPView.php | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/view/PHPView.php b/view/PHPView.php index 8c74c9d..877f7de 100644 --- a/view/PHPView.php +++ b/view/PHPView.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage View * @since 2010-02-25 - * @version SVN: $Id$ - * @filesource $URL$ */ /** @@ -15,17 +13,22 @@ * @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'])) { @@ -33,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 */ @@ -53,7 +56,7 @@ class PHPView implements iView $this->assign($name, $value); } } - + /** * @param string $name * @param mixed $value @@ -62,7 +65,7 @@ class PHPView implements iView { $this->variables[$name] = $value; } - + /** * @param string $name * @param mixed $value @@ -75,7 +78,7 @@ class PHPView implements iView $this->variables[$name] = $value; } } - + /** * @param string $name * @param mixed $value @@ -88,7 +91,7 @@ class PHPView implements iView $this->variables[$name] = $value; } } - + public function fetch($template) { $this->template = $this->getTemplatePath($template); @@ -97,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 @@ -120,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])) { @@ -132,7 +135,7 @@ class PHPView implements iView } return $this->helpers[$name]; } - + protected function getTemplatePath($template) { return $this->path . $template . $this->extension; From 6b9c07605302d2cb9ac7589649d1c63edfd16c74 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Wed, 21 Nov 2012 18:11:38 +0400 Subject: [PATCH 19/21] Added new message types: info, warning to MgsViewHelper. Added method withPrefix to add custom css prefix to message --- tests/view/helpers/MsgViewHelperTest.php | 29 ++++++++++++++++++++- view/helpers/MsgViewHelper.php | 44 +++++++++++++++++++++++++------- 2 files changed, 63 insertions(+), 10 deletions(-) diff --git a/tests/view/helpers/MsgViewHelperTest.php b/tests/view/helpers/MsgViewHelperTest.php index d9405e9..d813937 100644 --- a/tests/view/helpers/MsgViewHelperTest.php +++ b/tests/view/helpers/MsgViewHelperTest.php @@ -58,7 +58,21 @@ class MsgViewHelperTest extends PHPUnit_Framework_TestCase $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'); @@ -71,4 +85,17 @@ class MsgViewHelperTest extends PHPUnit_Framework_TestCase $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/view/helpers/MsgViewHelper.php b/view/helpers/MsgViewHelper.php index c45bdc4..8a1e335 100644 --- a/view/helpers/MsgViewHelper.php +++ b/view/helpers/MsgViewHelper.php @@ -13,37 +13,63 @@ 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 ''; } From a856dd484e76fe96d0b231ed5899803361624960 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Wed, 21 Nov 2012 18:42:29 +0400 Subject: [PATCH 20/21] Removed @version and @filesource from PHPDocs --- Config.php | 2 -- Load.php | 2 -- Registry.php | 2 -- app/Action.php | 2 -- app/PagerAction.php | 2 -- app/StaticAction.php | 2 -- app/router/Route.php | 2 -- cache/Cache.php | 2 -- cache/CacheKey.php | 2 -- cache/Cacher.php | 2 -- cache/MemcacheCache.php | 2 -- captcha/Captcha.php | 2 -- captcha/CaptchaImageAction.php | 2 -- captcha/CaptchaValidator.php | 2 -- classes/Env.class.php | 2 -- classes/Format.class.php | 2 -- classes/User.class.php | 2 -- exception/ErrorHandler.php | 2 -- exception/GeneralException.php | 2 -- form/Form.php | 2 -- form/FormField.php | 2 -- form/FormViewHelper.php | 2 -- i18n/I18N.php | 2 -- layout/Error.layout.php | 2 -- layout/Layout.php | 2 -- mail/Mailer.php | 2 -- model/Db.php | 2 -- model/DbDriver.php | 2 -- model/DbExpr.php | 2 -- model/DbStatement.php | 2 -- model/Model.php | 2 -- model/MySQLiDriver.php | 2 -- model/MySQLiStatement.php | 2 -- redis/RedisManager.php | 2 -- session/Session.model.php | 2 -- session/Session.php | 2 -- tests/form/FormFieldTest.php | 2 -- util/AutoloadBuilder.php | 2 -- util/profiler/CommandProfiler.php | 2 -- util/profiler/Profiler.php | 2 -- validator/EmailValidator.php | 2 -- validator/EqualValidator.php | 2 -- validator/NotEmptyValidator.php | 2 -- validator/RegexValidator.php | 2 -- validator/Validator.php | 2 -- validator/iValidator.php | 2 -- view/helpers/BreadcrumbViewHelper.php | 2 -- view/helpers/GetViewHelper.php | 2 -- view/helpers/HeadViewHelper.php | 2 -- view/helpers/MsgViewHelper.php | 2 -- view/helpers/TitleViewHelper.php | 2 -- view/helpers/ViewHelper.php | 2 -- view/iView.php | 2 -- 53 files changed, 106 deletions(-) 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/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 4f2a623..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 diff --git a/cache/Cache.php b/cache/Cache.php index f68d10b..bc97f36 100644 --- a/cache/Cache.php +++ b/cache/Cache.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage Cache * @since 2010-03-04 - * @version SVN: $Id$ - * @filesource $URL$ */ abstract class Cache diff --git a/cache/CacheKey.php b/cache/CacheKey.php index d7a4aeb..61678f0 100644 --- a/cache/CacheKey.php +++ b/cache/CacheKey.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage Cache * @since 2010-03-10 - * @version SVN: $Id$ - * @filesource $URL$ */ class CacheKey diff --git a/cache/Cacher.php b/cache/Cacher.php index 0d35887..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 diff --git a/cache/MemcacheCache.php b/cache/MemcacheCache.php index aa6b5cc..91430e3 100644 --- a/cache/MemcacheCache.php +++ b/cache/MemcacheCache.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage Cache * @since 2010-03-04 - * @version SVN: $Id$ - * @filesource $URL$ */ class MemcacheCache extends Cache 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 f5c6b06..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$ */ /** diff --git a/classes/User.class.php b/classes/User.class.php index 06ff07f..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 { diff --git a/exception/ErrorHandler.php b/exception/ErrorHandler.php index 058f9f6..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 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 ea4d233..fd061b9 100644 --- a/form/Form.php +++ b/form/Form.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage form * @since 2010-04-24 - * @version SVN: $Id$ - * @filesource $URL$ */ abstract class Form diff --git a/form/FormField.php b/form/FormField.php index 2e8a345..99683b6 100644 --- a/form/FormField.php +++ b/form/FormField.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage form * @since 2010-04-25 - * @version SVN: $Id$ - * @filesource $URL$ */ class FormField 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 2dd043a..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 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 ee75ac1..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 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/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/RedisManager.php b/redis/RedisManager.php index b329f11..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 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/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/util/AutoloadBuilder.php b/util/AutoloadBuilder.php index 1d1dad7..14e4d2c 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$ */ /** 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 6ad272c..e72fb8a 100644 --- a/util/profiler/Profiler.php +++ b/util/profiler/Profiler.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage util * @since 2010-03-09 - * @version SVN: $Id$ - * @filesource $URL$ */ class Profiler 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/helpers/BreadcrumbViewHelper.php b/view/helpers/BreadcrumbViewHelper.php index 10f8122..defa0ba 100644 --- a/view/helpers/BreadcrumbViewHelper.php +++ b/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 diff --git a/view/helpers/GetViewHelper.php b/view/helpers/GetViewHelper.php index d0d488b..430d342 100644 --- a/view/helpers/GetViewHelper.php +++ b/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 diff --git a/view/helpers/HeadViewHelper.php b/view/helpers/HeadViewHelper.php index f797056..761383d 100644 --- a/view/helpers/HeadViewHelper.php +++ b/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 diff --git a/view/helpers/MsgViewHelper.php b/view/helpers/MsgViewHelper.php index 8a1e335..0a2b89f 100644 --- a/view/helpers/MsgViewHelper.php +++ b/view/helpers/MsgViewHelper.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage View * @since 2010-03-09 - * @version SVN: $Id$ - * @filesource $URL$ */ class MsgViewHelper extends ViewHelper diff --git a/view/helpers/TitleViewHelper.php b/view/helpers/TitleViewHelper.php index 56fd7c7..d69dca2 100644 --- a/view/helpers/TitleViewHelper.php +++ b/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 diff --git a/view/helpers/ViewHelper.php b/view/helpers/ViewHelper.php index 59a52cb..a092228 100644 --- a/view/helpers/ViewHelper.php +++ b/view/helpers/ViewHelper.php @@ -5,8 +5,6 @@ * @package Majestic * @subpackage View * @since 2010-03-09 - * @version SVN: $Id$ - * @filesource $URL$ */ abstract class ViewHelper 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 From 255c3a837a0966aa9fdfeedd1b843315e2f2e682 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Wed, 21 Nov 2012 20:04:40 +0400 Subject: [PATCH 21/21] More complex regular expression for AutoloadBuilder --- util/AutoloadBuilder.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/util/AutoloadBuilder.php b/util/AutoloadBuilder.php index 14e4d2c..8adfaf6 100644 --- a/util/AutoloadBuilder.php +++ b/util/AutoloadBuilder.php @@ -22,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()) { @@ -34,7 +34,7 @@ class AutoloadBuilder public function build() { $array_string = "dirs as $dir) { $iterator = new RecursiveIteratorIterator( @@ -43,7 +43,9 @@ class AutoloadBuilder ); foreach ($iterator as $file) { - + /** + * @var SplFileInfo $file + */ if ($this->isExcluded($file->getRealPath())) { continue; } @@ -60,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(); } } }