1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* BaseControl.php |
4
|
|
|
* |
5
|
|
|
* @copyright Vice v copyright.php |
6
|
|
|
* @license https://www.ipublikuj.eu |
7
|
|
|
* @author Adam Kadlec <[email protected]> |
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\Application; |
20
|
|
|
use Nette\Localization; |
21
|
|
|
|
22
|
|
|
use IPub\Widgets\Exceptions; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Extensions base control definition |
26
|
|
|
* |
27
|
|
|
* @package iPublikuj:Widgets! |
28
|
|
|
* @subpackage Application |
29
|
|
|
* |
30
|
|
|
* @author Adam Kadlec <[email protected]> |
31
|
|
|
* |
32
|
|
|
* @property Application\UI\ITemplate $template |
33
|
|
|
*/ |
34
|
1 |
|
abstract class BaseControl extends Application\UI\Control |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $templateFile; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var Localization\ITranslator |
43
|
|
|
*/ |
44
|
|
|
protected $translator; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param Localization\ITranslator $translator |
48
|
|
|
* |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
|
|
public function injectTranslator(Localization\ITranslator $translator = NULL) : void |
52
|
|
|
{ |
53
|
|
|
$this->translator = $translator; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Change default control template path |
58
|
|
|
* |
59
|
|
|
* @param string $templateFile |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
* |
63
|
|
|
* @throws Exceptions\FileNotFoundException |
64
|
|
|
*/ |
65
|
|
|
public function setTemplateFile($templateFile) : void |
66
|
|
|
{ |
67
|
|
|
// Check if template file exists... |
68
|
|
|
if (!is_file($templateFile)) { |
69
|
|
|
// Get component actual dir |
70
|
|
|
$dir = dirname($this->getReflection()->getFileName()); |
71
|
|
|
|
72
|
|
|
// ...check if extension template is used |
73
|
|
|
if (is_file($dir . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $templateFile)) { |
74
|
|
|
$templateFile = $dir . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $templateFile; |
75
|
|
|
|
76
|
|
|
} else if (is_file($dir . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $templateFile . '.latte')) { |
77
|
|
|
$templateFile = $dir . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $templateFile . '.latte'; |
78
|
|
|
|
79
|
|
|
} else { |
80
|
|
|
// ...if not throw exception |
81
|
|
|
throw new Exceptions\FileNotFoundException(sprintf('Template file "%s" was not found.', $templateFile)); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$this->templateFile = $templateFile; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param Localization\ITranslator $translator |
90
|
|
|
*/ |
91
|
|
|
public function setTranslator(Localization\ITranslator $translator) : void |
92
|
|
|
{ |
93
|
|
|
$this->translator = $translator; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return Localization\ITranslator|NULL |
98
|
|
|
*/ |
99
|
|
|
public function getTranslator() : ?Localization\ITranslator |
100
|
|
|
{ |
101
|
|
|
if ($this->translator instanceof Localization\ITranslator) { |
|
|
|
|
102
|
|
|
return $this->translator; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
return NULL; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.