1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Decorator.php |
4
|
|
|
* |
5
|
|
|
* @copyright More in license.md |
6
|
|
|
* @license https://www.ipublikuj.eu |
7
|
|
|
* @author Adam Kadlec <[email protected]> |
8
|
|
|
* @package iPublikuj:Widgets! |
9
|
|
|
* @subpackage Decorators |
10
|
|
|
* @since 1.0.0 |
11
|
|
|
* |
12
|
|
|
* @date 18.06.15 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types = 1); |
16
|
|
|
|
17
|
|
|
namespace IPub\Widgets\Decorators; |
18
|
|
|
|
19
|
|
|
use Nette\Application; |
20
|
|
|
use Nette\Bridges; |
21
|
|
|
use Nette\Localization; |
22
|
|
|
|
23
|
|
|
use IPub\Widgets; |
24
|
|
|
use IPub\Widgets\Decorators; |
25
|
|
|
use IPub\Widgets\Exceptions; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Widgets base decorator control definition |
29
|
|
|
* |
30
|
|
|
* @package iPublikuj:Widgets! |
31
|
|
|
* @subpackage Decorators |
32
|
|
|
* |
33
|
|
|
* @author Adam Kadlec <[email protected]> |
34
|
|
|
* |
35
|
|
|
* @property Application\UI\ITemplate $template |
36
|
|
|
*/ |
37
|
1 |
|
abstract class Decorator extends Widgets\Application\UI\BaseControl implements Decorators\IDecorator |
38
|
|
|
{ |
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
public function render(Widgets\Widgets\IWidget $widget) : void |
43
|
|
|
{ |
44
|
|
|
// Check if control has template |
45
|
|
|
if ($this->template instanceof Bridges\ApplicationLatte\Template) { |
|
|
|
|
46
|
|
|
// Assign vars to template |
47
|
|
|
$this->template->widget = $widget; |
48
|
|
|
|
49
|
|
|
// Check if translator is available |
50
|
|
|
if ($this->getTranslator() instanceof Localization\ITranslator) { |
|
|
|
|
51
|
|
|
$this->template->setTranslator($this->getTranslator()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// If template was not defined before... |
55
|
|
|
if ($this->template->getFile() === NULL) { |
56
|
|
|
// Get component actual dir |
57
|
|
|
$dir = dirname($this->getReflection()->getFileName()); |
58
|
|
|
|
59
|
|
|
// ...try to get base component template file |
60
|
|
|
$templateFile = $this->templateFile !== NULL && is_file($this->templateFile) ? $this->templateFile : $dir . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . 'default.latte'; |
61
|
|
|
$this->template->setFile($templateFile); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// Render component template |
65
|
|
|
$this->template->render(); |
66
|
|
|
|
67
|
|
|
} else { |
68
|
|
|
throw new Exceptions\InvalidStateException('Widgets decorator control is without template.'); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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.