Skip to content

Commit ae1b1ae

Browse files
authored
Merge pull request #88 from samsonasik/v5
[Version 5] Remove laminas-mvc-console support, add support laminas-cli
2 parents 1737915 + 40d4af4 commit ae1b1ae

File tree

53 files changed

+751
-584
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+751
-584
lines changed

.github/workflows/ci_build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
php-versions: ['8.0', '8.1']
16+
php-versions: ['8.1']
1717
steps:
1818
- name: Setup PHP Action
1919
uses: shivammathur/setup-php@v2
@@ -38,7 +38,7 @@ jobs:
3838
run: "composer cs-check"
3939
- name: "Code analyze"
4040
run: |
41-
bin/phpstan analyse src/ --level=max -c phpstan.neon
41+
composer phpstan
4242
bin/rector process --dry-run
4343
- name: "Run test suite"
4444
run: |

README.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@ ErrorHeroModule
77
[![PHPStan](https://img.shields.io/badge/style-level%20max-brightgreen.svg?style=flat-square&label=phpstan)](https://github.com/phpstan/phpstan)
88
[![Downloads](https://poser.pugx.org/samsonasik/error-hero-module/downloads)](https://packagist.org/packages/samsonasik/error-hero-module)
99

10-
> This is README for version ^4.0 which only support Laminas Mvc version 3 and Mezzio version 3 with php ^8.0.
10+
> This is README for version ^5.0 which only support Laminas Mvc version 3 and Mezzio version 3 with php ^8.1.
1111
12-
> For version ^3.0, you can read at [version 3 readme](https://github.com/samsonasik/ErrorHeroModule/tree/3.x.x) which only support Laminas Mvc version 3 and Mezzio version 3 with php ^7.1.
13-
14-
> For version ^2.0, you can read at [version 2 readme](https://github.com/samsonasik/ErrorHeroModule/tree/2.x.x) which only support ZF3 and ZF Expressive version 3 with php ^7.1.
15-
16-
> For version 1, you can read at [version 1 readme](https://github.com/samsonasik/ErrorHeroModule/tree/1.x.x) which still support ZF2 and ZF Expressive version 1 and 2 with php ^5.6|^7.0 support.
12+
> For version ^4.0, you can read at [version 4 readme](https://github.com/samsonasik/ErrorHeroModule/tree/4.x.x) which only support Laminas Mvc version 3 and Mezzio version 3 with php ^8.0.
1713
1814
Introduction
1915
------------
@@ -351,29 +347,50 @@ You will get the following page if display_errors config is 0:
351347

352348
![error preview in web](https://cloud.githubusercontent.com/assets/459648/21668589/d4fdadac-d335-11e6-95aa-5a8cfa3f8e4b.png)
353349

354-
> For production env, you can disable error-preview sample page with set `['error-hero-module']['enable-error-preview-page']` to false.
355-
356350
_**Console Access**_
357351

358-
> If you use laminas-mvc v3, you need to have `laminas/laminas-mvc-console` in your vendor, if you don't have, you can install it via command:
352+
> You can use this module in `laminas-cli`, you can install:
359353
360354
> ```sh
361-
> composer require laminas/laminas-mvc-console --sort-packages
355+
> composer require laminas/laminas-cli --sort-packages
362356
> ```
363357
364-
| Command | Preview For |
365-
|--------------------------------------------|---------------|
366-
| php public/index.php error-preview | Exception |
367-
| php public/index.php error-preview error | Error |
368-
| php public/index.php error-preview warning | PHP E_WARNING |
358+
then you can see the error-preview console:
359+
360+
| Command | Preview For |
361+
|----------------------------------------------------|---------------|
362+
| vendor/bin/laminas errorheromodule:preview | Exception |
363+
| vendor/bin/laminas errorheromodule:preview error | Error |
364+
| vendor/bin/laminas errorheromodule:preview warning | PHP E_WARNING |
365+
| vendor/bin/laminas errorheromodule:preview fatal | PHP Fatal |
369366
370367
You will get the following page if display_errors config is 0:
371368
372-
![error preview in console](https://cloud.githubusercontent.com/assets/459648/21669141/8e7690f0-d33b-11e6-99c7-eed4f1ab7edb.png)
369+
![error preview in console](https://user-images.githubusercontent.com/459648/206882602-5f2e5ab0-86d6-4694-9a3c-c7b8896596fa.png))
373370
374-
> For production env, you can disable error-preview sample page with set `['error-hero-module']['enable-error-preview-page']` to false.
371+
You can use the error handling in your console application, by extends `BaseLoggingCommand`, like below:
372+
373+
```php
374+
namespace Application\Command;
375375
376-
> For Mezzio, there is no default console implementation, so, if you want to apply it in your console in Mezzio, you may need to custom implementation error handler that utilize `ErrorHeroModule\Handler\Logging` service (see detailed usage at `ErrorHeroModule\Middleware\Mezzio` class)
376+
use ErrorHeroModule\Command\BaseLoggingCommand;
377+
use Exception;
378+
use Symfony\Component\Console\Input\InputArgument;
379+
use Symfony\Component\Console\Input\InputInterface;
380+
use Symfony\Component\Console\Output\OutputInterface;
381+
382+
final class HelloWorld extends BaseLoggingCommand
383+
{
384+
protected function execute(InputInterface $input, OutputInterface $output): int
385+
{
386+
throw new Exception('some exception logged to DB');
387+
}
388+
}
389+
```
390+
391+
and register to your services like in the [documentation](https://docs.laminas.dev/laminas-cli/intro/).
392+
393+
> For production env, you can disable error-preview sample page with set `['error-hero-module']['enable-error-preview-page']` to false.
377394
378395
Contributing
379396
------------

composer.json

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,46 +36,45 @@
3636
}
3737
],
3838
"require": {
39-
"php": "^8.0",
40-
"laminas/laminas-db": "^2.12",
41-
"laminas/laminas-diactoros": "^2.5",
42-
"laminas/laminas-log": "^2.13",
43-
"laminas/laminas-mail": "^2.13",
44-
"laminas/laminas-psr7bridge": "^1.3",
45-
"laminas/laminas-text": "^2.8",
46-
"laminas/laminas-uri": "^2.8",
47-
"psr/container": "^1.0 || 2.0",
48-
"seld/jsonlint": "^1.8",
49-
"webmozart/assert": "^1.9.1"
39+
"php": "^8.1",
40+
"laminas/laminas-db": "^2.15",
41+
"laminas/laminas-diactoros": "^2.14",
42+
"laminas/laminas-log": "^2.15.2",
43+
"laminas/laminas-mail": "^2.17",
44+
"laminas/laminas-psr7bridge": "^1.6",
45+
"laminas/laminas-uri": "^2.9.1",
46+
"psr/container": "^1.1.2 || 2.0",
47+
"seld/jsonlint": "^1.9",
48+
"webmozart/assert": "^1.11"
5049
},
5150
"conflict": {
5251
"doctrine/dbal": "<3.0",
5352
"doctrine/doctrine-orm-module": "<4.1",
5453
"laminas/laminas-mvc": "<3.2 >=4.0",
5554
"laminas/laminas-servicemanager": "<3.10",
56-
"mezzio/mezzio": "<3.3 >=4.0"
55+
"mezzio/mezzio": "<3.3 >=4.0",
56+
"laminas/laminas-mvc-console": "*"
5757
},
5858
"require-dev": {
59-
"aura/di": "^3.4 || ^4.0",
60-
"doctrine/dbal": "^3.0",
61-
"doctrine/doctrine-orm-module": "^4.1",
62-
"kahlan/kahlan": "^5.2.0",
63-
"laminas/laminas-coding-standard": "^2.1.1",
64-
"laminas/laminas-form": "^2.16 || ^3.0",
65-
"laminas/laminas-mvc": "^3.2",
66-
"laminas/laminas-mvc-console": "^1.1",
67-
"laminas/laminas-servicemanager": "^3.10",
68-
"mezzio/mezzio": "^3.3",
69-
"mezzio/mezzio-laminasviewrenderer": "^2.3",
70-
"php-coveralls/php-coveralls": "^2.4",
71-
"phpstan/phpstan": "^1.6.7",
72-
"phpstan/phpstan-webmozart-assert": "^1.0",
73-
"pimple/pimple": "^3.2",
59+
"aura/di": "^3.4 || ^4.2.1",
60+
"doctrine/dbal": "^3.4",
61+
"doctrine/doctrine-orm-module": "^4.2.1",
62+
"kahlan/kahlan": "^5.2.1",
63+
"laminas/laminas-cli": "^1.5",
64+
"laminas/laminas-coding-standard": "^2.3",
65+
"laminas/laminas-form": "^2.16 || ^3.4.1",
66+
"laminas/laminas-mvc": "^3.3.3",
67+
"laminas/laminas-servicemanager": "^3.16",
68+
"mezzio/mezzio": "^3.11",
69+
"mezzio/mezzio-laminasviewrenderer": "^2.6",
70+
"php-coveralls/php-coveralls": "^2.5.2",
71+
"phpstan/phpstan": "^1.8.2",
72+
"phpstan/phpstan-webmozart-assert": "^1.2",
73+
"pimple/pimple": "^3.5",
7474
"rector/rector": "dev-main",
75-
"symfony/dependency-injection": "^5.0"
75+
"symfony/dependency-injection": "^5.4.11"
7676
},
7777
"suggest": {
78-
"laminas/laminas-mvc-console": "^1.1 for laminas-mvc ^3.0 usage to be able to use Console Controller",
7978
"mezzio/mezzio-laminasviewrenderer": "^2.0 to be able to use laminas-view template engine in mezzio ^3.0",
8079
"mezzio/mezzio-platesrenderer": "^2.0 to be able to use plates template engine in mezzio ^3.0",
8180
"mezzio/mezzio-twigrenderer": "^2.0 to be able to use twig template engine in mezzio ^3.0"
@@ -114,6 +113,7 @@
114113
"prefer-stable": true,
115114
"scripts": {
116115
"cs-check": "phpcs",
117-
"cs-fix": "phpcbf"
116+
"cs-fix": "phpcbf",
117+
"phpstan": "phpstan analyse src/ --level=max -c phpstan.neon"
118118
}
119119
}

config/error-hero-module.local.php.dist

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use App\Exception\MyException;
34
use Laminas\Db\Adapter\AdapterInterface;
45

56
return [
@@ -68,13 +69,13 @@ return [
6869
'exclude-exceptions' => [
6970

7071
// can be an Exception class or class extends Exception class
71-
\App\Exception\MyException::class,
72+
MyException::class,
7273

7374
// can be specific exception with specific message
74-
[\RuntimeException::class, 'specific exception message'],
75+
[RuntimeException::class, 'specific exception message'],
7576

7677
// or specific Error class with specific message
77-
[\Error::class, 'specific error message'],
78+
[Error::class, 'specific error message'],
7879

7980
],
8081

config/mezzio-error-hero-module.local.php.dist

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@
22

33
namespace ErrorHeroModule;
44

5+
use App\Exception\MyException;
6+
use RuntimeException;
7+
use Error;
8+
use ErrorHeroModule\Command\BaseLoggingCommandInitializer;
9+
use ErrorHeroModule\Middleware\Mezzio;
10+
use ErrorHeroModule\Middleware\MezzioFactory;
11+
use ErrorHeroModule\ErrorHeroModule\Middleware\Routed\Preview\ErrorPreviewAction;
12+
use ErrorHeroModule\Handler\Logging;
13+
use ErrorHeroModule\Handler\LoggingFactory;
14+
use ErrorHeroModule\Command\BaseLoggingCommand;
15+
use ErrorHeroModule\Command\Preview\ErrorPreviewConsoleCommand;
516
use Laminas\Db\Adapter\AdapterInterface;
617
use Laminas\Log;
18+
use Laminas\Log\LoggerAbstractServiceFactory;
719
use Laminas\ServiceManager\Factory\InvokableFactory;
820

921
return [
@@ -64,13 +76,13 @@ return [
6476
'exclude-exceptions' => [
6577

6678
// can be an Exception class or class extends Exception class
67-
\App\Exception\MyException::class,
79+
MyException::class,
6880

6981
// can be specific exception with specific message
70-
[\RuntimeException::class, 'specific exception message'],
82+
[RuntimeException::class, 'specific exception message'],
7183

7284
// or specific Error class with specific message
73-
[\Error::class, 'specific error message'],
85+
[Error::class, 'specific error message'],
7486

7587
],
7688

@@ -141,20 +153,31 @@ json
141153

142154
'dependencies' => [
143155
'abstract_factories' => [
144-
Log\LoggerAbstractServiceFactory::class,
156+
LoggerAbstractServiceFactory::class,
145157
],
146158
'factories' => [
147-
Middleware\Mezzio::class => Middleware\MezzioFactory::class,
148-
ErrorHeroModule\Middleware\Routed\Preview\ErrorPreviewAction::class => InvokableFactory::class,
159+
Mezzio::class => MezzioFactory::class,
160+
ErrorPreviewAction::class => InvokableFactory::class,
149161

150-
Handler\Logging::class => Handler\LoggingFactory::class,
162+
Logging::class => LoggingFactory::class,
163+
164+
ErrorPreviewConsoleCommand::class => InvokableFactory::class,
165+
],
166+
'initializers' => [
167+
BaseLoggingCommandInitializer::class,
168+
],
169+
],
170+
171+
'laminas-cli' => [
172+
'commands' => [
173+
'errorheromodule:preview' => ErrorPreviewConsoleCommand::class,
151174
],
152175
],
153176

154177
'templates' =>[
155178
'paths' => [
156179
'error-hero-module' => [
157-
realpath( dirname(dirname(__DIR__) ) . '/vendor/samsonasik/error-hero-module/view/error-hero-module' ),
180+
realpath( dirname(__DIR__, 2) . '/vendor/samsonasik/error-hero-module/view/error-hero-module' ),
158181
],
159182
],
160183
],

config/module.config.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
namespace ErrorHeroModule;
44

5+
use ErrorHeroModule\Command\BaseLoggingCommandInitializer;
6+
use ErrorHeroModule\Command\Preview\ErrorPreviewConsoleCommand;
57
use ErrorHeroModule\Controller\ErrorPreviewController;
6-
use ErrorHeroModule\Controller\ErrorPreviewConsoleController;
78
use Laminas\Log\LoggerAbstractServiceFactory;
89
use ErrorHeroModule\Listener\Mvc;
910
use ErrorHeroModule\Listener\MvcFactory;
@@ -16,7 +17,6 @@
1617
'controllers' => [
1718
'factories' => [
1819
ErrorPreviewController::class => InvokableFactory::class,
19-
ErrorPreviewConsoleController::class => InvokableFactory::class,
2020
],
2121
],
2222

@@ -37,36 +37,30 @@
3737
],
3838
],
3939

40-
'console' => [
41-
'router' => [
42-
'routes' => [
43-
'error-preview-console' => [
44-
'options' => [
45-
'route' => 'error-preview [<action>]',
46-
'defaults' => [
47-
'controller' => ErrorPreviewConsoleController::class,
48-
'action' => 'exception'
49-
],
50-
],
51-
],
52-
],
53-
],
54-
],
55-
5640
'service_manager' => [
5741
'abstract_factories' => [
5842
LoggerAbstractServiceFactory::class,
5943
],
6044
'factories' => [
6145
Mvc::class => MvcFactory::class,
6246
Logging::class => LoggingFactory::class,
47+
ErrorPreviewConsoleCommand::class => InvokableFactory::class,
48+
],
49+
'initializers' => [
50+
BaseLoggingCommandInitializer::class,
6351
],
6452
],
6553

6654
'listeners' => [
6755
Mvc::class,
6856
],
6957

58+
'laminas-cli' => [
59+
'commands' => [
60+
'errorheromodule:preview' => ErrorPreviewConsoleCommand::class,
61+
],
62+
],
63+
7064
'view_manager' => [
7165
'template_map' => [
7266
'error-hero-module/error-default' => __DIR__.'/../view/error-hero-module/error-default.phtml',

kahlan-config.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Kahlan\Reporter\Coverage\Driver\Xdebug;
66

77
// autoload hack
8-
file_put_contents('vendor/laminas/laminas-zendframework-bridge/src/autoload.php', '');
98
class_alias(Laminas\ServiceManager\AbstractPluginManager::class, Zend\ServiceManager\AbstractPluginManager::class);
109

1110
Filters::apply($this, 'coverage', function($next) {
@@ -19,8 +18,13 @@ class_alias(Laminas\ServiceManager\AbstractPluginManager::class, Zend\ServiceMan
1918
'driver' => new Xdebug(),
2019
'path' => $this->commandLine()->get('src'),
2120
'exclude' => [
22-
'src/Controller/ErrorPreviewConsoleController.php',
21+
// laminas-cli preview console command
22+
'src/Command/Preview/ErrorPreviewConsoleCommand.php',
23+
24+
// laminas-mvc preview page
2325
'src/Controller/ErrorPreviewController.php',
26+
27+
// mezzio preview page
2428
'src/Middleware/Routed/Preview/ErrorPreviewAction.php',
2529
],
2630
'colors' => ! $this->commandLine()->get('no-colors')

phpstan.neon

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ includes:
33

44
parameters:
55
excludePaths:
6-
- src/Controller/ErrorPreviewConsoleController.php
6+
- src/Command/Preview/ErrorPreviewConsoleCommand.php
77
- src/Controller/ErrorPreviewController.php
88
- src/Middleware/Routed/Preview/ErrorPreviewAction.php
99
checkMissingIterableValueType: false
1010
reportUnmatchedIgnoredErrors: false
1111
treatPhpDocTypesAsCertain: false
12+
checkGenericClassInNonGenericObjectType: false
1213
ignoreErrors:
1314
- '#function set_error_handler expects (callable(int, string, string, int, array): bool)*#'
1415
- '#Invalid type object to throw#'
16+
- '#Cannot call method getBody\(\) on int#'

0 commit comments

Comments
 (0)