예제 #1
0
 function testParameter()
 {
     $r = new Rest\Server();
     $r->setParameter("foo", "bar");
     $this->assertEqual($r->getParameter("foo"), "bar");
 }
예제 #2
0
// First we include the restserver lib
//include '../restserver.phar';
include '../src/Rest/Server.php';
include 'Items.php';
// Them we instantiate the server
// Using the rewrite rule on .htaccess file the request url is passed into $_GET['q']
// Therefore we pass this parameter to restserver
// If app is running on root and .htacces working, them restserver can guess the url
$server = new Rest\Server($_GET["q"]);
// The server handles proper mime-types, * is for no extension
$server->setAccept(array("*", "application/json"));
// Using the "setParameter" we can have some globaly available vars
// This var will be accessible to all requests handlers
// Here I define a salt for the user authentication
$server->setParameter("salt", "&dcalsd-09o");
// Since this is just a demo I don't want to get much into
// Logic and stuff, so I'm creating a database on sqlite on
// the fly just to run something
$create = !file_Exists("data.db");
if ($create) {
    touch("data.db");
}
$db = new PDO("sqlite:data.db");
if ($create) {
    $db->query(file_get_contents("schema.sql"));
}
// Again using the server to setup some global database
$server->setParameter("db", $db);
// This is a dummy authentication function receiving
// a server instance (exactly like the handlers will receive)