public function testMethod()
 {
     $app = new \OnePHP\App();
     $func = function () {
         return true;
     };
     //default HTTP Requests in OneFramework
     $app->get('/get', $func);
     $app->post('/post', $func);
     $app->put('/put', $func);
     $app->delete('/delete', $func);
     $routes = $app->getRoutes();
     //check if routes are found
     $this->assertEquals('/get', $routes['GET'][0]->route);
     $this->assertEquals('/post', $routes['POST'][0]->route);
     $this->assertEquals('/put', $routes['PUT'][0]->route);
     $this->assertEquals('/delete', $routes['DELETE'][0]->route);
 }
Ejemplo n.º 2
0
    }
});
$app->post('/api/:action', function ($action) use($app) {
    // login
    if ($action == "auth") {
        $response = auth();
        $app->JsonResponse($response);
        return;
    }
    // verifica o Token
    $auth = checkAuth($app->getRequest()->header("Authorization"));
    if (!$auth["success"]) {
        $app->JsonResponse($auth);
        return;
    }
    $data = (array) json_decode($app->getRequest()->getBody());
    // define o nome da model, se não existir usa a base model
    $entity = ucfirst(load($action));
    // instancia a model, passando o nome da action (tabela) como parametro
    $model = new $entity($action);
    // chama o metodo
    try {
        $response = $model->save($data);
        // imprime a resposta em JSON
        $app->JsonResponse($response);
    } catch (Exception $e) {
        // imprime a resposta em JSON
        $app->JsonResponse('[' . $e->getMessage() . ']', 500);
    }
});
$app->put('/api/:action/:id', function ($action, $id) use($app) {
    // verifica o Token
Ejemplo n.º 3
0
require_once 'lib/OnePHP/one_framework.php';
/*
 * Remember remove this examples to avoid collisions in routes
 */
//load Micro Framework with debug enabled
$app = new \OnePHP\App();
$app->get('/telegramBot/', function () use($app, $aTParam) {
    //Action on the Root URL
    return $app->ResponseHTML("\r\n        <a href=\"https://api.telegram.org/bot" . $aTParam['token'] . "/setWebhook?url=" . $aTParam['urlWebhooks'] . "\"> attiva WebHooks </a> <br/>\r\n        <a href=\"https://api.telegram.org/bot" . $aTParam['token'] . "/setWebhook?url=\"> disattiva WebHooks </a> <br/>\r\n        <a href=\"https://api.telegram.org/bot" . $aTParam['token'] . "/getUpdates\"> getUpdate WebHooks </a> <br/>\r\n        <a href=\"https://api.telegram.org/bot" . $aTParam['token'] . "/getMe\"> getMe </a> <br/>");
});
$app->post('/telegramBot/command.php', function () use($app, $database) {
    log::addLog('Chiamata');
    try {
        $message = json_decode(file_get_contents('php://input'), true);
        log::addLog(print_r($message, true));
        $database->insert("log", ["chat_idMessage" => $message['message']['message_id'], "chat_idUser" => $message['message']['from']['id'], "chat_name" => $message['message']['from']['first_name'], "chat_surname" => $message['message']['from']['last_name'], "chat_username" => $message['message']['from']['username'], "chat_date" => $message['message']['date'], "chat_text" => $message['message']['text'], "chat_log" => print_r($message, true)]);
    } catch (Exception $e) {
        log::addLog('Caught exception: ' . $e->getMessage());
    }
    return $app->ResponseHTML("Finito.");
});
$app->get('/telegramBot/message.php', function () use($app, $aTParam) {
    $data = array('chat_id' => 28751773, 'text' => 'ciao io funziono...');
    $request = new HTTPRequest($aTParam['urlCommand'] . 'sendMessage', HTTP_METH_POST);
    $request->setRawPostData($data);
    $request->send();
    $response = $request->getResponseBody();
    print_r($response);
    //// use key 'http' even if you send the request to https://...
    //    $options = array(
    //        'http' => array(