slimphp / Slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
http://slimframework.com
MIT License
11.98k stars 1.95k forks source link

Let router resolve `MyController::method` callable with and without container #2049

Closed codeguy closed 7 years ago

codeguy commented 7 years ago

Because the DIC is optional, should we let router continue to resolve MyController::method route callables even if no DIC container is specified? Or should the DIC be required to use this callable format?

/cc @akrabat

geggleto commented 7 years ago

DIC should be required, imo

codeguy commented 7 years ago

Why? You'll still be welcome to provide one, but there won't be one by default. One less dependency. Should also simplify the codebase.

kadevland commented 7 years ago

feature propose : add a namespace by default ( by setting) like App\Controllers

$app->get('\','HomeController::index') ==> App\Controllers\HomeController

akrabat commented 7 years ago

@kadevland You can add namespace App\Controllers; to the top of routes.php file and you can do that today in Slim 3.

geggleto commented 7 years ago

I don't think it really would simplify it at all. Instead of accessing a service from the container we now need our own dependency management solution for Slim's services. The easiest way is singletons, or we end up with our own internal DIC... which raises the question of why bother.

These are the only 2 solutions that I can come up with, so perhaps there are more options that are better.

//cc @akrabat @codeguy @silentworks

kadevland commented 7 years ago

@akrabat thx for this astuce

mathmarques commented 7 years ago

I think we should allow MyController::method even without DIC. Otherwise we will be forcing users to add all controllers on the DIC (I'm not saying that this is a bad thing).

codeguy commented 7 years ago

After further review, this is actually already in place EXCEPT for one change. We need to make the CallableResolver::__construct() arguments optional.

codeguy commented 7 years ago

PR https://github.com/slimphp/Slim/pull/2095

codeguy commented 7 years ago

Done