Skip to content

Commit 621e11c

Browse files
committed
Updated deps, added simple example.
1 parent 2a437dd commit 621e11c

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/simple.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
require __DIR__.'/../vendor/autoload.php';
4+
5+
use Symfony\Component\HttpFoundation\Request;
6+
7+
$app = new Silex\Application();
8+
9+
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
10+
11+
$app['debug'] = true;
12+
$app['env'] = 'dev';
13+
14+
$app->get('/', function (Request $request) use ($app) {
15+
$output = 'Hello!';
16+
if ($request->attributes->has('stack.authn.token')) {
17+
$output .= ' Your token is '. $request->attributes->get('stack.authn.token');
18+
} else {
19+
$output .= ' <a href="'.$app['url_generator']->generate('login').'">Login</a>';
20+
}
21+
22+
return $output;
23+
})->bind('home');
24+
25+
$app->get('/login', function (Request $request) use ($app) {
26+
return $app->redirect($app['url_generator']->generate('home'));
27+
})->bind('login');
28+
29+
$app = (new Stack\Builder())
30+
->push('Dflydev\Stack\BasicAuthentication', [
31+
'firewalls' => [
32+
['path' => '/', 'anonymous' => true],
33+
['path' => '/login'],
34+
],
35+
'authenticator' => function ($username, $password) {
36+
if ('admin' === $username && 'default' === $password) {
37+
return 'admin-user-token';
38+
}
39+
}
40+
])
41+
->resolve($app);
42+
43+
$request = Request::createFromGlobals();
44+
$response = $app->handle($request)->send();
45+
$app->terminate($request, $response);

0 commit comments

Comments
 (0)