diff --git a/docroot/include/core/Exception.php b/docroot/include/core/Exception.php new file mode 100644 index 0000000..1da5ce2 --- /dev/null +++ b/docroot/include/core/Exception.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/docroot/include/core/ZirrorAPI.php b/docroot/include/core/ZirrorAPI.php new file mode 100644 index 0000000..56d66ba --- /dev/null +++ b/docroot/include/core/ZirrorAPI.php @@ -0,0 +1,16 @@ +request = $request; + return (true); + + } + +} + +?> \ No newline at end of file diff --git a/docroot/include/http/Request.php b/docroot/include/http/Request.php new file mode 100644 index 0000000..36dc6aa --- /dev/null +++ b/docroot/include/http/Request.php @@ -0,0 +1,36 @@ +rawData = file_get_contents ( "php://input" ); + break; + default : + Header ( "Location: http://www.Zirror.com" ); + exit ( 0 ); + } + + $this->rData = json_decode ( $this->rawData ); + + } + + function get($key) { + + if (! isset ( $this->rData->$key )) { + return false; + } else + return $this->rData->$key; + + } + +} +?> \ No newline at end of file diff --git a/docroot/include/runtime/Start.php b/docroot/include/runtime/Start.php new file mode 100644 index 0000000..193298a --- /dev/null +++ b/docroot/include/runtime/Start.php @@ -0,0 +1,32 @@ +authenticated; + + } + + function setAuth($authenticated) { + + if ($this->login) + throw new ApiException ( 'Login is already set.' ); + $this->authenticated = $authenticated; + + } + + function hasAuth() { + + return $this->getAuth () ? true : false; + + } + + abstract function process(ZirrorAPI_Request $request); + +} +?> \ No newline at end of file diff --git a/docroot/index.php b/docroot/index.php index 230cabc..245a641 100755 --- a/docroot/index.php +++ b/docroot/index.php @@ -4,47 +4,35 @@ ini_set ( 'include_path', $_SERVER ['DOCUMENT_ROOT'] . "./include/" ); include ("config.php"); -$rMethod = isset ( $_SERVER ['REQUEST_METHOD'] ) ? $_SERVER ['REQUEST_METHOD'] : "FAIL"; +include_once "include/core/ZirrorAPI.php"; -switch ($rMethod) { - case 'POST' : - processPost ( file_get_contents ( "php://input" ) ); - break; - default : - Header ( "Location: http://www.Zirror.com" ); - exit ( 0 ); +$ZirrorAPI = new ZirrorAPI (); +$ZirrorAPI->process ( new ZirrorAPI_Request () ); + +if (! isset ( $pData->module )) { + $rData = array (); + $rData ['result'] = 'EXCEPTION'; + $rData ['resultCode'] = - 1; + $rData ['resultString'] = 'FOOBAR'; + $rData ['accessToken'] = 0; + print (json_encode ( $rData )) ; + exit ( 0 ); } -function processPost($jData) { - - $pData = json_decode ( $jData ); - - if (! isset ( $pData->module )) { +switch ($ZirrorAPI->request->get ( "module" )) { + case 'user' : + userModule ( $ZirrorAPI->request ); + break; + case 'session' : + sessionModule ( $ZirrorAPI->request ); + break; + default : $rData = array (); $rData ['result'] = 'EXCEPTION'; $rData ['resultCode'] = - 1; - $rData ['resultString'] = 'FOOBAR'; + $rData ['resultString'] = 'INVALID MODULE: ' . $ZirrorAPI->request->get ( "module" ); $rData ['accessToken'] = 0; print (json_encode ( $rData )) ; - exit ( 0 ); - } - - switch ($pData->module) { - case 'user' : - userModule ( $pData ); - break; - case 'session' : - sessionModule ( $pData ); - break; - default : - $rData = array (); - $rData ['result'] = 'EXCEPTION'; - $rData ['resultCode'] = - 1; - $rData ['resultString'] = 'INVALID MODULE: ' . $pData->module; - $rData ['accessToken'] = 0; - print (json_encode ( $rData )) ; - } - } function userModule($pData) {