예제 #1
0
 public function WriteResponse(RestResponse $restResponse, $statusCode = 200)
 {
     $this->slim->response()->header('Content-Type', 'application/json');
     $this->slim->response()->status($statusCode);
     $this->slim->response()->write(json_encode($restResponse));
     unset($restResponse);
 }
예제 #2
0
 /**
  * Check if the provided $user_id matches the logged-in user.
  *
  * @param mixed $user_id The user id.
  *
  * @return bool true if it's the logged in user, false otherwise.
  */
 public function checkUserId($user_id)
 {
     if (!isset($_SESSION) || $user_id != $_SESSION['user_id']) {
         $this->app->response()->status(403);
         $this->app->response()->write("Wrong user_id");
         return false;
     }
     return true;
 }
예제 #3
0
 private function runAppHead($action, $actionName, $mwOptions = NULL, $headers = array())
 {
     \Slim\Environment::mock(array('REQUEST_METHOD' => 'HEAD', 'SERVER_NAME' => 'localhost', 'SERVER_PORT' => 80, 'ACCEPT' => 'application/json', 'SCRIPT_NAME' => '/index.php', 'PATH_INFO' => '/' . $actionName));
     $app = new \Slim\Slim();
     $app->setName($actionName);
     $mw = function () {
         // Do nothing
     };
     if (isset($mwOptions)) {
         if (is_callable($mwOptions)) {
             $mw = $mwOptions;
         } else {
             $mwOptions['appName'] = $actionName;
             $mw = \CorsSlim\CorsSlim::routeMiddleware($mwOptions);
         }
     }
     $app->get('/:name', $mw, function ($name) use($app, $action) {
         if ($app->request->isHead()) {
             $app->status(204);
             return;
         }
         $app->contentType('application/json');
         $app->response->write(json_encode(array("action" => $action, "method" => "GET", "name" => $name)));
     });
     foreach ($headers as $key => $value) {
         $app->request->headers()->set($key, $value);
     }
     $app->run();
     $this->assertEquals(204, $app->response()->status());
     return $app;
 }
예제 #4
0
 /**
  * 
  * @return array ['status', 'headers', 'body']
  */
 protected function _getResponse($envArgs)
 {
     \Slim\Environment::mock($envArgs);
     $app = new \Slim\Slim();
     new \Voce\Thermal\v1\API($app);
     $app->call();
     return $app->response()->finalize();
 }
예제 #5
0
function autenticado()
{
    $app = new \Slim\Slim();
    $response = $app->response();
    $response->header('Access-Control-Allow-Origin', '*');
    $response->write(json_encode(array('autenticado' => true)));
    echo json_encode(array('autenticado' => false));
}
예제 #6
0
 public function request($method, $path, $options = array())
 {
     // Capture STDOUT
     ob_start();
     // Prepare a mock environment
     Environment::mock(array_merge(array('REQUEST_METHOD' => $method, 'PATH_INFO' => $path, 'SERVER_NAME' => 'slim-test.dev'), $options));
     $app = new \Slim\Slim();
     $this->app = $app;
     $this->request = $app->request();
     $this->response = $app->response();
     // Return STDOUT
     return ob_get_clean();
 }
 /**
  * Test maintenance middleware when 'maintenance' mode is enabled with a custom callable
  */
 public function testMaintenanceEnabledCustomCallable()
 {
     \Slim\Environment::mock(array('SCRIPT_NAME' => '/index.php', 'PATH_INFO' => '/'));
     $app = new \Slim\Slim(array('mode' => 'maintenance'));
     $app->get('/', function () {
         echo "Success";
     });
     $mw = new \Mnlg\Middleware\Maintenance(function () use($app) {
         $app->response()->body('Maintenance');
     });
     $mw->setApplication($app);
     $mw->setNextMiddleware($app);
     $mw->call();
     $this->assertEquals(200, $app->response()->status());
     $this->assertEquals('Maintenance', $app->response()->body());
 }
