$method = $route['method']; switch ($method) { case 'get': case 'delete': $controllerAction = "\\" . $route['controller'] . ":" . $route['action']; $this->app->{$method}($route['url'], $controllerAction); break; case 'post': case 'patch': /* The following results in the dynamic construction of something like this: $app->post('/users', function() use ($app) { (new \HelloController($app))->addUser(); }); */ $this->app->{$method}($route['url'], function () use($route) { $controllerString = "\\" . $route['controller']; $controller = new $controllerString($this->app); $controller->{$route}['action'](); }); break; default: // Invalid method break; } } } $app = new \Slim\Slim(); $router = new Router($app); $router->loadRoutes()->parseRoutes(); $app->run();