Skip to content

Commit 5077732

Browse files
committed
add error preview concsole command
1 parent cc8589c commit 5077732

File tree

3 files changed

+47
-46
lines changed

3 files changed

+47
-46
lines changed

config/module.config.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace ErrorHeroModule;
44

55
use ErrorHeroModule\Command\BaseLoggingCommand;
6+
use ErrorHeroModule\Command\Preview\ErrorPreviewConsoleCommand;
67
use ErrorHeroModule\Controller\ErrorPreviewController;
7-
use ErrorHeroModule\Controller\ErrorPreviewConsoleController;
88
use Laminas\Log\LoggerAbstractServiceFactory;
99
use ErrorHeroModule\Listener\Mvc;
1010
use ErrorHeroModule\Listener\MvcFactory;
@@ -17,7 +17,6 @@
1717
'controllers' => [
1818
'factories' => [
1919
ErrorPreviewController::class => InvokableFactory::class,
20-
ErrorPreviewConsoleController::class => InvokableFactory::class,
2120
],
2221
],
2322

@@ -38,29 +37,14 @@
3837
],
3938
],
4039

41-
'console' => [
42-
'router' => [
43-
'routes' => [
44-
'error-preview-console' => [
45-
'options' => [
46-
'route' => 'error-preview [<action>]',
47-
'defaults' => [
48-
'controller' => ErrorPreviewConsoleController::class,
49-
'action' => 'exception'
50-
],
51-
],
52-
],
53-
],
54-
],
55-
],
56-
5740
'service_manager' => [
5841
'abstract_factories' => [
5942
LoggerAbstractServiceFactory::class,
6043
],
6144
'factories' => [
6245
Mvc::class => MvcFactory::class,
6346
Logging::class => LoggingFactory::class,
47+
ErrorPreviewConsoleCommand::class => InvokableFactory::class,
6448
],
6549
'initializers' => [
6650
static function ($service, $instance) : void {
@@ -78,6 +62,12 @@ static function ($service, $instance) : void {
7862
Mvc::class,
7963
],
8064

65+
'laminas-cli' => [
66+
'commands' => [
67+
'errorheromodule:preview' => ErrorPreviewConsoleCommand::class,
68+
],
69+
],
70+
8171
'view_manager' => [
8272
'template_map' => [
8373
'error-hero-module/error-default' => __DIR__.'/../view/error-hero-module/error-default.phtml',
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ErrorHeroModule\Command\Preview;
6+
7+
use Error;
8+
use ErrorHeroModule\Command\BaseLoggingCommand;
9+
use Exception;
10+
use Symfony\Component\Console\Input\InputArgument;
11+
use Symfony\Component\Console\Input\InputInterface;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
14+
class ErrorPreviewConsoleCommand extends BaseLoggingCommand
15+
{
16+
protected function configure()
17+
{
18+
$this
19+
->addArgument('type', InputArgument::OPTIONAL, 'Type of preview: exception, error, warning');
20+
}
21+
22+
protected function execute(InputInterface $input, OutputInterface $output)
23+
{
24+
$type = $input->getArgument('type');
25+
26+
if ($type === null) {
27+
throw new Exception('a sample exception preview');
28+
}
29+
30+
if ($type === 'error') {
31+
throw new Error('a sample error preview');
32+
}
33+
34+
if ($type === 'warning') {
35+
$array = [];
36+
$array[1]; // E_WARNING
37+
}
38+
}
39+
}

src/Controller/ErrorPreviewConsoleController.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)