It's common for many frameworks to have classes that can accept configuration parameters from an array, but why arrays, if we may use closures or invokable classes?
For example some router service:
class Router
{
public function __construct(Closure $config)
{
$closure($this);
}
public function addRoute(...$params) {
// some code
}
}
config/router.php:
return function($router) {
$router
->addRoute('/')
->setName('home')
;
// and so on....
}
Then somewhere:
$router = new Router(include 'config/router.php');
$controller = $router->match('/some/path');
Am I missing something? Maybe I'm not experienced enough, but I haven't seen this approach yet.
Aucun commentaire:
Enregistrer un commentaire