Skip to content

Commit

Permalink
adding error preview console controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 5, 2017
1 parent c09e83f commit 1579f09
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -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 |
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Expand Up @@ -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": {
Expand Down
31 changes: 27 additions & 4 deletions config/module.config.php
Expand Up @@ -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 [<action>]',
'defaults' => [
'controller' => (class_exists(ZF2AbstractConsoleController::class) ? Controller\ErrorPreviewConsoleZF2Controller::class : Controller\ErrorPreviewConsoleZF3Controller::class,
'action' => 'exception'
],
],
],
],
Expand All @@ -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,
],
],
Expand Down
22 changes: 22 additions & 0 deletions src/Controller/ErrorPreviewConsoleZF2Controller.php
@@ -0,0 +1,22 @@
<?php

namespace ErrorHeroModule\Controller;

use Zend\Mvc\Controller\AbstractConsoleController;
use Zend\View\Model\ConsoleModel;

class ErrorPreviewConsoleZF2Controller extends AbstractConsoleController
{
public function exceptionAction()
{
throw new \Exception('a sample error preview');
}

public function errorAction()
{
$array = [];
$array[1]; // E_NOTICE

return new ConsoleModel();
}
}
22 changes: 22 additions & 0 deletions src/Controller/ErrorPreviewConsoleZF3Controller0.php
@@ -0,0 +1,22 @@
<?php

namespace ErrorHeroModule\Controller;

use Zend\Mvc\Console\Controller\AbstractConsoleController;
use Zend\View\Model\ConsoleModel;

class ErrorPreviewConsoleZF3Controller extends AbstractConsoleController
{
public function exceptionAction()
{
throw new \Exception('a sample error preview');
}

public function errorAction()
{
$array = [];
$array[1]; // E_NOTICE

return new ConsoleModel();
}
}

0 comments on commit 1579f09

Please sign in to comment.