Example #1
0
* See the License for the specific language governing permissions and
* limitations under the License.
*/
require_once dirname(__DIR__) . "/vendor/autoload.php";
use fkooman\Config\Config;
use fkooman\Http\JsonResponse;
use fkooman\Http\Request;
use fkooman\Http\IncomingRequest;
use fkooman\Rest\Service;
use fkooman\Rest\Plugin\BasicAuthentication;
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) {