Exemplo n.º 1
0
use fkooman\VootProvider\VootStorageException;
try {
    $config = Config::fromIniFile(dirname(__DIR__) . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "voot.ini");
    $vootStorageBackend = sprintf('fkooman\\VootProvider\\%s', $config->getValue('storageBackend'));
    $vootStorage = new $vootStorageBackend($config);
    $request = Request::fromIncomingRequest(new IncomingRequest());
    $service = new Service($request);
    // require authentication?
    if (null !== $config->getValue('basicUser')) {
        $basicAuthPlugin = new BasicAuthentication($config->getValue('basicUser'), $config->getValue('basicPass'), $config->getValue('serviceName'));
        $service->registerBeforeMatchingPlugin($basicAuthPlugin);
    }
    // GROUPS
    $service->match("GET", "/groups/:uid", function ($uid) use($request, $vootStorage) {
        $groups = $vootStorage->isMemberOf($uid, $request->getQueryParameter("startIndex"), $request->getQueryParameter("count"));
        $response = new JsonResponse(200);
        $response->setContent($groups);
        return $response;
    });
    // PEOPLE IN GROUP
    $service->match("GET", "/people/:uid/:gid", function ($uid, $gid) use($request, $vootStorage) {
        $users = $vootStorage->getGroupMembers($uid, $gid, $request->getQueryParameter("startIndex"), $request->getQueryParameter("count"));
        $response = new JsonResponse(200);
        $response->setContent($users);
        return $response;
    });
    $service->run()->sendResponse();
} catch (VootStorageException $e) {
    $response = new JsonResponse($e->getResponseCode());
    $response->setContent(array("error" => $e->getMessage(), "error_description" => $e->getDescription()));
    $response->sendResponse();
} catch (Exception $e) {