1
|
|
|
<?php |
2
|
|
|
namespace Tpg\ExtjsBundle\Twig; |
3
|
|
|
|
4
|
|
|
class ExtjsExtension extends \Twig_Extension { |
5
|
|
|
|
6
|
|
|
protected $generator; |
7
|
|
|
protected $router; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* DI for ExtJS Generator |
11
|
|
|
* @param $generator |
12
|
|
|
*/ |
13
|
3 |
|
public function setGenerator($generator) { |
14
|
3 |
|
$this->generator = $generator; |
15
|
3 |
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* DI for Router |
19
|
|
|
* @param $router |
20
|
|
|
*/ |
21
|
3 |
|
public function setRouter($router) { |
22
|
3 |
|
$this->router = $router; |
23
|
3 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Returns the name of the extension. |
27
|
|
|
* |
28
|
|
|
* @return string The extension name |
29
|
|
|
*/ |
30
|
3 |
|
public function getName() |
31
|
|
|
{ |
32
|
3 |
|
return 'extjs'; |
33
|
|
|
} |
34
|
|
|
|
35
|
2 |
|
public function getFilters() { |
36
|
|
|
return array( |
37
|
2 |
|
new \Twig_SimpleFilter('ucfirst', array($this, 'ucfirst')), |
38
|
2 |
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
2 |
|
public function getFunctions() |
42
|
|
|
{ |
43
|
|
|
return array( |
44
|
2 |
|
new \Twig_SimpleFunction('extjs_model', array($this, 'injectModel'), array('is_safe' => array('all'))), |
45
|
2 |
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Inject ExtJs Model into the DOM. |
50
|
|
|
* |
51
|
|
|
* @param boolean $injection Produce ExtJS model code on the page directly? |
|
|
|
|
52
|
|
|
* @param string $model Model Name. |
|
|
|
|
53
|
|
|
*/ |
54
|
2 |
|
public function injectModel() { |
55
|
2 |
|
$params = func_get_args(); |
56
|
2 |
|
$injection = array_shift($params); |
57
|
2 |
|
if ($injection == false) { |
58
|
1 |
|
$url = $this->router->generate('extjs_generate_model', array('model'=>$params), false); |
59
|
1 |
|
return "<script type='text/javascript' src='$url'></script>"; |
60
|
|
|
} else { |
61
|
1 |
|
$code = ''; |
62
|
1 |
|
foreach ($params as $model) { |
63
|
1 |
|
$model = str_replace(".", "\\", $model); |
64
|
1 |
|
$code .= $this->generator->generateMarkupForEntity($model); |
65
|
1 |
|
} |
66
|
1 |
|
return $code; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function ucfirst($string) { |
71
|
|
|
return ucfirst($string); |
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
} |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.