-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasePresenter.php
More file actions
54 lines (43 loc) · 1.62 KB
/
Copy pathBasePresenter.php
File metadata and controls
54 lines (43 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace ADT\Application;
use Exception;
use Nette\Application\UI\Presenter;
use Nette\Localization\Translator;
use stdClass;
abstract class BasePresenter extends Presenter
{
abstract protected function getTranslator(): Translator;
const DEFAULT_AUTO_CLOSE_DURATION = 3000;
public array $allowedMethods = ['GET', 'POST', 'HEAD'];
/**
* @throws Exception
*/
public function flashMessage($message, string $type = 'info'): stdClass
{
throw new Exception('Use one of flashMessageError / flashMessageWarning / flashMessageSuccess / flashMessageInfo method instead.');
}
public function flashMessageError(string $message, ?int $autoCloseDuration = null): stdClass
{
return $this->flashMessageCommon($message, 'danger', $autoCloseDuration);
}
public function flashMessageWarning(string $message, ?int $autoCloseDuration = null): stdClass
{
return $this->flashMessageCommon($message, 'warning', $autoCloseDuration);
}
public function flashMessageSuccess(string $message, ?int $autoCloseDuration = null): stdClass
{
return $this->flashMessageCommon($message, 'success', $autoCloseDuration);
}
public function flashMessageInfo(string $message, ?int $autoCloseDuration = null): stdClass
{
return $this->flashMessageCommon($message, 'info', $autoCloseDuration);
}
/** @internal */
private function flashMessageCommon(string $message, string $type, ?int $autoCloseDuration = null): stdClass
{
$this->redrawControl('flashes');
$flash = parent::flashMessage($this->getTranslator()->translate($message), $type);
$flash->closeDuration = $autoCloseDuration ?? self::DEFAULT_AUTO_CLOSE_DURATION;
return $flash;
}
}