These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\AdminListBundle\Twig; |
||
4 | |||
5 | use Kunstmaan\AdminListBundle\AdminList\AdminList; |
||
6 | use Kunstmaan\AdminListBundle\Service\ExportService; |
||
7 | use Twig\Environment; |
||
8 | use Twig\Error\LoaderError; |
||
9 | use Twig\Error\RuntimeError; |
||
10 | use Twig\Error\SyntaxError; |
||
11 | use Twig\Extension\AbstractExtension; |
||
12 | use Twig\TwigFunction; |
||
13 | use Twig\TwigTest; |
||
14 | |||
15 | /** |
||
16 | * AdminListTwigExtension |
||
17 | * |
||
18 | * @final since 5.4 |
||
19 | */ |
||
20 | class AdminListTwigExtension extends AbstractExtension |
||
21 | { |
||
22 | /** |
||
23 | * Returns a list of functions to add to the existing list. |
||
24 | * |
||
25 | * @return array An array of functions |
||
0 ignored issues
–
show
|
|||
26 | */ |
||
27 | View Code Duplication | public function getFunctions() |
|
28 | { |
||
29 | return [ |
||
30 | new TwigFunction('adminlist_widget', [$this, 'renderWidget'], ['needs_environment' => true, 'is_safe' => ['html']]), |
||
31 | new TwigFunction('adminthumb_widget', [$this, 'renderThumbWidget'], ['needs_environment' => true, 'is_safe' => ['html']]), |
||
32 | new TwigFunction('supported_export_extensions', [$this, 'getSupportedExtensions']), |
||
33 | ]; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function getTests() |
||
40 | { |
||
41 | return [ |
||
42 | new TwigTest('instanceof', [$this, 'isInstanceOf']), |
||
43 | ]; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param object $object |
||
48 | * @param string $class |
||
49 | * |
||
50 | * @return bool |
||
51 | */ |
||
52 | public function isInstanceOf($object, $class) |
||
53 | { |
||
54 | return $object instanceof $class; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Renders the HTML for a given view |
||
59 | * |
||
60 | * Example usage in Twig: |
||
61 | * |
||
62 | * {{ form_widget(view) }} |
||
63 | * |
||
64 | * You can pass options during the call: |
||
65 | * |
||
66 | * {{ form_widget(view, {'attr': {'class': 'foo'}}) }} |
||
67 | * |
||
68 | * {{ form_widget(view, {'separator': '+++++'}) }} |
||
69 | * |
||
70 | * @param Environment $env |
||
71 | * @param AdminList $view The view to render |
||
72 | * @param string $basepath The base path |
||
73 | * @param array $urlparams Additional url params |
||
74 | * @param array $addparams Add params |
||
75 | * |
||
76 | * @return string The html markup |
||
77 | * |
||
78 | * @throws \Throwable |
||
79 | * @throws LoaderError |
||
80 | * @throws RuntimeError |
||
81 | * @throws SyntaxError |
||
82 | */ |
||
83 | View Code Duplication | public function renderWidget(Environment $env, AdminList $view, $basepath, array $urlparams = [], array $addparams = []) |
|
84 | { |
||
85 | $filterBuilder = $view->getFilterBuilder(); |
||
86 | |||
87 | return $env->render( |
||
88 | '@KunstmaanAdminList/AdminListTwigExtension/widget.html.twig', |
||
89 | [ |
||
90 | 'filter' => $filterBuilder, |
||
91 | 'basepath' => $basepath, |
||
92 | 'addparams' => $addparams, |
||
93 | 'extraparams' => $urlparams, |
||
94 | 'adminlist' => $view, |
||
95 | ] |
||
96 | ); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Renders the HTML for a given view |
||
101 | * |
||
102 | * Example usage in Twig: |
||
103 | * |
||
104 | * {{ form_widget(view) }} |
||
105 | * |
||
106 | * You can pass options during the call: |
||
107 | * |
||
108 | * {{ form_widget(view, {'attr': {'class': 'foo'}}) }} |
||
109 | * |
||
110 | * {{ form_widget(view, {'separator': '+++++'}) }} |
||
111 | * |
||
112 | * @param Environment $env |
||
113 | * @param AdminList $view The view to render |
||
114 | * @param string $basepath The base path |
||
115 | * @param array $urlparams Additional url params |
||
116 | * @param array $addparams Add params |
||
117 | * |
||
118 | * @return string The html markup |
||
119 | * |
||
120 | * @throws \Throwable |
||
121 | * @throws LoaderError |
||
122 | * @throws RuntimeError |
||
123 | * @throws SyntaxError |
||
124 | */ |
||
125 | View Code Duplication | public function renderThumbWidget(Environment $env, AdminList $view, $basepath, array $urlparams = [], array $addparams = []) |
|
126 | { |
||
127 | $filterBuilder = $view->getFilterBuilder(); |
||
128 | |||
129 | return $env->render( |
||
130 | '@KunstmaanAdminList/AdminListTwigExtension/thumbwidget.html.twig', |
||
131 | [ |
||
132 | 'filter' => $filterBuilder, |
||
133 | 'basepath' => $basepath, |
||
134 | 'addparams' => $addparams, |
||
135 | 'extraparams' => $urlparams, |
||
136 | 'adminlist' => $view, |
||
137 | ] |
||
138 | ); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * @return array |
||
143 | */ |
||
144 | public function getSupportedExtensions() |
||
145 | { |
||
146 | return ExportService::getSupportedExtensions(); |
||
147 | } |
||
148 | } |
||
149 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.