Created
July 25, 2016 12:37
-
-
Save robrotheram/281d00bfb6e85bd45048187127f01ff0 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Created by PhpStorm. | |
* User: robert | |
* Date: 07/06/2015 | |
* Time: 18:55 | |
*/ | |
namespace ParseApp; | |
ini_set('display_errors',1); | |
ini_set('display_startup_errors',1); | |
error_reporting(-1); | |
class api { | |
public $response; | |
public $status; | |
public $error; | |
private $url; | |
private $class; | |
private $methodname; | |
function __construct($url){ | |
$this->url = $url; | |
$this->tidyUrl(); | |
if($this->status!=500){$this->callback();} | |
} | |
public function tidyUrl() | |
{ | |
$url = $this->_cleanUrl($this->url); | |
$url = explode('/', $url); | |
if((isset($url[2]))&&(isset($url[3]))){ | |
$this->class = $url[2]; | |
$this->methodname = $url[3]; | |
}else { | |
$this->error("Name Space incorrect"); | |
} | |
} | |
public function callback(){ | |
$class = __NAMESPACE__; | |
$class .= '\\' .$this->class; | |
if(class_exists($class)){ | |
$class = new $class; | |
$method = $this->methodname; | |
if(method_exists($class,$method)){ | |
$postdata = file_get_contents("php://input"); | |
$request = json_decode($postdata); | |
$this->response["status"] = 200; | |
$this->response["message"]=$class->$method($request); | |
}else{ | |
//$this->error("Method Does not exist"); | |
} | |
}else{ | |
$this->error("Class Does not exist"); | |
} | |
} | |
private function _cleanUrl($url) | |
{ | |
$url = trim($url); | |
return $url; | |
} | |
private function error($error){ | |
$this->status = 500; | |
$this->error = $error; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment