Skip to content

Instantly share code, notes, and snippets.

@jamiehollern
Forked from drefined/app.php
Created June 22, 2017 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiehollern/6cdc6aba4ce20e04ecf93183c85f8a9f to your computer and use it in GitHub Desktop.
Save jamiehollern/6cdc6aba4ce20e04ecf93183c85f8a9f to your computer and use it in GitHub Desktop.
This is the simple silex app.
<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\SecurityServiceProvider());
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => dirname(__DIR__) . '/src/views'
));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app['security.firewalls'] = array(
'admin' => array(
'pattern' => '^/admin/?',
'form' => array('login_path' => '/login', 'check_path' => '/admin/login_check'),
'logout' => array('logout_path' => '/logout'),
'users' => array(
'admin' => array('ROLE_ADMIN', '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg=='),
),
),
);
$app->get('/', function(Request $request) use ($app) {
return new Response('index', 200);
});
$app->get('/admin', function(Request $request) use ($app) {
return new Response('admin', 200);
});
$app->get('/logout', function() use ($app) {
return new Response('logout', 200);
});
$app->get('/login', function(Request $request) use ($app) {
return $app['twig']->render('login.twig', array(
'error' => $app['security.last_error']($request),
'last_username' => $app['session']->get('_security.last_username'),
));
});
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment