Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Created June 2, 2012 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coreymcmahon/2856378 to your computer and use it in GitHub Desktop.
Save coreymcmahon/2856378 to your computer and use it in GitHub Desktop.
The first version of our front controller for Simplex. - http://www.symfonycentral.com
<?php
/* Import the autoloader and classes from external namespaces */
require_once __DIR__.'/../src/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/* Build the request and response objects using HttpFoundation */
$request = Request::createFromGlobals();
$response = new Response();
/* Create routes... */
$map = array(
'/hello' => __DIR__.'/../src/pages/hello.php',
'/bye' => __DIR__.'/../src/pages/bye.php',
);
/* Handle the request and create the response */
$path = $request->getPathInfo();
if (isset($map[$path])) {
ob_start();
include $map[$path];
$response->setContent(ob_get_clean());
} else {
$response = new Response('Not found', 404);
}
/* Send the response */
$response->send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment