diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index 2262fd61a8..326a91ad9f 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -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', diff --git a/lib/Alchemy/Phrasea/Controller/Admin/SetupController.php b/lib/Alchemy/Phrasea/Controller/Admin/SetupController.php new file mode 100644 index 0000000000..bab5d26ed1 --- /dev/null +++ b/lib/Alchemy/Phrasea/Controller/Admin/SetupController.php @@ -0,0 +1,38 @@ +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(), + ]); + } +} diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Setup.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Setup.php index 58694a7287..3767efc1f8 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Setup.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Setup.php @@ -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(), - ]); - } }