|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Routes. |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Zikula contributors (Zikula) |
|
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
7
|
|
|
* @author Zikula contributors <[email protected]>. |
|
8
|
|
|
* @link http://www.zikula.org |
|
9
|
|
|
* @link http://zikula.org |
|
10
|
|
|
* @version Generated by ModuleStudio 0.7.1 (http://modulestudio.de). |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Zikula\RoutesModule\Controller\Base; |
|
14
|
|
|
|
|
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
16
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
|
17
|
|
|
use Zikula\Core\Controller\AbstractController; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Config controller base class. |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class AbstractConfigController extends AbstractController |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* This method takes care of the application configuration. |
|
26
|
|
|
* |
|
27
|
|
|
* @param Request $request Current request instance |
|
28
|
|
|
* |
|
29
|
|
|
* @return string Output |
|
30
|
|
|
* |
|
31
|
|
|
* @throws AccessDeniedException Thrown if the user doesn't have required permissions |
|
32
|
|
|
*/ |
|
33
|
|
|
public function configAction(Request $request) |
|
34
|
|
|
{ |
|
35
|
|
|
if (!$this->hasPermission($this->name . '::', '::', ACCESS_ADMIN)) { |
|
36
|
|
|
throw new AccessDeniedException(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$form = $this->createForm('Zikula\RoutesModule\Form\AppSettingsType'); |
|
40
|
|
|
|
|
41
|
|
|
if ($form->handleRequest($request)->isValid()) { |
|
42
|
|
|
if ($form->get('save')->isClicked()) { |
|
|
|
|
|
|
43
|
|
|
$this->setVars($form->getData()); |
|
44
|
|
|
|
|
45
|
|
|
$this->addFlash('status', $this->__('Done! Module configuration updated.')); |
|
46
|
|
|
$userName = $this->get('zikula_users_module.current_user')->get('uname'); |
|
47
|
|
|
$this->get('logger')->notice('{app}: User {user} updated the configuration.', ['app' => 'ZikulaRoutesModule', 'user' => $userName]); |
|
48
|
|
|
} elseif ($form->get('cancel')->isClicked()) { |
|
|
|
|
|
|
49
|
|
|
$this->addFlash('status', $this->__('Operation cancelled.')); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
// redirect to config page again (to show with GET request) |
|
53
|
|
|
return $this->redirectToRoute('zikularoutesmodule_config_config'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$templateParameters = [ |
|
57
|
|
|
'form' => $form->createView() |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
|
|
// render the config form |
|
61
|
|
|
return $this->render('@ZikulaRoutesModule/Config/config.html.twig', $templateParameters); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: