Skip to content

Instantly share code, notes, and snippets.

@cgsmith
Last active August 29, 2015 14:19
Show Gist options
  • Save cgsmith/6ef17173539795e98637 to your computer and use it in GitHub Desktop.
Save cgsmith/6ef17173539795e98637 to your computer and use it in GitHub Desktop.
<h1>Cart</h1>
<?php
require 'lib/myLibrary.php';
?>
<p>Your cart consists of <?=$_GET['item']. ' for $' . $inventory[$_GET['item']]/100;?></p>
<h1>My Storefront</h1>
<?php
// Pulling in a library - this would be everywhere
require 'lib/myLibrary.php';
// loop over our inventory for the main page
// @todo: remove comments - this is a legacy app
echo '<ul>';
foreach ($inventory as $item => $price) {
echo '<li>' . $item . ' sells for ';
echo '$' . $price/100;
echo ' <a href="buyit.php?item=' . $item . '">Buy it!</a></li>';
}
echo '</ul>';
<?php
// A start towards refactoring
require 'classes/router.php';
require 'classes/request.php';
// First step is to configure current routes
$routes = [
'/' => 'home.php',
'/index.php' => 'home.php',
'/buyit.php' => 'buyit.php'
];
$request = new request($_REQUEST,$_SERVER);
$router = new router($routes, $request);
/**
* If your router does not match the old route - run through your application
* otherwise load up the requires again ;)
*/
if (!$router->match()) {
$app = new application();
$app->run();
}else {
require $router->getOldRoute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment