From 1579f0923ac68c9ffd217b90f7f737910ed4d5d2 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 5 Jan 2017 11:25:52 +0700 Subject: [PATCH] adding error preview console controllers --- README.md | 6 ++++ composer.json | 6 +++- config/module.config.php | 31 ++++++++++++++++--- .../ErrorPreviewConsoleZF2Controller.php | 22 +++++++++++++ .../ErrorPreviewConsoleZF3Controller0.php | 22 +++++++++++++ 5 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 src/Controller/ErrorPreviewConsoleZF2Controller.php create mode 100644 src/Controller/ErrorPreviewConsoleZF3Controller0.php diff --git a/README.md b/README.md index e0b0885e..2478b5f9 100644 --- a/README.md +++ b/README.md @@ -230,6 +230,12 @@ You will get the following page if display_errors config is 0: *Console Access* +> If you use zend-mvc v3, you need to have `zendframework/zend-mvc-console:^1.1` in your vendor, if you don't have, you can install it via command: + +``` +composer require zendframework/zend-mvc-console:^1.1 +``` + | Command | Preview For | |------------------------------------------|--------------| | php public/index.php error-preview | Exception | diff --git a/composer.json b/composer.json index e1f9492e..d9b845c5 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,11 @@ "doctrine/doctrine-orm-module": "^1.1", "kahlan/kahlan": "^3.0.0", "satooshi/php-coveralls": "^1.0", - "zendframework/zend-mvc": "^2.5|^3.0" + "zendframework/zend-mvc": "^2.5|^3.0", + "zendframework/zend-mvc-console": "^1.1" + }, + "suggest": { + "zendframework/zend-mvc-console": "^1.1 for zend-mvc ^3.0 usage to be able to use Console Controller" }, "autoload": { "psr-4": { diff --git a/config/module.config.php b/config/module.config.php index b48cd41a..9aa3d7a6 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -4,29 +4,52 @@ use Zend\ServiceManager\Factory\InvokableFactory; use Zend\Log; +use Zend\Mvc\Controller\AbstractConsoleController as ZF2AbstractConsoleController; return [ 'controllers' => [ 'invokables' => [ // sm v2 compat - Controller\ErrorPreviewController::class => Controller\ErrorPreviewController::class, + Controller\ErrorPreviewController::class => Controller\ErrorPreviewController::class, + Controller\ErrorPreviewConsoleZF2Controller::class => Controller\ErrorPreviewConsoleZF2Controller::class, + Controller\ErrorPreviewConsoleZF3Controller::class => Controller\ErrorPreviewConsoleZF3Controller::class, ], 'factories' => [ // sm v3 - Controller\ErrorPreviewController::class => InvokableFactory::class, + Controller\ErrorPreviewController::class => InvokableFactory::class, + Controller\ErrorPreviewConsoleZF2Controller::class => InvokableFactory::class, + Controller\ErrorPreviewConsoleZF3Controller::class => InvokableFactory::class, ], ], 'router' => [ 'routes' => [ + 'error-preview' => [ 'type' => 'Segment', 'options' => [ 'route' => '/error-preview[/][:action]', 'defaults' => [ 'controller' => Controller\ErrorPreviewController::class, - 'action' => 'exception', + 'action' => 'exception', + ], + ], + ], + + ], + ], + + 'console' => [ + 'router' => [ + 'routes' => [ + 'error-preview-console' => [ + 'options' => [ + 'route' => 'error-preview []', + 'defaults' => [ + 'controller' => (class_exists(ZF2AbstractConsoleController::class) ? Controller\ErrorPreviewConsoleZF2Controller::class : Controller\ErrorPreviewConsoleZF3Controller::class, + 'action' => 'exception' + ], ], ], ], @@ -38,7 +61,7 @@ Log\LoggerAbstractServiceFactory::class, ], 'factories' => [ - Listener\Mvc::class => Listener\MvcFactory::class, + Listener\Mvc::class => Listener\MvcFactory::class, Handler\Logging::class => Handler\LoggingFactory::class, ], ], diff --git a/src/Controller/ErrorPreviewConsoleZF2Controller.php b/src/Controller/ErrorPreviewConsoleZF2Controller.php new file mode 100644 index 00000000..63313de4 --- /dev/null +++ b/src/Controller/ErrorPreviewConsoleZF2Controller.php @@ -0,0 +1,22 @@ +