Extend Routes By files?

For my apps I parse the url first before involving Slim routes to determine which component I need to load.

My app component structure:

app/components
  /contacts
	/controllers
	/models
	containers.php
	index.php

 /users
	/controllers
	/models
	containers.php
	index.php

The base route in the url determines which component to load:

www.myapp.com/contacts
www.myapp.com/users

The index.php file in the component dir (app/components/contacts/index.php) requires the containers and sets the routes.

I use a switch statement in my router for some routes that might not follow this guideline.

// app/config/router.php

$_url = parse_url($_SERVER['REQUEST_URI']);
$_routes = explode('/',$_url['path']);
$_baseRoute = $_routes[1];
$_componentFile = 'app/components/' . $_baseRoute . '/index.php';';

switch ($_baseRoute) {
	case 'someweirdroute':
		require 'app/components/myOneOffComponent/index.php';
		break;

	default:
		if (!file_exists($_componentFile)) {
		  die('Invalid Request');
	    }
	    require $_componentFile;
		break;
}

Here’s how I set it up in public/index.php:

chdir(dirname(__DIR__));

require_once 'vendor/autoload.php';

$app = new Slim\App;

// custom router
require 'app/config/router.php';

$app->run();

Hope this helps