|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace UniMan\Presenters; |
|
4
|
|
|
|
|
5
|
|
|
use UniMan\Core\LoginForm; |
|
6
|
|
|
use Nette\Application\Responses\TextResponse; |
|
7
|
|
|
|
|
8
|
|
|
class DefaultPresenter extends AbstractBasePresenter |
|
9
|
|
|
{ |
|
10
|
|
|
public function actionDefault($driver = null) |
|
11
|
|
|
{ |
|
12
|
|
|
$actualDriver = $driver ?: current(array_keys($this->driverStorage->getDrivers())); |
|
13
|
|
|
$this->driver = $this->driverStorage->getDriver($actualDriver); |
|
14
|
|
|
$this->template->driver = $actualDriver; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function actionLogout($driver = null) |
|
18
|
|
|
{ |
|
19
|
|
|
$section = $this->getSession('uniman'); |
|
20
|
|
|
if ($driver) { |
|
21
|
|
|
unset($section->{$driver}); |
|
22
|
|
|
} else { |
|
23
|
|
|
$section->remove(); |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
$this->redirect('Default:default', $driver); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function actionFile($file) |
|
29
|
|
|
{ |
|
30
|
|
|
$httpResponse = $this->getHttpResponse(); |
|
31
|
|
|
$httpResponse->setHeader('Pragma', null); |
|
32
|
|
|
$httpResponse->setExpiration('+10 minutes'); |
|
33
|
|
|
$contentTypes = [ |
|
34
|
|
|
'css' => 'text/css', |
|
35
|
|
|
'js' => 'application/javascript', |
|
36
|
|
|
'jpg' => 'image/jpeg', |
|
37
|
|
|
'jpeg' => 'image/jpeg', |
|
38
|
|
|
'png' => 'image/png', |
|
39
|
|
|
'ico' => 'image/x-icon', |
|
40
|
|
|
'eot' => 'application/vnd.ms-fontobject', |
|
41
|
|
|
'woff' => 'application/font-woff', |
|
42
|
|
|
'woff2' => 'application/font-woff2', |
|
43
|
|
|
'ttf' => 'application/x-font-truetype', |
|
44
|
|
|
'svg' => 'image/svg+xml', |
|
45
|
|
|
'otf' => 'application/x-font-opentype', |
|
46
|
|
|
]; |
|
47
|
|
|
$path = __DIR__ . '/../../www/' . $file; |
|
48
|
|
|
$extension = pathinfo($path, PATHINFO_EXTENSION); |
|
49
|
|
|
$contentType = isset($contentTypes[$extension]) ? $contentTypes[$extension] : 'text/plain'; |
|
50
|
|
|
$httpResponse->setContentType($contentType); |
|
51
|
|
|
$this->sendResponse(new TextResponse(file_get_contents($path))); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function renderCheck() |
|
55
|
|
|
{ |
|
56
|
|
|
$drivers = $this->driverStorage->getDrivers(); |
|
57
|
|
|
$actualDriver = current(array_keys($drivers)); |
|
58
|
|
|
$this->driver = $this->driverStorage->getDriver($actualDriver); |
|
59
|
|
|
$this->template->driver = $actualDriver; |
|
60
|
|
|
$this->template->drivers = $drivers; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
protected function createComponentLoginForm() |
|
64
|
|
|
{ |
|
65
|
|
|
return new LoginForm($this->translator, $this->driverStorage, $this->credentialsStorage, $this->driver->type(), $this->locale); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: