Skip to content

Instantly share code, notes, and snippets.

@Javlopez
Created August 22, 2011 21:31
Show Gist options
  • Save Javlopez/1163650 to your computer and use it in GitHub Desktop.
Save Javlopez/1163650 to your computer and use it in GitHub Desktop.
Rest implementation
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
/*
*
* ASI DEBE de SALIR
/users/
/users/add
/users/javier/delete
/users/0015/update
*/
Class User {
protected $_method;
protected $_arguments;
private function __construct()
{
$method = $this->getMethod();
switch ($method) {
case 'GET':
break;
case 'POST':
$arguments = $_POST;
break;
case 'PUT':
case 'DELETE':
parse_str(file_get_contents('php://input'), $arguments);
break;
}
}
/**
* apirun
*
* This static method run application (API) system
*/
static public function apirun()
{
new self;
}
public function getMethod()
{
return $this->_method = $_SERVER['REQUEST_METHOD'];
}
public function fd()
{
//["PATH_INFO"]
}
public function users()
{
}
}
User::apirun();
var_dump($_SERVER);
/*
*
/*
$method = $_SERVER['REQUEST_METHOD'];
switch ($method) {
case 'GET':
case 'HEAD':
$arguments = $_GET;
break;
case 'POST':
$arguments = $_POST;
break;
case 'PUT':
case 'DELETE':
parse_str(file_get_contents('php://input'), $arguments);
break;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment