|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace UniMan\Presenters; |
|
4
|
|
|
|
|
5
|
|
|
use UniMan\Components\DatabaseSelect\DatabaseSelectControl; |
|
6
|
|
|
use UniMan\Core\Exception\ConnectException; |
|
7
|
|
|
use Nette\Application\BadRequestException; |
|
8
|
|
|
|
|
9
|
|
|
abstract class BasePresenter extends AbstractBasePresenter |
|
10
|
|
|
{ |
|
11
|
|
|
protected function startup() |
|
12
|
|
|
{ |
|
13
|
|
|
parent::startup(); |
|
14
|
|
|
$drivers = $this->driverStorage->getDrivers(); |
|
15
|
|
|
$actualDriver = isset($this->params['driver']) ? $this->params['driver'] : current(array_keys($drivers)); |
|
16
|
|
|
|
|
17
|
|
|
$this->template->driver = $actualDriver; |
|
18
|
|
|
$this->driver = $this->driverStorage->getDriver($actualDriver); |
|
19
|
|
|
if (!$this->driver) { |
|
20
|
|
|
throw new BadRequestException('Driver "' . $actualDriver . '" not found'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
$credentials = $this->credentialsStorage->getCredentials($actualDriver); |
|
24
|
|
|
if (!$credentials) { |
|
|
|
|
|
|
25
|
|
|
$this->redirect('Default:default', $actualDriver); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
foreach ($this->driver->defaultCredentials() as $key => $defaultCredential) { |
|
29
|
|
|
$credentials[$key] = $credentials[$key] ?: $defaultCredential; |
|
30
|
|
|
} |
|
31
|
|
|
try { |
|
32
|
|
|
$this->driver->connect($credentials); |
|
33
|
|
|
if (isset($this->params['database'])) { |
|
34
|
|
|
$this->driver->dataManager()->selectDatabase($this->params['database']); |
|
35
|
|
|
} |
|
36
|
|
|
} catch (ConnectException $e) { |
|
37
|
|
|
$this->flashMessage($e->getMessage(), 'danger'); |
|
38
|
|
|
$this->redirect('Default:default', $actualDriver); |
|
39
|
|
|
} |
|
40
|
|
|
$this->template->actualDriver = $this->driver; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
protected function createComponentDatabaseSelect() |
|
44
|
|
|
{ |
|
45
|
|
|
return new DatabaseSelectControl($this->driver, $this->translator, $this->database); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.