我目前正在开发Silex框架下的应用程序。我想使用一个身份验证系统,但我是这个框架的新手,即使我要在文档中潜入好几天,我仍然不了解所有内容......
我的申请非常基本。 root是一个连接页面,用户必须连接,然后根据它们在MYSQL数据库上的类型(3类型用户)重定向到3页中的一个,因此,在/home.
Composer.json
{
"name": "fabpot/silex-skeleton",
"description": "A pre-configured skeleton for the Silex microframework",
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"silex/silex": "~2.0",
"silex/web-profiler": "~2.0",
"symfony/asset": "~2.8|^3.0",
"symfony/browser-kit": "~2.8|^3.0",
"symfony/class-loader": "~2.8|^3.0",
"symfony/config": "~2.8|^3.0",
"symfony/console": "~2.8|^3.0",
"symfony/css-selector": "~2.8|^3.0",
"symfony/debug": "~2.8|^3.0",
"symfony/finder": "~2.8|^3.0",
"symfony/form": "~2.8|^3.0",
"symfony/monolog-bridge": "~2.8|^3.0",
"symfony/process": "~2.8|^3.0",
"symfony/security": "~2.8|^3.0",
"symfony/translation": "~2.8|^3.0",
"symfony/twig-bridge": "~2.8|^3.0",
"symfony/validator": "~2.8|^3.0",
"doctrine/dbal": "~2.2"
},
"autoload": {
"psr-0": { "": "src/" }
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"scripts": {
"run": [
"echo 'Started web server on http://localhost:8888'",
"php -S localhost:8888 -t web"
]
}
}
App.php
<?php
use Silex\Application;
use Silex\Provider\AssetServiceProvider;
use Silex\Provider\TwigServiceProvider;
use Silex\Provider\ServiceControllerServiceProvider;
use Silex\Provider\HttpFragmentServiceProvider;
$app = new Application();
$app->register(new ServiceControllerServiceProvider());
$app->register(new AssetServiceProvider());
$app->register(new TwigServiceProvider());
$app->register(new HttpFragmentServiceProvider());
$app['twig'] = $app->extend('twig', function ($twig, $app) {
// add custom globals, filters, tags, ...
return $twig;
});
return $app;
?>
Controllers.php
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
//Request::setTrustedProxies(array('127.0.0.1'));
# Configuration Database
require '../web/php/bd.php';
# DAO
require '../web/model/DAO/UtilisateurDAO.php';
require '../web/model/DAO/QuestionDAO.php';
require '../web/model/DAO/PartieDAO.php';
require '../web/model/DAO/ScenarioDAO.php';
require '../web/model/DAO/RessourceDAO.php';
require '../web/model/DAO/ReponseDAO.php';
require '../web/model/DAO/SiteDAO.php';
# DTO
require '../web/model/DTO/UtilisateurDTO.php';
require '../web/model/DTO/QuestionDTO.php';
require '../web/model/DTO/PartieDTO.php';
require '../web/model/DTO/ScenarioDTO.php';
require '../web/model/DTO/RessourceDTO.php';
require '../web/model/DTO/ReponseDTO.php';
require '../web/model/DTO/SiteDTO.php';
$app->register(new Silex\Provider\SessionServiceProvider());
$app->before(function ($request) {
$request->getSession()->start();
});
$app->get('/', function (Request $request) use ($app) {
return $app['twig']->render('index.html.twig', array());
});
$app->post('/accueil', function (Request $request) use ($app) {
# Some Code...
switch () {
case '#':
return $app['twig']->render('accueil_joueur.html.twig', array());
break;
case 'Admin':
return $app['twig']->render('accueil_admin.html.twig', array());
break;
case 'Jury':
return $app['twig']->render('accueil_jury.html.twig', array());
break;
default:
return $app->redirect('/');
break;
}
});
$app->error(function (\Exception $e, Request $request, $code) use ($app) {
if ($app['debug']) {
return;
}
// 404.html, or 40x.html, or 4xx.html, or error.html
$templates = array(
'errors/'.$code.'.html.twig',
'errors/'.substr($code, 0, 2).'x.html.twig',
'errors/'.substr($code, 0, 1).'xx.html.twig',
'errors/default.html.twig',
);
return new Response($app['twig']->resolveTemplate($templates)->render(array('code' => $code)), $code);
});
从哪里开始利用Silex提出的SecurityServiceProvider系统?
问候。