예제 #8
0
파일: rest.php 프로젝트: pdelbar/onethree
 /**
  * @param One_Scheme $scheme
  * @param $idOrAlias
  *
  * DELETE schemename/ID
  * Delete an item
  */
 public static function restDelete(One_Scheme $scheme, $idOrAlias)
 {
     try {
         $model = One_Repository::selectOne($scheme->getName(), $idOrAlias);
         if ($model === null) {
             throw new One_Exception_Rest_404('Cannot locate instance of scheme ' . $scheme->getName() . ' identified by ' . $idOrAlias);
         }
         $model->delete();
         $this->slim->response()->status(200);
         echo 'OK';
     } catch (One_Exception_Rest_404 $e) {
         // return 404 server error
         $this->slim->response()->status(404);
         echo '{}';
     } catch (Exception $e) {
         $this->slim->response()->status(400);
         $this->slim->response()->header('X-Status-Reason', $e->getMessage());
     }
 }
예제 #9
0
 /**
  * @param \Pimple $pimple
  */
 public function setup(\Pimple $pimple)
 {
     $me = $this;
     $pimple['db'] = function () use($me) {
         $conn = Utils::getConnection(SW_PATH);
         return $conn;
     };
     $pimple['filesystem.factory'] = function () use($me) {
         $updateConfig = $me->getParameter('update.config');
         $ftp = isset($updateConfig['ftp_credentials']) ? $updateConfig['ftp_credentials'] : array();
         return new FilesystemFactory(SW_PATH, $ftp);
     };
     $pimple['path.builder'] = function () use($me) {
         $baseDir = SW_PATH;
         $updateDir = UPDATE_FILES_PATH;
         $backupDir = SW_PATH . '/files/backup';
         return new PathBuilder($baseDir, $updateDir, $backupDir);
     };
     $pimple['migration.manager'] = function () use($me) {
         $migrationPath = UPDATE_ASSET_PATH . '/migrations/';
         $db = $me->get('db');
         $migrationManger = new MigrationManager($db, $migrationPath);
         return $migrationManger;
     };
     $pimple['dump'] = function () use($me) {
         $snippetsSql = UPDATE_ASSET_PATH . '/snippets.sql';
         $snippetsSql = file_exists($snippetsSql) ? $snippetsSql : null;
         if (!$snippetsSql) {
             return null;
         }
         return new Dump($snippetsSql);
     };
     $pimple['app'] = function () use($me) {
         $slimOptions = $me->getParameter('slim');
         $slim = new \Slim\Slim($slimOptions);
         $me->set('slim.request', $slim->request());
         $me->set('slim.response', $slim->response());
         return $slim;
     };
     $pimple['controller.batch'] = function () use($me) {
         return new BatchController($me->get('slim.request'), $me->get('slim.response'), $me);
     };
 }
예제 #10
0
        }
    };
};
$app->post("/auth/process/admin", function () use($app, $db) {
    $array = (array) json_decode($app->request()->getBody());
    $email = $array['email'];
    $password = $array['password'];
    $person = $db->admin()->where('email', $email)->where('password', $password);
    $count = count($person);
    if ($count == 1) {
        $_SESSION['admin'] = $email;
        $data = array('login_success' => "true", 'login_attempt_by' => $email, 'message' => "Successfull sigin");
    } else {
        $data = array('login_success' => "false", 'login_attempt_by' => $email, 'message' => "please provide correct details");
    }
    $app->response()->header('Content-Type', 'application/json');
    echo json_encode($data);
});
$app->get('/auth/process/admin', function () use($app) {
    if (isset($_SESSION['admin'])) {
        $data = $_SESSION['admin'];
    } else {
        $data = false;
    }
    $app->response()->header('Content-Type', 'application/json');
    echo json_encode($data);
});
$app->get("/auth/logout/admin", function () use($app) {
    unset($_SESSION['admin']);
});
$app->post("/auth/process/user", function () use($app, $db) {
예제 #11
0
<?php

require 'vendor/autoload.php';
$app = new \Slim\Slim();
//http://hostname/api/
$app->get('/', function () use($app) {
    echo "Welcome to Task REST API";
});
// http://domain.address/api/tasks
$app->get('/tasks', function () use($app) {
    $tasks = getTasks();
    //Define what kind is this response
    $app->response()->header('Content-Type', 'application/json');
    echo json_encode($tasks);
});
$app->get('/tasks/:id', function ($id) use($app) {
    $tasks = getTasks();
    $index = array_search($id, array_column($tasks, 'id'));
    if ($index > -1) {
        $app->response()->header('Content-Type', 'application/json');
        echo json_encode($tasks[$index]);
    } else {
        $app->response()->setStatus(204);
    }
});
//TODO move it to a DAO class
function getTasks()
{
    $tasks = array(array('id' => 1, 'description' => 'Learn REST', 'done' => false), array('id' => 2, 'description' => 'Learn JavaScript', 'done' => false), array('id' => 3, 'description' => 'Learn English', 'done' => false));
    return $tasks;
}
예제 #12
0
        } else {
            if ($issue['PRICING'] == 'free') {
                // Issue is marked as free, allow download
                $allow_download = true;
            }
        }
        if ($allow_download) {
            if (isInDevelopmentMode($app_id) == "TRUE" && !$app->request()->isHead()) {
                logMessage(LogType::Info, "Downloading ISSUE: " . $name . " for APP ID: " . $app_id . " USER ID: " . $user_id);
            }
            logAnalyticMetric(AnalyticType::ApiInteraction, 1, NULL, $app_id, $user_id);
            if (!$app->request()->isHead()) {
                logAnalyticMetric(AnalyticType::Download, 1, $name, $app_id, $user_id);
            }
            // Redirect to the downloadable file, nothing else needed in API call
            $app->response()->redirect($issue['URL'], 303);
        } else {
            header('HTTP/1.1 403 Forbidden');
            die;
        }
    } catch (PDOException $e) {
        // Handle exception
        logMessage(LogType::Error, $e->getMessage());
    }
});
// Purchases List
// *Returns a list of Purchased Product ID's
$app->get('/purchases/:app_id/:user_id', function ($app_id, $user_id) {
    global $dbContainer;
    $db = $dbContainer['db'];
    $purchased_product_ids = array();
예제 #13
0
    $parameters["id_course"] = $id_course;
    $MVC = new RESTFULLComponents(ACTION_DELETE_COURSES, $app, $parameters);
    // delete courses with the user given id_course
});
$app->delete("/ nationalities/:id", function ($id) use($app) {
    $parameters["id"] = $id;
    $MVC = new RESTFULLComponents(ACTION_DELETE_NATIONALITIES, $app, $parameters);
    // delete nationalities with the user given id
});
$app->delete("/ tasks/:task_id", function ($task_id) use($app) {
    $parameters["task_id"] = $task_id;
    $MVC = new RESTFULLComponents(ACTION_DELETE_TASKS, $app, $parameters);
    // delete task with the user given task_id
});
// set up common headers for every response
$app->response()->header(" Content - Type ", " application / json ; charset =utf -8");
// Run the slim framework(API).
$app->run();
class RESTFULLComponents
{
    public function __construct($action, $app, $parameters = null)
    {
        $model = new restfullModel();
        // common model
        $controller = new restfullController($model, $action, $app, $parameters);
        //common controller with different actions
        $view = new restfullView($controller, $model, $app);
        // common view
        $view->output();
        // this returns the response to the requesting client
    }
예제 #14
0
파일: index.php 프로젝트: 0x7678/activeMDM
        } else {
            // empty plist for you
            $res_plist = new \CFPropertyList\CFPropertyList();
            $res_plist->add($dict = new \CFPropertyList\CFDictionary());
            echo $res_plist->toXML(true);
        }
    }
});
$slim->get('/checkin', function () use($slim) {
    //doCheckin($slim);
});
$slim->put('/checkin', function () use($slim) {
    // read data, do things
    $body = $slim->request->getBody();
    if (!isset($body) || strlen($body) == 0) {
        $slim->response()->status(401);
        // not authorised
    } else {
        $body = str_replace("#012", "", $body);
        $body = str_replace("#011", "", $body);
        syslog(LOG_DEBUG, "c");
        syslog(LOG_DEBUG, $body);
        $plist = new \CFPropertyList\CFPropertyList();
        $plist->parse($body);
        $message = $plist->toArray();
        $message_type = $message["MessageType"];
        if ($message_type == "Authenticate") {
            // TODO: authentication
            // grab our UUID and create/update our data
            $udid = $message["UDID"];
            $device = array();
예제 #15
0
 /**
  * Test custom error handler uses existing Response object
  */
 public function testErrorHandlerUsesCurrentResponseObject()
 {
     $s = new \Slim\Slim(array('debug' => false));
     $s->error(function (\Exception $e) use($s) {
         $r = $s->response();
         $r->status(503);
         $r->write('Foo');
         $r['X-Powered-By'] = 'Slim';
         echo 'Bar';
     });
     $s->get('/bar', function () {
         throw new \Exception('Foo');
     });
     $s->call();
     list($status, $header, $body) = $s->response()->finalize();
     $this->assertEquals(503, $status);
     $this->assertEquals('FooBar', $body);
     $this->assertEquals('Slim', $header['X-Powered-By']);
 }
예제 #16
0
$app = new \Slim\Slim();
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
$app->get('/getShopByUserId', function () use($app) {
    $db = getDB();
    $user = json_decode($app->request->getBody(), true);
    $shop = array();
    $stt = "SELECT tblShop.id, tblShop.transactionValue,  ";
    $stt = $stt . " tblCart.gameIdFk, tblGame.name, tblGame.console, ";
    $stt = $stt . " tblGame.photoLink, tblCart.transactionValue as gameValue ";
    $stt = $stt . " FROM tblShop ";
    $stt = $stt . " INNER JOIN tblShopCart ON tblShopCart.id = tblCart.shopIdFk ";
    $stt = $stt . " INNER JOIN tblCart ON tblCart.id = tblShopCart.cartIdFk ";
    $stt = $stt . " INNER JOIN tblGame ON tblGame.id = tblCart.gameIdFk ";
    $stt = $stt . " WHERE tblShop.userIdFk = " . $user['id'] . " ; ";
    $result = mysql_query($stt, $db);
    if ($result) {
        while ($row = mysql_fetch_array($result)) {
            $shop[] = array('id' => $row['id'], 'transactionValue' => $row['transactionValue'], 'gameIdFk' => $row['gameIdFk'], 'name' => $row['name'], 'console' => $row['console'], 'photoLink' => $row['photoLink'], 'gameValue' => $row['gameValue']);
        }
    } else {
        echo 'FAIL';
    }
    $app->response()->header('Content_type', 'application/json');
    echo json_encode($shop);
});
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
$app->run();
예제 #17
0
<?php

# Definindo pacotes de retorno em padrão JSON...
header('Content-Type: application/json;charset=utf-8');
# Carregando o framework Slim...
require 'Slim\\Slim.php';
\Slim\Slim::registerAutoloader();
# Iniciando o objeto de manipulação da API SlimFramework
$app = new \Slim\Slim();
$app->response()->header('Content-Type', 'application/json;charset=utf-8');
function authenticate()
{
    $app = \Slim\Slim::getInstance();
    $user = $app->request->headers->get('HTTP_USER');
    $pass = $app->request->headers->get('HTTP_PASS');
    //recebo a senha jᠦormatada em md5
    $erro = 0;
    try {
        if ($user != "MG" or $pass != 'MG') {
            //se retornar e99 houve falha ao autenticar
            echo json_encode('e99');
            $erro = 1;
        }
    } catch (Exception $e) {
        //se retornar e100 houve algum erro
        echo json_encode('e100');
        $erro = 1;
    }
    if ($erro == 1) {
        $app->stop();
    }
예제 #18
0
    $layout = new Layout($main);
    $layout->loadRecent();
    $layout->loadPopular();
    $layout->loadFeatured();
    // Add SEO
    if (!empty($layout->featured)) {
        /* @var $content Content Featured content */
        $content = reset($layout->featured);
        $layout->title = $content->title;
        $layout->description = $content->description;
        $layout->keywords = $content->getKeywords();
        $layout->author = $content->author;
        $layout->main_image = $content->image->getUrl();
    }
    // Output layout
    $app->response()->body((string) $layout);
});
/*
 * Change idiom
 */
$app->get('/idiom/:idiom', function ($idiom) use($app) {
    BootWiki::setIdiom($idiom);
    $app->redirect(BASEURL);
});
/*
 * Display search results
 */
$app->get('/search', function () use($app) {
    // load query
    $q = $app->request()->get('q');
    // Process results
예제 #19
0
파일: index.php 프로젝트: CloCkWeRX/kort
// define REST resources
$app->get('/(:secret)', function ($secret = null) use($userGetHandler, $slim) {
    if (empty($secret) && isset($_SESSION['secret'])) {
        $secret = $_SESSION['secret'];
    }
    $userData = $userGetHandler->getUserBySecret($secret);
    $slim->returnData($userData);
});
$app->get('/:id/badges', function ($id) use($userBadgesHandler, $slim, $app) {
    $userBadgesHandler->setLanguage($app->request()->params('lang'));
    $userBadges = $userBadgesHandler->getUserBadges($id);
    $slim->returnData($userBadges);
});
$app->get('/:id/logout', function () use($app) {
    \session_destroy();
    $app->response()->write("Congratulations! You've now officially logged out!");
});
$app->put('/(:id)', function ($id = null) use($userHandler, $app) {
    if (empty($id)) {
        $id = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : -1;
    }
    $data = json_decode($app->request()->getBody(), true);
    //only allow certain attributes to be set via the webservice
    $allowedAttributes = array("username");
    $allowedData = array();
    foreach ($allowedAttributes as $attribute) {
        $allowedData[$attribute] = $data[$attribute];
    }
    $app->response()->write($userHandler->updateUser($id, $allowedData));
});
if (!isset($_SESSION)) {
예제 #20
0
<?php

require '../vendor/autoload.php';
require '../config.php';
$app = new \Slim\Slim(array('templates.path' => '../api', 'debug' => false));
// Define routes
$app->get('/:route', function () use($app) {
    $app->view(new \Slim\Views\Twig());
    $twig = $app->view->getInstance();
    $loader = $twig->getLoader();
    // This is a addition directory
    $loader->addPath('../templates');
    $app->view->parserOptions = array('charset' => 'utf-8', 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true);
    $app->view->parserExtensions = array(new \Slim\Views\TwigExtension());
    $app->render('index.html');
})->conditions(array("route" => "(|api|api/)"));
$app->get('/api/:name', function ($name) use($app) {
    $app->response()->header("Content-Type", "application/json");
    $app->response()->header("Cache-Control", "no-cache");
    $app->render('index.php', compact('app', 'name'));
});
// Run app
$app->run();
예제 #21
0
            $app->stop();
        } else {
            header("Content-Description: File Transfer");
            header("Content-Type: application/octet-stream");
            header("Content-disposition:attachment");
            -readfile($path);
        }
    } else {
        $app->notFound();
    }
});
$app->get("/view/:id", function ($id) use($app) {
    $file = $app->filesMapper->fetchFile($id);
    $path = $app->filesHelper->getPathToFile($file);
    if ($size = getimagesize($path)) {
        $app->response()->header('Content-Type', $size['mime']);
        readfile($path);
    } else {
        $app->notFound();
    }
});
$app->get("/thumbs/:id/:fileName", function ($id, $fileName) use($app) {
    $file = $app->filesMapper->fetchFile($id);
    $thumbName = $app->filesHelper->getThumbName($file);
    if (file_exists($app->filesHelper->getPathToFile($file)) && $thumbName == $fileName) {
        $thumb = new Filehosting\Thumbnail($id, $app->filesHelper->getPathToFile($file), $app->filesHelper->getRootDirectory(), 250, 250);
        $thumb->showThumbnail();
    } else {
        $app->notFound();
    }
});
예제 #22
0
        print_r("\n\n\n");
        if (isset($proc_params) && isset($procedure->proc_body)) {
            $sql_drop = 'DROP PROCEDURE IF EXISTS ' . $procedure->proc_name . "; \n";
            $sql_create = "CREATE PROCEDURE " . $procedure->proc_name . "(" . $proc_params . ") " . "BEGIN \n" . $procedure->proc_body . " \nEND; \n\n";
            if (!$mysqli->query($sql_drop) || !$mysqli->query($sql_create)) {
                return false;
            }
        }
    }
    return true;
}
$app->group('/', function () use($app, $dbsettings) {
    $username = $app->request()->headers('PHP_AUTH_USER');
    $password = $app->request()->headers('PHP_AUTH_PW');
    if ($username != $dbsettings->dbuser || $password != $dbsettings->dbpass) {
        $app->response()->status(401);
        $app->response()->header('WWW-Authenticate', sprintf('Basic realm="%s"', 'Protected Area'));
        return;
    }
    $app->get('/', function () use($app) {
        $app->render('app.html');
    });
    $app->post('procparams', function () use($app) {
        $entry = json_decode($app->request()->getBody());
        echo getInputParams($entry);
    });
    $app->get('api', function () use($app) {
        $app->render('../../api/api.json');
    });
    $app->post('api', function () use($app) {
        $json = $app->request()->getBody();
require_once '../service/ContraMedidaService.php';
require_once '../model/ContraMedida.php';
require_once '../Slim/Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$contraMedidaService = new ContraMedidaService();
$app->get("/", function () {
    echo "<h1>Hello World</h1>";
});
$app->get("/contraMedida/getall", function () use($app, $contraMedidaService) {
    echo '{"contraMedidas": ' . json_encode($contraMedidaService->buscarContraMedidas()) . '}';
});
$app->get("/contraMedida/:id", function ($id) use($app, $contraMedidaService) {
    echo json_encode($contraMedidaService->buscarContraMedida($id));
});
$app->post("/contraMedida/cadastrar", function () use($app, $contraMedidaService) {
    $app->response()->header("Content-Type", "application/json");
    $resultado = json_decode($app->request()->getBody());
    echo json_encode($contraMedidaService->cadastrarContraMedida($resultado->nomeContraMedida));
});
$app->put("/contraMedida/atualizar", function ($id) use($app, $contraMedidaService) {
    $app->response()->header("Content-Type", "application/json");
    $resultado = json_decode($app->request()->getBody());
    echo json_encode($contraMedidaService->atualizarContraMedida($resultado->idContraMedida, $resultado->nomeContramedida));
});
$app->delete("/contraMedida/remover/:id", function ($id) use($app, $contraMedidaService) {
    $app->response()->header("Content-Type", "application/json");
    $resultado = json_decode($app->request()->getBody());
    echo json_encode($contraMedidaService->removerContraMedida($id));
});
$app->run();
예제 #24
0
require 'lib/XSLTeaParser.class.php';
/**
 *
 * Debug
 *
 */
//error_reporting(E_ALL);
//ini_set("display_errors", 1);
/**
 *
 * Application
 *
 */
$app = new \Slim\Slim();
$app->get('/utilities', function () use($app) {
    $response = $app->response();
    $response->header('Access-Control-Allow-Origin', '*');
    $response->write(file_get_contents('utilities.json'));
});
$app->post('/parse', function () use($app) {
    $response = $app->response();
    $response->header('Access-Control-Allow-Origin', '*');
    $variables = array();
    parse_str($app->request->getBody(), $variables);
    if (isset($variables['xml']) && isset($variables['xsl'])) {
        $parser = new XSLTeaParser();
        $parser->setXML($variables['xml']);
        $parser->setXSL($variables['xsl']);
        if (isset($variables['import'])) {
            $parser->setImports($variables['import']);
        }
예제 #25
0
파일: index.php 프로젝트: 0x7678/activeMDM
<?php

require 'vendor/autoload.php';
require '../../lib/db.php';
require '../../lib/Classes/Config.php';
$slim = new \Slim\Slim(array('debug' => true, 'view' => new \Slim\Views\Twig()));
$view = $slim->view();
$view->parserOptions = array('debug' => true);
$view->parserExtensions = array(new \Slim\Views\TwigExtension());
/**
Root URL
*/
$slim->get('/', function () use($slim) {
    $slim->response()->redirect('index.php/index');
});
/**
The index page
*/
$slim->get('/index', function () use($slim) {
    $slim->render('index.php');
});
/**
The enrolment page
*/
$slim->get('/enrol', function () use($slim) {
    // $slim->contentType('application/x-apple-aspen-config');
    $config = get_config();
    if (!isset($config)) {
        $config = array("access_rights" => 1024, "organisation_name" => "Abstractec", "master_profile_uuid" => "1234", "cert_uuid" => "4567", "mdm_uuid" => "7890", "mdm_certificate" => "certificate", "mdm_certificate_password" => "password", "mdm_topic" => "com.abstractec.mdm", "check_in_url" => "http://127.0.0.1:8888/~jimbob/service/checkin", "service_url" => "http://127.0.0.1:8888/~jimbob/service");
    }
    $slim->response->headers->set('Content-Type', 'application/x-apple-aspen-config');
예제 #26
0
파일: index.php 프로젝트: CloCkWeRX/kort
/**
 * kort - the /db webservices
 */
/** Load Slim library */
require_once '../../../lib/Slim-2.1.0/Slim/Slim.php';
/** Load ClassLoader */
require_once '../../../server/php/ClassLoader.php';
// Load Slim library
\Slim\Slim::registerAutoloader();
Kort\ClassLoader::registerAutoLoader();
$app = new \Slim\Slim();
$dbHandler = new \Webservice\Database\DbHandler();
// define REST resources
$app->get('/:table(/:fields)', function ($table, $fields = null) use($dbHandler, $app) {
    if (!$dbHandler->checkAuth($app->request()->params('key'))) {
        $app->response()->status(403);
    } else {
        $fields = isset($fields) ? explode(",", $fields) : array("*");
        $where = $app->request()->params('where');
        $orderBy = $app->request()->params('orderby');
        $limit = $app->request()->params('limit');
        $app->response()->write($dbHandler->doSelect($fields, $table, $where, $orderBy, $limit));
    }
});
$app->post('/:table/:fields', function ($table, $fields) use($dbHandler, $app) {
    $request = $app->request();
    if (!$dbHandler->checkAuth($request->params('key'))) {
        $app->response()->status(403);
        return;
    }
    $fields = isset($fields) ? explode(",", $fields) : null;
예제 #27
0
     $courseController = new \Controllers\Cursos($app, $db);
     $courseController->checkname($name);
 });
 $app->get('/buscar/:usuario_id/:name', function ($usuario_id, $name) use($app, $db) {
     //busqueda de un curso por nombre
     $courseController = new \Controllers\Cursos($app, $db);
     $courseController->buscar($usuario_id, $name);
 });
 $app->post('/alta', function () use($app, $db) {
     //dar de alta un nuevo curso
     try {
         $request = $app->request();
         $courseController = new \Controllers\Cursos($app, $db);
         $courseController->crearCurso($request->post('nombre'), $request->post('descripcion'), $request->post('horarios'), $request->post('usuario_id'));
     } catch (Exception $e) {
         $app->response()->status(400);
         $app->response()->header('X-Status-Reason', $e->getMessage());
     }
 });
 $app->post('/generar_clase/', function () use($app, $db) {
     //generar una clase para un curso
     try {
         $request = $app->request();
         $courseController = new \Controllers\Cursos($app, $db);
         $courseController->generarClase($request->post('curso_id'));
     } catch (Exception $e) {
         $app->response()->status(400);
         $app->response()->header('X-Status-Reason', $e->getMessage());
     }
 });
 $app->post('/resolver_pendientes/', function () use($app, $db) {
<?php

require __DIR__ . '/../vendor/autoload.php';
use Sergeylukin\AmazonProductSearch as Amazon;
$app = new \Slim\Slim();
$app->get('/api/v1/product', function () use($app) {
    try {
        $Product = Amazon::factory()->findOneProductByKeyword($app->request->get('keyword'));
        // send response header for JSON content type
        $app->response()->header('Content-Type', 'application/json');
        echo json_encode((array) $Product);
    } catch (Exception $e) {
        $app->response()->status(400);
        $app->response()->header('X-Status-Reason', $e->getMessage());
    }
});
$app->run();
예제 #29
0
파일: index.php 프로젝트: erick305/testing
<?php

include_once dirname(__FILE__) . '/lib/Slim/Slim/Slim.php';
include_once dirname(__FILE__) . '/config.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
function debug($msg)
{
    if (is_string($msg)) {
        file_put_contents(dirname(__FILE__) . '/log/pfc.log', $msg . "\n", FILE_APPEND);
    } else {
        file_put_contents(dirname(__FILE__) . '/log/pfc.log', print_r($msg, true), FILE_APPEND);
    }
}
$req = $app->request();
$res = $app->response();
$res['X-Powered-By'] = 'phpfreechat-' . $GLOBALS['pfc_version'];
// connect custom user hooks
foreach ($GLOBALS['pfc_hooks'] as $hook_name => $hooks) {
    foreach ($hooks as $priority => $function) {
        $GLOBALS['pfc_hooks'][$hook_name][$priority] = $function($app, $req, $res);
    }
}
require 'routes/auth.php';
require 'routes/channels.php';
require 'routes/users.php';
$app->run();
예제 #30
0
 /**
  * {@inheritdoc}
  */
 public function register(Container $container)
 {
     $container['config'] = $this->config;
     $container['shopware.version'] = function () {
         $version = trim(file_get_contents(__DIR__ . '/../data/version'));
         return $version;
     };
     $container['slim.app'] = function ($c) {
         $slimOptions = $c['config']['slim'];
         $slim = new \Slim\Slim($slimOptions);
         $slim->contentType('text/html; charset=utf-8');
         $c['slim.request'] = $slim->request();
         $c['slim.response'] = $slim->response();
         return $slim;
     };
     $container['system.locker'] = function ($c) {
         return new SystemLocker(SW_PATH . '/recovery/install/data/install.lock');
     };
     $container['translation.service'] = function ($c) {
         return new TranslationService($c['translations']);
     };
     // dump class contains state so we define it as factory here
     $container['database.dump_iterator'] = $container->factory(function ($c) {
         $dumpFile = __DIR__ . '/../data/sql/install.sql';
         return new DumpIterator($dumpFile);
     });
     // dump class contains state so we define it as factory here
     $container['database.dump_iterator_en_gb'] = $container->factory(function ($c) {
         $dumpFile = __DIR__ . '/../data/sql/en.sql';
         return new DumpIterator($dumpFile);
     });
     // dump class contains state so we define it as factory here
     $container['database.snippet_dump_iterator'] = $container->factory(function ($c) {
         $dumpFile = __DIR__ . '/../data/sql/snippets.sql';
         return new DumpIterator($dumpFile);
     });
     $container['shopware.container'] = function (Container $c) {
         require_once SW_PATH . '/autoload.php';
         $kernel = new \Shopware\Kernel('production', false);
         $kernel->boot();
         $container = $kernel->getContainer();
         $container->get('models')->generateAttributeModels();
         return $container;
     };
     $container['shopware.theme_installer'] = function ($c) {
         $shopwareContainer = $c['shopware.container'];
         /** @var $themeInstaller \Shopware\Components\Theme\Installer */
         $themeInstaller = $shopwareContainer->get('theme_installer');
         return $themeInstaller;
     };
     $container['http-client'] = function ($c) {
         return new CurlClient();
     };
     $container['theme.service'] = function ($c) {
         return new ThemeService($c['db'], $c['shopware.theme_installer']);
     };
     $container['install.requirements'] = function ($c) {
         return new Requirements(__DIR__ . '/../data/System.xml');
     };
     $container['install.requirementsPath'] = function ($c) {
         $check = new RequirementsPath(SW_PATH, SW_PATH . '/engine/Shopware/Components/Check/Data/Path.xml');
         $check->addFile('recovery/install/data');
         return $check;
     };
     $container['db'] = function ($c) {
         throw new \RuntimeException("Identifier DB not initialized yet");
     };
     $container['config.writer'] = function ($c) {
         return new ConfigWriter(SW_PATH . '/config.php');
     };
     $container['webserver.check'] = function ($c) {
         return new WebserverCheck($c['config']['check.ping_url'], $c['config']['check.check_url'], $c['config']['check.token.path'], $c['http-client']);
     };
     $container['database.service'] = function ($c) {
         return new DatabaseService($c['db']);
     };
     $container['license.service'] = function ($c) {
         return new LocalLicenseUnpackService();
     };
     $container['license.installer'] = function ($c) {
         return new LicenseInstaller($c['db']);
     };
     $container['menu.helper'] = function ($c) {
         $routes = $c['config']['menu.helper']['routes'];
         return new MenuHelper($c['slim.app'], $c['translation.service'], $routes);
     };
 }