1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* BaseControl.php |
4
|
|
|
* |
5
|
|
|
* @copyright Vice v copyright.php |
6
|
|
|
* @license http://www.ipublikuj.eu |
7
|
|
|
* @author Adam Kadlec http://www.ipublikuj.eu |
8
|
|
|
* @package iPublikuj:Widgets! |
9
|
|
|
* @subpackage Application |
10
|
|
|
* @since 1.0.0 |
11
|
|
|
* |
12
|
|
|
* @date 24.07.13 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types = 1); |
16
|
|
|
|
17
|
|
|
namespace IPub\Widgets\Application\UI; |
18
|
|
|
|
19
|
|
|
use Nette; |
20
|
|
|
use Nette\Application; |
21
|
|
|
use Nette\Localization; |
22
|
|
|
|
23
|
|
|
use IPub; |
24
|
|
|
use IPub\Widgets\Exceptions; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Extensions base control definition |
28
|
|
|
* |
29
|
|
|
* @package iPublikuj:Widgets! |
30
|
|
|
* @subpackage Application |
31
|
|
|
* |
32
|
|
|
* @author Adam Kadlec <[email protected]> |
33
|
|
|
* |
34
|
|
|
* @property Application\UI\ITemplate $template |
35
|
|
|
*/ |
36
|
1 |
|
abstract class BaseControl extends Application\UI\Control |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $templateFile; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var Localization\ITranslator |
45
|
|
|
*/ |
46
|
|
|
protected $translator; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param Localization\ITranslator $translator |
50
|
|
|
*/ |
51
|
|
|
public function injectTranslator(Localization\ITranslator $translator = NULL) |
52
|
|
|
{ |
53
|
|
|
$this->translator = $translator; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Change default control template path |
58
|
|
|
* |
59
|
|
|
* @param string $templateFile |
60
|
|
|
* |
61
|
|
|
* @throws Exceptions\FileNotFoundException |
62
|
|
|
*/ |
63
|
|
|
public function setTemplateFile($templateFile) |
64
|
|
|
{ |
65
|
|
|
// Check if template file exists... |
66
|
|
|
if (!is_file($templateFile)) { |
67
|
|
|
// Get component actual dir |
68
|
|
|
$dir = dirname($this->getReflection()->getFileName()); |
69
|
|
|
|
70
|
|
|
// ...check if extension template is used |
71
|
|
|
if (is_file($dir . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $templateFile)) { |
72
|
|
|
$templateFile = $dir . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $templateFile; |
73
|
|
|
|
74
|
|
|
} else if (is_file($dir . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $templateFile . '.latte')) { |
75
|
|
|
$templateFile = $dir . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $templateFile . '.latte'; |
76
|
|
|
|
77
|
|
|
} else { |
78
|
|
|
// ...if not throw exception |
79
|
|
|
throw new Exceptions\FileNotFoundException(sprintf('Template file "%s" was not found.', $templateFile)); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$this->templateFile = $templateFile; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param Localization\ITranslator $translator |
88
|
|
|
*/ |
89
|
|
|
public function setTranslator(Localization\ITranslator $translator) |
90
|
|
|
{ |
91
|
|
|
$this->translator = $translator; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return Localization\ITranslator|NULL |
96
|
|
|
*/ |
97
|
|
|
public function getTranslator() |
98
|
|
|
{ |
99
|
|
|
if ($this->translator instanceof Localization\ITranslator) { |
100
|
|
|
return $this->translator; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return NULL; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|