Detect controller instance

Hi, i use a micro application and i want detect current calling controller instance. i use before method

$app->before(function () use ($app) {
// HERE. I WANT CHECK HANDLER INSTANCE. HOW?
})

i know that i use

$app->getActiveHandler();
$handler[0]->getDefinition();

but getDefinition return path to class, not instance ;/ What can I do?



66.6k

https://olddocs.phalconphp.com/en/3.0.0/api/Phalcon%5FMvc%5FDispatcher.html

basically you can call dispatcher methods in any controller

$this->dispatcher->getActiveController();

i think this is what you need ? i am not 100% sure tho



315
edited 15d ago

thanks for answer but i can not use $this in function pointer in before() ;/

if i use $app->dispatcher->getActiveController() i get NULL

Important attention. i use LazyLoader

There is no dispatcher in micro app.

$app->getActiveHandler(); This doesn't return just controller instance?



315
edited 14d ago

getActiveHandler() return an array. First argument is LazyLoader(instance) and second parameter is the called method.

LazyLoader has getDefinition method but this method return class path(NOT INSTANCE!).

I can do it:

$lazyLoader->getDefinition() === App\Controller\TestController::class

but not

$lazyLoader->getDefinition() instanceof App\Controller\TestController // <- i want like this