Skip to content

Instantly share code, notes, and snippets.

@chobie
Created May 9, 2012 14:17
Show Gist options
  • Save chobie/2644787 to your computer and use it in GitHub Desktop.
Save chobie/2644787 to your computer and use it in GitHub Desktop.
<?php
namespace Pinatra;
class Application
{
protected static $instance;
public $routes = array();
public static function getInstnace()
{
if (!isset(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
public static function run()
{
$app = Application::getInstnace();
if (isset($app->routes[$_SERVER['REQUEST_URI']][$_SERVER['REQUEST_METHOD']])) {
$app->routes[$_SERVER['REQUEST_URI']][$_SERVER['REQUEST_METHOD']]();
}
}
public function route($method,$path,$callback)
{
$this->routes[$path][$method] = $callback;
}
}
function get($path,$callback,$options = array())
{
$app = Application::getInstnace();
$app->route('GET',$path,$callback);
}
register_shutdown_function('Pinatra\Application::run');
<?php
// extension版だとrequireしないでokになるはず
// php -S localhost:8888 route.php
require 'pinatra.php';
use Pinatra;
get("/",function(){
var_dump("Hello");
},[]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment