phalcon / phalcon

[WIP] Phalcon Framework. Work will continue after release of v5.0
https://phalcon.io
MIT License
219 stars 46 forks source link

Can't get module name from cli dispatcher #152

Open lanlin opened 6 years ago

lanlin commented 6 years ago

phalcon: 3.2.4

description

My project has multiple modules for both mvc application & cli application.

There's many events attached in my project, like 'dispatch:beforeDispatchLoop'.

When this event triggered, from the "getModuleName" method of \Phalcon\Cli\Dispatcher can't get the module name, but \Phalcon\Mvc\Dispatcher did.

The source code of mvc application has called the "setModuleName" method when handle a request, image

but the cli console hasn't. image

So in cli mode, how to get the module name from the callback function of dispatch event?

Jurigag commented 6 years ago

There are no modules system in cli mode.

You would need to write your own dispatcher for multi module cli.

You can see this - https://forum.phalconphp.com/discussion/7283/multiple-module-cli

lanlin commented 6 years ago

@Jurigag I did that from the beginning.

I didn't attach any event in cli mode before. After attach events, i find i can't get module name from callback.

image

Like above, the $arguments passed to handle() contains a module name.

In mvc application's handle() method, line 266 dispatcher->setModuleName been called, so module name been setted correct, but it's not been setted yet in console's handle() method.

I think that's why i can't get the module name from event callback. image

The getTaskName & getActionName methods both can return a valid value.

I have another way to get the module name, from the router $router->getModuleName. I just wander could it be a issue?

Jurigag commented 6 years ago

It's not set because Dispatcher cli doesn't use modules at all. It's not an issue. Just dispatcher cli/router doesn't support modules.

lanlin commented 6 years ago

@Jurigag thanks for your help.

Could it be supported in next version?

I think the peoples who choosen phalcon that means they should be have a little complex project like me, so both cli and mvc all need support multiple modules.

niden commented 5 years ago

Closing in favor of phalcon/cphalcon#13855. Will revisit if the community votes for it, or in later versions.