Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add middleware to phpErrorHandler? #17

Closed
visualcookie opened this issue Jan 16, 2017 · 2 comments
Closed

How to add middleware to phpErrorHandler? #17

visualcookie opened this issue Jan 16, 2017 · 2 comments

Comments

@visualcookie
Copy link

visualcookie commented Jan 16, 2017

I know, when placing the Middleware call into my src/middleware.php file, it will automatically replace Slim's error message with Whoops (haven't tested yet). But sometimes, I run into trouble with PHP errors.

Is there a way to replace them with Whoops too? If so, how? Haven't found it anywhere.

EDIT: Tried the rest, to see if the Error Handler is replaced, but it's not. Doing it like so: $app->response()->status(500);

This is my public/index.php file:

<?php

require __DIR__ . '/../vendor/autoload.php';

session_start();

// Instantiate the app
$settings = require __DIR__ . '/../src/settings.php';
$app = new \Slim\App($settings);

// Set up dependencies
require __DIR__ . '/../src/dependencies.php';

// Register middleware
require __DIR__ . '/../src/middleware.php';

// Register routes
require __DIR__ . '/../src/routes.php';

// Run app
$app->run();

In the src/middleware.php is the Middleware call as in the Readme $app->add(new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware($app));.

@zeuxisoo
Copy link
Owner

zeuxisoo commented Jan 16, 2017

In this stage, the middleware only replaces the default errorHandler container only not phpErrorHandler. The phpErrorHandler is for PHP7.

And if your application breaks the lifecycle of slim middleware. it will not trigger this middleware that why you cannot see the whoop error. For example, the program throws an exception and without a handle.

Update on 2017-01-18 06:39:

  1. Now, the middleware will replace the default errorHandler and phpErrorHandler.
  2. If you want all errors/exceptions handle by whoops, you can use the global mode to install the whoops. this mode supports the program life cycle broken.

@visualcookie
Copy link
Author

visualcookie commented Jan 18, 2017

Amazing, will try that out as soon as I'm back. 👍

@zeuxisoo
Edit Hum... somehow it still shows the default Slim Application Error message. Have tried to implement it as middleware aswell as trying it as global in my depenencies file. To see my file structure look here: https://github.com/visualcookie/slim-sentinel-auth/tree/version-2

Maybe you have an idea. I've not yet committed this, since it's not working, but I think you can kinda imagine what I did.

Edit 2 Have figured it out. I needed to implement it in Middleware as well as set the Global. Now works. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants