Skip to content

Commit 22168fe

Browse files
committed
Merge branch 'expressive-support'
2 parents 01cf82f + e0caf80 commit 22168fe

28 files changed

Lines changed: 1828 additions & 147 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ vendor
22
composer.lock
33
coverage/
44
coverage.json
5-
bin
5+
bin
6+
.php_cs.cache

README.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ return [
102102
composer require samsonasik/error-hero-module
103103
```
104104

105-
**4. Copy `error-hero-module.local.php.dist` config to your local's autoload and configure it**
105+
**4. Copy config**
106+
107+
***a. For [ZF2/ZF3 Mvc](https://zendframework.github.io/tutorials/getting-started/overview/) application, copy `error-hero-module.local.php.dist` config to your local's autoload and configure it***
106108

107109
| source | destination |
108110
|------------------------------------------------------------------------------|---------------------------------------------|
@@ -114,11 +116,23 @@ Or run copy command:
114116
cp vendor/samsonasik/error-hero-module/config/error-hero-module.local.php.dist config/autoload/error-hero-module.local.php
115117
```
116118

119+
***b. For [ZF Expressive](https://zendframework.github.io/zend-expressive/) application, copy `expressive-error-hero-module.local.php.dist` config to your local's autoload and configure it***
120+
121+
| source | destination |
122+
|-----------------------------------------------------------------------------------------|--------------------------------------------------------|
123+
| vendor/samsonasik/error-hero-module/config/expressive-error-hero-module.local.php.dist | config/autoload/expressive-error-hero-module.local.php |
124+
125+
Or run copy command:
126+
127+
```sh
128+
cp vendor/samsonasik/error-hero-module/config/expressive-error-hero-module.local.php.dist config/autoload/expressive-error-hero-module.local.php
129+
```
130+
117131
When done, you can modify logger service named `ErrorHeroModuleLogger` and `error-hero-module` config in your's local config:
118132

119133
```php
120134
<?php
121-
// config/autoload/error-hero-module.local.php
135+
// config/autoload/error-hero-module.local.php or config/autoload/expressive-error-hero-module.local.php
122136
return [
123137

124138
'log' => [
@@ -223,6 +237,9 @@ json
223237
```
224238

225239
**5. Lastly, enable it**
240+
241+
***a. For ZF Mvc application***
242+
226243
```php
227244
// config/modules.config.php or config/application.config.php
228245
return [
@@ -231,6 +248,26 @@ return [
231248
],
232249
```
233250

251+
***b. For ZF Expressive application***
252+
253+
> You need to use Zend\ServiceManager for service container and Zend\View for template engine.
254+
255+
For [zend-expressive-skeleton](https://github.com/zendframework/zend-expressive-skeleton) ^1.0, It's should already just works!
256+
257+
For [zend-expressive-skeleton](https://github.com/zendframework/zend-expressive-skeleton) ^2.0 (upcoming), you need to open `config/pipeline.php` and add the `ErrorHeroModule\Middleware\Expressive::class` middleware after default `ErrorHandler::class` registration:
258+
259+
```php
260+
$app->pipe(ErrorHandler::class);
261+
$app->pipe(ErrorHeroModule\Middleware\Expressive::class); // here
262+
```
263+
264+
and also add `error-preview` routes in `config/routes.php`:
265+
266+
```php
267+
$app->get('/error-preview[/:action]', ErrorHeroModule\Middleware\Routed\Preview\ErrorPreviewAction::class, 'error-preview');
268+
```
269+
270+
234271
Give it a try!
235272
--------------
236273

@@ -265,6 +302,7 @@ You will get the following page if display_errors config is 0:
265302
![error preview in console](https://cloud.githubusercontent.com/assets/459648/21669141/8e7690f0-d33b-11e6-99c7-eed4f1ab7edb.png)
266303
267304
> For production env, you can disable error-preview sample page with set `['error-hero-module']['enable-error-preview-page']` to false.
305+
> For ZF Expressive, there is no default console implementation, so, if you want to apply it in your console in ZF Expressive, you may need to custom implementation error handler that utilize `ErrorHeroModule\Handler\Logging` service (see detailed usage at `ErrorHeroModule\Middleware\Expressive` class)
268306
269307
Contributing
270308
------------

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "samsonasik/error-hero-module",
33
"type": "library",
44
"description": "A Hero for your ZF2 and ZF3 application to trap php errors & exceptions",
5-
"keywords": ["zf2", "zf3", "error", "hero", "log", "logger", "logging", "mail", "db", "doctrine", "handler"],
5+
"keywords": ["zf2", "zf3", "error", "expressive", "hero", "log", "logger", "logging", "mail", "db", "doctrine", "handler"],
66
"homepage": "https://github.com/samsonasik/ErrorHeroModule",
77
"license": "MIT",
88
"authors": [
@@ -27,6 +27,11 @@
2727
"doctrine/doctrine-orm-module": "^1.1",
2828
"kahlan/kahlan": "^3.0.0",
2929
"satooshi/php-coveralls": "^1.0",
30+
"zendframework/zend-config-aggregator": "^0.2.0",
31+
"zendframework/zend-expressive": "^1.1|^2.0",
32+
"zendframework/zend-expressive-helpers": "^3.0.1",
33+
"zendframework/zend-expressive-zendrouter": "^2.0.1",
34+
"zendframework/zend-expressive-zendviewrenderer": "^1.3",
3035
"zendframework/zend-mvc": "^2.5|^3.0",
3136
"zendframework/zend-mvc-console": "^1.1"
3237
},
@@ -44,7 +49,8 @@
4449
}
4550
},
4651
"config": {
47-
"bin-dir": "bin"
52+
"bin-dir": "bin",
53+
"sort-packages": true
4854
},
4955
"extra": {
5056
"zf": {
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?php
2+
3+
namespace ErrorHeroModule;
4+
5+
use Zend\Expressive\ZendView\HelperPluginManagerFactory;
6+
use Zend\Log;
7+
use Zend\ServiceManager\Factory\InvokableFactory;
8+
9+
return [
10+
11+
'log' => [
12+
'ErrorHeroModuleLogger' => [
13+
'writers' => [
14+
15+
[
16+
'name' => 'db',
17+
'options' => [
18+
'db' => 'Zend\Db\Adapter\Adapter',
19+
'table' => 'error_log',
20+
'column' => [
21+
'timestamp' => 'date',
22+
'priority' => 'type',
23+
'message' => 'event',
24+
'extra' => [
25+
'url' => 'url',
26+
'file' => 'file',
27+
'line' => 'line',
28+
'error_type' => 'error_type',
29+
'trace' => 'trace',
30+
'request_data' => 'request_data',
31+
],
32+
],
33+
],
34+
],
35+
36+
],
37+
],
38+
],
39+
40+
'error-hero-module' => [
41+
// it's for the enable/disable the logger functionality
42+
'enable' => true,
43+
44+
// default to true, if set to true, then you can see sample:
45+
// 1. /error-preview page ( ErrorHeroModule\Middleware\ErrorPreviewAction )
46+
// 2. error-preview command ( ErrorHeroModule\Controller\ErrorPreviewConsoleAction ) via
47+
// php public/index.php error-preview
48+
//
49+
// otherwise(false), you can't see them, eg: on production env.
50+
'enable-error-preview-page' => true,
51+
52+
'display-settings' => [
53+
54+
// excluded php errors
55+
'exclude-php-errors' => [
56+
E_USER_DEPRECATED
57+
],
58+
59+
// show or not error
60+
'display_errors' => 0,
61+
62+
// if enable and display_errors = 0, the page will bring layout and view
63+
'template' => [
64+
'layout' => 'layout::default',
65+
'view' => 'error-hero-module::error-default'
66+
],
67+
68+
// if enable and display_errors = 0, and on console env, the console will bring message
69+
'console' => [
70+
'message' => 'We have encountered a problem and we can not fulfill your request. An error report has been generated and send to the support team and someone will attend to this problem urgently. Please try again later. Thank you for your patience.',
71+
],
72+
73+
// if enable, display_errors = 0, and request XMLHttpRequest
74+
// on this case, the "template" key will be ignored.
75+
'ajax' => [
76+
'message' => <<<json
77+
{
78+
"type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
79+
"title": "Internal Server Error",
80+
"status": 500,
81+
"detail": "We have encountered a problem and we can not fulfill your request. An error report has been generated and send to the support team and someone will attend to this problem urgently. Please try again later. Thank you for your patience."
82+
}
83+
json
84+
],
85+
86+
],
87+
'logging-settings' => [
88+
// time range for same error, file, line, url, message to be re-logged
89+
// in seconds range, 86400 means 1 day
90+
'same-error-log-time-range' => 86400,
91+
],
92+
'email-notification-settings' => [
93+
// set to true to activate email notification on log error
94+
'enable' => false,
95+
96+
// Zend\Mail\Message instance registered at service manager
97+
'mail-message' => 'YourMailMessageService',
98+
99+
// Zend\Mail\Transport\TransportInterface instance registered at service manager
100+
'mail-transport' => 'YourMailTransportService',
101+
102+
// email sender
103+
'email-from' => 'Sender Name <sender@host.com>',
104+
105+
'email-to-send' => [
106+
'developer1@foo.com',
107+
'developer2@foo.com',
108+
],
109+
],
110+
],
111+
112+
'dependencies' => [
113+
'abstract_factories' => [
114+
Log\LoggerAbstractServiceFactory::class,
115+
],
116+
'factories' => [
117+
Middleware\Expressive::class => Middleware\ExpressiveFactory::class,
118+
ErrorHeroModule\Middleware\Routed\Preview\ErrorPreviewAction::class => InvokableFactory::class,
119+
120+
Handler\Logging::class => Handler\LoggingFactory::class,
121+
'ViewHelperManager' => HelperPluginManagerFactory::class,
122+
],
123+
],
124+
125+
'templates' =>[
126+
'paths' => [
127+
'error-hero-module' => [
128+
realpath( dirname(dirname(__DIR__) ) . '/vendor/samsonasik/error-hero-module/view/error-hero-module' ),
129+
],
130+
],
131+
],
132+
133+
'middleware_pipeline' => [
134+
'always' => [
135+
'middleware' => [
136+
Middleware\Expressive::class
137+
],
138+
'priority' => PHP_INT_MAX,
139+
],
140+
],
141+
142+
];
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
use Zend\Expressive\Application;
4+
use Zend\Expressive\Container;
5+
use Zend\Expressive\Delegate;
6+
use Zend\Expressive\Helper;
7+
use Zend\Expressive\Middleware;
8+
9+
return [
10+
// Provides application-wide services.
11+
// We recommend using fully-qualified class names whenever possible as
12+
// service names.
13+
'dependencies' => [
14+
// Use 'aliases' to alias a service name to another service. The
15+
// key is the alias name, the value is the service to which it points.
16+
'aliases' => [
17+
Delegate\DefaultDelegate::class => Delegate\NotFoundDelegate::class,
18+
],
19+
// Use 'invokables' for constructor-less services, or services that do
20+
// not require arguments to the constructor. Map a service name to the
21+
// class name.
22+
'invokables' => [
23+
// Fully\Qualified\InterfaceName::class => Fully\Qualified\ClassName::class,
24+
Helper\ServerUrlHelper::class => Helper\ServerUrlHelper::class,
25+
],
26+
// Use 'factories' for services provided by callbacks/factory classes.
27+
'factories' => [
28+
Application::class => Container\ApplicationFactory::class,
29+
Delegate\NotFoundDelegate::class => Container\NotFoundDelegateFactory::class,
30+
Helper\ServerUrlMiddleware::class => Helper\ServerUrlMiddlewareFactory::class,
31+
Helper\UrlHelper::class => Helper\UrlHelperFactory::class,
32+
Helper\UrlHelperMiddleware::class => Helper\UrlHelperMiddlewareFactory::class,
33+
34+
Zend\Stratigility\Middleware\ErrorHandler::class => Container\ErrorHandlerFactory::class,
35+
Middleware\ErrorResponseGenerator::class => Container\ErrorResponseGeneratorFactory::class,
36+
Middleware\NotFoundHandler::class => Container\NotFoundHandlerFactory::class,
37+
],
38+
],
39+
];

0 commit comments

Comments
 (0)