Created
May 9, 2012 14:17
-
-
Save chobie/2644787 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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