# init consumer/client
if (isset($_SERVER['PHP_AUTH_USER'])) {
    consumer::init($_SERVER['PHP_AUTH_USER'], $u);
} elseif (isset($_GET['client-id'])) {
    consumer::init($_GET['client-id'], $u);
}
#
# new Slim()
$app = new \Slim\Slim();
$app->config('debug', false);
# config/init template [twig]
$app->container->singleton('twig', function () {
    $twig = new \Slim\Views\Twig();
    $twig->parserExtensions = array(new \Slim\Views\TwigExtension());
    $templatePath = __DIR__ . '/api/templates';
    $twig->setTemplatesDirectory($templatePath);
    return $twig;
});
# 404 handler inside app()
$app->notFound(function () use($app) {
    $app->twig->display('error.php');
});
# Exception handler inside app()
$app->error(function (\Exception $e) use($app) {
    $app->twig->display('error.php');
});
# auth
if (!isset($_GET['client-id'])) {
    # Basic Authentication /vassarapi
    # use an authenticator() ? github/tuupola/slim-basic-auth
    $user_array = array("user-acct2" => "user-acct2", "user-acct1" => "user-acct1");
Exemple #2
0
    return new Moritz\Library\SecurityHandler($app);
});
// Email
$app->email = function () use($app) {
    return new Moritz\Library\EmailHandler($app->log, $app->config('email'));
};
// Sitemap
$app->container->singleton('sitemap', function () use($app) {
    return new Moritz\Library\SitemapHandler($app);
});
// Twig Template Rendering
$app->container->singleton('twig', function () use($app) {
    $twig = new \Slim\Views\Twig();
    $twig->parserOptions = $app->config('twig.parserOptions');
    $twig->parserExtensions = $app->config('twig.extensions');
    $twig->setTemplatesDirectory($app->config('templates.path'));
    return $twig;
});
// Encryption Function
$app->encrypt = function () use($app) {
    return function ($str) use($app) {
        $salt = $app->config('session');
        return hash('sha256', $str . $salt['salt']);
    };
};
// Image Upload
$app->uploader = function () use($app) {
    return function ($key) use($app) {
        $storage = new \Upload\Storage\FileSystem($app->config('file.path'));
        return new \Upload\File($key, $storage);
    };