-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sven Marc Gehring
committed
May 21, 2014
1 parent
2fe2162
commit d52ddf4
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/** | ||
* crunchDB - A simple file based database system | ||
* written in pure PHP. Useful for smaller applications. | ||
* | ||
* Written and copyrighted 2014+ | ||
* by Sven Marc 'cybrox' Gehring | ||
* | ||
* Licensed under CC BY-NC-SA | ||
* Named after delicious cookies! | ||
*/ | ||
|
||
require_once('./src/crunchdb.class.php'); | ||
require_once('./src/crunchroot.class.php'); | ||
require_once('./src/crunchtable.class.php'); | ||
|
||
$reqMethd = (!empty($_GET['method'])) ? $_GET['method'] : ''; | ||
$reqTable = (!empty($_GET['table'])) ? $_GET['table'] : ''; | ||
$reqArgms = array($reqTable); | ||
|
||
$postArgs = $_POST; | ||
ksort($postArgs); | ||
foreach($postArgs as $a) array_push($reqArgms, $a); | ||
|
||
$cdb = new crunchDB(); | ||
$smooth = true; | ||
|
||
try { $res = call_user_func_array(array($cdb, $reqMethd), $reqArgms); } | ||
catch (Exception $e) { | ||
handleResponse(false, 'Caught exception: '.$e->getMessage()); | ||
$smooth = false; | ||
} | ||
|
||
if($smooth){ | ||
if(gettype($res) == 'boolean') handleResponse($res, 'performed action'); | ||
else handleResponse(true, $res); | ||
} | ||
|
||
|
||
function handleResponse($success, $message){ | ||
$data = ($success) ? $message : ''; | ||
$erro = ($success) ? '' : $message; | ||
echo json_encode(array( | ||
'success' => $success, | ||
'error' => $erro, | ||
'data' => $data | ||
)); | ||
} | ||
|
||
?> |