cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Vote to rename Application classes

Open dschissler opened this issue 7 years ago • 14 comments

I'm creating a vote to see if there is any degree of consensus for renaming the application classes as brought up in #13714. Please try to keep on point. Please don't use this issue to flesh out completely new ideas since there is already another issue for that.

Choice 1

Keep it as it is.

Choice 2

Other

Choice 3

use Phalcon\Application\Cli;
use Phalcon\Application\Micro;
use Phalcon\Application\Mvc;

The upside is a short namespace which is to the point. The downside is that the root Phalcon\Application namespace will need to be cluttered with other non-application classes such as Exception and in a third-party framework there could be much more.

Choice 4

use Phalcon\Application\Cli\Console;
use Phalcon\Application\Web\Micro;
use Phalcon\Application\Web\Mvc;

The upside here is that the application classes are classified into their run mode, ie; run from the command line or through a server process. Another upside is that the root Phalcon\Application is free to store other types of classes. The downside here is a longer namespace.

Choice 5

use Phalcon\Application\Types\Console;
use Phalcon\Application\Types\Micro;
use Phalcon\Application\Types\Mvc;

The upside here is that the application classes are all contained within their own namespace and so the root Phalcon\Application can be used to store other types of classes such as Exception. The downside here is a longer namespace.

Choice 6

Rename Phalcon\Cli\Console to Phalcon\Cli\Application and call it a day.

dschissler avatar Feb 28 '19 00:02 dschissler

Voting for **Choice 4 ** In genereal 3 scenarios \Phalcon\Application\Web\SelfHosted, \Phalcon\Application\Web\RequestHandler (under web server) and \Phalcon\Application\Console (regular application with readline, arg parser & etc like composer)

But better with Choice nr.2 (not sure if it can be released in near future), because I think there should be some kind of builder (like in NETCore there is Builder pattern and You can do whatever You want)

Just move App entrypoint logic to middlewares/closures/delegates.

My use cases will be:

  • Command line can have direct execution of task, and/or read input, and/or start daemon for serving content (debug mode?). We need correct arg processing also. Somebody already mentioned, that there should be environment auto-setup possibilities.
  • For request handling it is simple - we just need pass concrete Router/Dispatcher (middlewares) implementation and configure them (already done?)

So, my example to handle web requests from self-hosted Cli selfhosted-swoole.php In console just type:

$ php selfhosted-swoole.php --port=80

<?php
...
// autoload stuff
...
try { 
    // returns \Phalcon\Application\Web\SelfHosted;
    $appBuilder = \Phalcon\Application\ApplicationBuilder::createWebHost();

    // Create propper app instance with builder and initilize everything needed in build()
    $app = $appBuilder
       ->useConfigurator(function () use ($appBuilder) { 
               // can inject needed services to builder
              new \Phalcon\Application\Web\Configurator\Mvc($appBuilder);
       })
       ->useConfigurator(function () use ($appBuilder) { 
              // for example propper Swoole http/2 server initialization
              new \Phalcon\Application\Web\Configurator\SwooleServer($appBuilder);
       })
       ->useEnvironment(\Phalcon\Env::autoDetect())
       ->build(); 

    // parent process will see correct exit-code
    return $app->boot()->run(); 
} catch (...) { 
     // parent process will see correct exit-code
     return 1; 
}

ViltusVilks avatar Feb 28 '19 09:02 ViltusVilks

I vote for choice 4

@ViltusVilks Take a look at my PR for DI Presets. I'm intending them to replace the factory defaults since they can simply do more. How do they fit with your "Configurator" idea?

dschissler avatar Feb 28 '19 15:02 dschissler

I vote for choice 4. I think more than it's name, the internal implementation must change. For example, the method handle in \Phalcon\Mvc\Application has to be separated into multiple protected functions. This makes it easier for procedure modification

erisrayanesh avatar Mar 02 '19 11:03 erisrayanesh

@erisrayanesh You are saying that there should be two different base application classes? So the inheritance chain looks like Phalcon\Application -> Phalcon\Application\Cli -> Phalcon\Application\Cli\Console?

dschissler avatar Mar 02 '19 15:03 dschissler

Choice 5

grigoriy-ivanov avatar Mar 02 '19 16:03 grigoriy-ivanov

Choice 3

ekmst avatar Mar 02 '19 17:03 ekmst

@dschissler No. I think choice 4 is OK. I created a new issue (#13873) for what I tried to say but apart from their namespace (and directory structure), current implementation of all 3 applications have very low chance and capacity of routins customization.

erisrayanesh avatar Mar 03 '19 15:03 erisrayanesh

For the sake of simplicity and KISS, I vote for Choice 3

stamster avatar Mar 04 '19 12:03 stamster

I'm leaning to change my vote to Choice 3 as I outlined in the other talking issue. I don't want to get a huge topic going in this vote issue but my idea is that Choice 3 gets us there, is good enough and there is always the possibility to tweak it more during the v4 development. Most of the work is moving the classes around and its a very small amount of work to nest them one level deeper. Depending on @erisrayanesh 's findings then there could be more of a reason to go with another option over another. Again if we went with Choice 3 then its basically there for everyone and then someone could later propose a tweak to the de facto new class structure. I think that an incremental change can be very effective when dealing with a group and when it won't lead to a dead end just to try an idea. Choice 3 could be a stepping stone to anything else. Maybe that next thing needs to have a technical rationale. If people who are voting for Choice 4 could get behind Choice 3 then we can make it happen and I promise to pursue any other later tweaks if there is a technical reason for it. I can easily do that work myself, its just a matter of consensus.

dschissler avatar Mar 04 '19 17:03 dschissler

Choice 3

jturbide avatar Mar 04 '19 18:03 jturbide

All right @dschissler, I'd like to accept your offer. I get behind the Choice 3 If there is a chance to change my mind here

erisrayanesh avatar Mar 08 '19 16:03 erisrayanesh

@niden I think that its safe to safe that the community is decided on Choice 3. Also it will be easy to make small changes to another Choice. So we could then after committing source for Choice 3 we could put a vote on whether to change it from Choice 3 to say Choice 4 or 5. That is minimal work since Choice 4 and 5 are just one level difference in nesting (if we decide to do that). So any work done isn't a dead end. If you close this issue with comment Choice 3 was chosen then I can put this on my work queue. I won't be spending the time on this unless its pre-approved (the idea not the source).

I did it this way to work through community paralysis.

dschissler avatar Mar 14 '19 22:03 dschissler

Choice 3

LenoM avatar Mar 21 '19 11:03 LenoM

No choice 7? To replace Application with shorter App.

use Phalcon\App\Types\Console;
use Phalcon\App\Types\Micro;
use Phalcon\App\Types\Mvc;

ghost avatar Apr 04 '19 04:04 ghost