|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Copyright 2011 Johannes M. Schmitt <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace TwigJs\Compiler; |
|
20
|
|
|
|
|
21
|
|
|
use TwigJs\JsCompiler; |
|
22
|
|
|
use TwigJs\TypeCompilerInterface; |
|
23
|
|
|
|
|
24
|
|
|
class IncludeCompiler implements TypeCompilerInterface |
|
25
|
|
|
{ |
|
26
|
|
|
public function getType() |
|
27
|
|
|
{ |
|
28
|
|
|
return 'Twig_Node_Include'; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function compile(JsCompiler $compiler, \Twig_NodeInterface $node) |
|
32
|
|
|
{ |
|
33
|
|
|
if (!$node instanceof \Twig_Node_Include) { |
|
34
|
|
|
throw new \RuntimeException( |
|
35
|
|
|
sprintf( |
|
36
|
|
|
'$node must be an instanceof of \Include, but got "%s".', |
|
37
|
|
|
get_class($node) |
|
38
|
|
|
) |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$compiler->addDebugInfo($node); |
|
43
|
|
|
|
|
44
|
|
|
$compiler->isTemplateName = true; |
|
45
|
|
View Code Duplication |
if ($node->getNode('expr') instanceof Twig_Node_Expression_Constant) { |
|
|
|
|
|
|
46
|
|
|
$compiler |
|
47
|
|
|
->write("(new ") |
|
48
|
|
|
->subcompile($node->getNode('expr')) |
|
49
|
|
|
->raw("(this.env_)).render_(sb, ") |
|
50
|
|
|
; |
|
51
|
|
|
} else { |
|
52
|
|
|
$compiler |
|
53
|
|
|
->write("(new ") |
|
54
|
|
|
->subcompile($node->getNode('expr')) |
|
55
|
|
|
->raw("(this.env_)).render_(sb, ") |
|
56
|
|
|
; |
|
57
|
|
|
} |
|
58
|
|
|
$compiler->isTemplateName = false; |
|
59
|
|
|
|
|
60
|
|
|
if (false === $node->getAttribute('only')) { |
|
61
|
|
|
if (!$this->hasVariablesNode($node)) { |
|
62
|
|
|
$compiler->raw('context'); |
|
63
|
|
|
} else { |
|
64
|
|
|
$compiler |
|
65
|
|
|
->raw('twig.extend({}, context, ') |
|
66
|
|
|
->subcompile($node->getNode('variables')) |
|
67
|
|
|
->raw(')') |
|
68
|
|
|
; |
|
69
|
|
|
} |
|
70
|
|
|
} else { |
|
71
|
|
|
if (!$node->hasNode('variables')) { |
|
72
|
|
|
$compiler->raw('{}'); |
|
73
|
|
|
} else { |
|
74
|
|
|
$compiler->subcompile($node->getNode('variables')); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$compiler->raw(");\n"); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
View Code Duplication |
private function hasVariablesNode(\Twig_NodeInterface $node) |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
if (!$node->hasNode('variables')) { |
|
84
|
|
|
return false; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
if (null === $node->getNode('variables')) { |
|
|
|
|
|
|
88
|
|
|
return false; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return true; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto 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
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.