/** * @param array $values */ public function __construct(array $values = []) { parent::__construct($values); $this['debug'] = false; $this['app.cache.dir'] = __DIR__ . '/../../var/cache'; $this['app.views.dir'] = __DIR__ . '/../../views'; $this['app.session'] = function () { return new Session(['cookie_lifetime' => 5 * 60], 5 * 60); }; $this['app.user'] = $this->factory(function ($app) { return $app['app.session']->getUser(); }); $this['api.provider.user'] = function ($app) { return new HttpBasicUserProvider($app['app.repository.user']); }; $this['api.user'] = $this->factory(function ($app) { return $this['api.provider.user']->getUser($app['app.request']); }); $this['twig.loader'] = function ($app) { return new \Twig_Loader_Filesystem($app['app.views.dir']); }; $this['twig'] = function ($app) { $twig = new \Twig_Environment($app['twig.loader'], ['debug' => $app['debug'], 'cache' => $this['app.cache.dir'] . '/twig']); return $twig; }; $this['app.repository.user'] = function () { return new UserRepository(); }; $this['app.controller.default'] = function ($app) { return new DefaultController($app); }; $this['app.controller.security'] = function ($app) { return new SecurityController($app); }; $this['app.controller.page'] = function ($app) { return new PageController($app); }; $this['app.controller.api.user'] = function ($app) { return new UserController($app); }; $this['api.response.negociator'] = function () { return new ResponseHandler(new Negotiator()); }; $this['app.firewall'] = function () { $firewall = new Firewall(); $firewall->addRoute([], '/page/1', 'ROLE_PAGE_1'); $firewall->addRoute([], '/page/2', 'ROLE_PAGE_2'); $firewall->addRoute([], '/page/3', 'ROLE_PAGE_3'); return $firewall; }; $this['api.firewall'] = function () { $firewall = new Firewall(); $firewall->addRoute('GET', '/api', 'ROLE_API_READ'); return $firewall; }; $this['app.router'] = function ($app) { return \FastRoute\simpleDispatcher(function (\FastRoute\RouteCollector $router) { $router->addRoute(['GET'], '/', ['default', 'index']); $router->addRoute(['GET', 'POST'], '/login', ['security', 'index']); $router->addRoute(['GET'], '/logout', ['security', 'logout']); $router->addRoute(['GET'], '/page/{page:[1-3]}', ['page', 'index']); $router->addRoute(['GET'], '/api/users', ['api.user', 'list']); $router->addRoute(['GET'], '/api/users/{name}', ['api.user', 'get']); $router->addRoute(['POST', 'PUT'], '/api/users/{name}', ['api.user', 'update']); $router->addRoute(['DELETE'], '/api/users/{name}', ['api.user', 'delete']); }, ['cacheFile' => $app['app.cache.dir'] . '/route', 'cacheDisabled' => $app['debug']]); }; }
public function testWithUserAccessForMethod() { $this->firewall->addRoute('POST', '/private', 'USER_2'); $this->assertFalse($this->firewall->isGranted('POST', '/private', $this->user)); $this->assertTrue($this->firewall->isGranted('GET', '/private', $this->user)); }