The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Cant call halt() from inside custom hook

booster's Avatar

booster

05 Nov, 2015 04:02 PM

Hi,
I cant call halt() from inside my custom hook,
I have a backend Api which has a group "rest" which is only for logged in users and an group "public" which is for all users.
The Problem is that in the "rest/"-group I have to check if the user is logged in and setup some globals.
If somethind fails a function is triggered that calls halt() on the global App.

But I always get a Slim/Exception/Stop.

$app->hook("group.rest", function() use ($app, $accountManager, $pdo){
    //Calls $app->halt() on global $app
    sendJsonHttpResponse(503, [
        "message" => "Test"
    ]);
});

$app->group("/rest", function() use ($app){
    $app->applyHook("group.rest");
    /*** ROUTES ***/
});

The code throws the following Error:

<br />
<b>Fatal error</b>:  Uncaught exception 'Slim\Exception\Stop' in webserver\api\vendor\slim\slim\Slim\Slim.php:1022
Stack trace:
#0 webserver\api\index.php(134): Slim\Slim-&gt;stop(503, 'Test')
#1 [internal function]: {closure}()
#2 webserver\api\vendor\slim\slim\Slim\Slim.php(1210): call_user_func_array(Object(Closure), Array)
#3 webserver\api\index.php(144): Slim\Slim-&gt;applyHook('group.rest')
#4 [internal function]: {closure}()
#5 webserver\api\vendor\slim\slim\Slim\Slim.php(553): call_user_func(Object(Closure))
#6 webserver\api\index.php(192): Slim\Slim-&gt;group('/rest', Object(Closure))
#7 {main}
  thrown in <b>webserver\api\vendor\slim\slim\Slim\Slim.php</b> on line <b>1022</b><br />

Inside a slim.before hook I can call halt().

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac