Refactor Admin/SetupController

This commit is contained in:
Benoît Burnichon
2015-04-13 18:03:37 +02:00
parent 6d4fcbbe9a
commit 9b96e96e04
3 changed files with 64 additions and 28 deletions

View File

@@ -312,6 +312,7 @@ class Application extends SilexApplication
'Alchemy\Phrasea\ControllerProvider\Admin\Fields' => [],
'Alchemy\Phrasea\ControllerProvider\Admin\Root' => [],
'Alchemy\Phrasea\ControllerProvider\Admin\SearchEngine' => [],
'Alchemy\Phrasea\ControllerProvider\Admin\Setup' => [],
'Alchemy\Phrasea\ControllerProvider\Admin\Users' => [],
'Alchemy\Phrasea\ControllerProvider\Datafiles' => [],
'Alchemy\Phrasea\ControllerProvider\Lightbox' => [],
@@ -622,7 +623,6 @@ class Application extends SilexApplication
$this->mount('/login/', new Login());
$this->mount('/developers/', new Developers());
$this->mount('/admin/setup', new Setup());
$this->mount('/admin/task-manager', new TaskManager());
$this->mount('/admin/subdefs', new Subdefs());
@@ -676,6 +676,7 @@ class Application extends SilexApplication
'/admin/fields' => 'Alchemy\Phrasea\ControllerProvider\Admin\Fields',
'/admin/publications' => 'Alchemy\Phrasea\ControllerProvider\Admin\Feeds',
'/admin/search-engine' => 'Alchemy\Phrasea\ControllerProvider\Admin\SearchEngine',
'/admin/setup' => 'Alchemy\Phrasea\ControllerProvider\Admin\Setup',
'/admin/users' => 'Alchemy\Phrasea\ControllerProvider\Admin\Users',
'/datafiles' => 'Alchemy\Phrasea\ControllerProvider\Datafiles',
'/include/minify' => 'Alchemy\Phrasea\ControllerProvider\Minifier',

View File

@@ -0,0 +1,38 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2015 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Core\Configuration\RegistryManipulator;
use Symfony\Component\HttpFoundation\Request;
class SetupController extends Controller
{
public function submitGlobalsAction(Request $request)
{
/** @var RegistryManipulator $manipulator */
$manipulator = $this->app['registry.manipulator'];
$form = $manipulator->createForm($this->app['conf']);
if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {
$this->app['conf']->set('registry', $manipulator->getRegistryData($form));
return $this->app->redirectPath('setup_display_globals');
}
}
return $this->render('admin/setup.html.twig', [
'form' => $form->createView(),
]);
}
}

View File

@@ -11,45 +11,42 @@
namespace Alchemy\Phrasea\ControllerProvider\Admin;
use Alchemy\Phrasea\Application;
use Silex\Application as SilexApplication;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\Admin\SetupController;
use Alchemy\Phrasea\Security\Firewall;
use Silex\Application;
use Silex\ControllerCollection;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Silex\ServiceProviderInterface;
class Setup implements ControllerProviderInterface
class Setup implements ControllerProviderInterface, ServiceProviderInterface
{
public function connect(SilexApplication $app)
public function register(Application $app)
{
$app['controller.admin.setup'] = $this;
$app['controller.admin.setup'] = $app->share(function (PhraseaApplication $app) {
return new SetupController($app);
});
}
public function boot(Application $app)
{
}
public function connect(Application $app)
{
/** @var ControllerCollection $controllers */
$controllers = $app['controllers_factory'];
$controllers->before(function (Request $request) use ($app) {
$app['firewall']->requireAdmin();
/** @var Firewall $firewall */
$firewall = $app['firewall'];
$controllers->before(function () use ($firewall) {
$firewall->requireAdmin();
});
$controllers->match('/', 'controller.admin.setup:getGlobals')
$controllers->match('/', 'controller.admin.setup:submitGlobalsAction')
->bind('setup_display_globals')
->method('GET|POST');
return $controllers;
}
public function getGlobals(Application $app, Request $request)
{
$form = $app['registry.manipulator']->createForm($app['conf']);
if ('POST' === $request->getMethod()) {
$form->bind($request);
if ($form->isValid()) {
$app['conf']->set('registry', $app['registry.manipulator']->getRegistryData($form));
return $app->redirectPath('setup_display_globals');
}
}
return $app['twig']->render('admin/setup.html.twig', [
'form' => $form->createView(),
]);
}
}