|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
|
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerShop\Yves\ChartWidget\Plugin\Twig; |
|
9
|
|
|
|
|
10
|
|
|
use Spryker\Shared\Chart\Dependency\Plugin\ChartLayoutablePluginInterface; |
|
|
|
|
|
|
11
|
|
|
use Spryker\Shared\Chart\Dependency\Plugin\ChartPluginInterface; |
|
|
|
|
|
|
12
|
|
|
use Spryker\Shared\Chart\Dependency\Plugin\TwigChartFunctionPluginInterface; |
|
|
|
|
|
|
13
|
|
|
use Spryker\Yves\Kernel\AbstractPlugin; |
|
14
|
|
|
use Twig_Environment; |
|
|
|
|
|
|
15
|
|
|
use Twig_SimpleFunction; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @method \SprykerShop\Yves\ChartWidget\ChartWidgetFactory getFactory() |
|
19
|
|
|
* @method \SprykerShop\Yves\ChartWidget\ChartWidgetConfig getConfig() |
|
20
|
|
|
*/ |
|
21
|
|
|
abstract class AbstractTwigChartPlugin extends AbstractPlugin implements TwigChartFunctionPluginInterface |
|
22
|
|
|
{ |
|
23
|
|
|
public const TWIG_FUNCTION_NAME = 'chart'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @return string |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getName(): string |
|
29
|
|
|
{ |
|
30
|
|
|
return static::TWIG_FUNCTION_NAME; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return \Twig_SimpleFunction[] |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getChartFunctions(): array |
|
37
|
|
|
{ |
|
38
|
|
|
return [ |
|
39
|
|
|
new Twig_SimpleFunction( |
|
40
|
|
|
static::TWIG_FUNCTION_NAME, |
|
41
|
|
|
[$this, 'renderChart'], |
|
42
|
|
|
$this->getDefaultTwigOptions() |
|
43
|
|
|
), |
|
44
|
|
|
]; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param \Twig_Environment $twig |
|
49
|
|
|
* @param string $chartPluginName |
|
50
|
|
|
* @param string|null $dataIdentifier |
|
51
|
|
|
* |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
|
|
public function renderChart(Twig_Environment $twig, $chartPluginName, $dataIdentifier = null): string |
|
55
|
|
|
{ |
|
56
|
|
|
$context = $this->getChartContext($chartPluginName, $dataIdentifier); |
|
57
|
|
|
$rendered = $twig->render($this->getTemplateName(), $context); |
|
58
|
|
|
|
|
59
|
|
|
return $rendered; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
abstract protected function getTemplateName(): string; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param string $chartPluginName |
|
69
|
|
|
* @param string|null $dataIdentifier |
|
70
|
|
|
* |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function getChartContext($chartPluginName, $dataIdentifier): array |
|
74
|
|
|
{ |
|
75
|
|
|
$chartPlugin = $this->getChartPluginByName($chartPluginName); |
|
76
|
|
|
|
|
77
|
|
|
$context = [ |
|
78
|
|
|
'data' => $chartPlugin->getChartData($dataIdentifier), |
|
79
|
|
|
'layout' => $this->getConfig()->getDefaultChartLayout(), |
|
80
|
|
|
]; |
|
81
|
|
|
if ($chartPlugin instanceof ChartLayoutablePluginInterface) { |
|
82
|
|
|
$context['layout'] = $chartPlugin->getChartLayout(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $context; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return array |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function getDefaultTwigOptions(): array |
|
92
|
|
|
{ |
|
93
|
|
|
return [ |
|
94
|
|
|
'is_safe' => ['html'], |
|
95
|
|
|
'needs_environment' => true, |
|
96
|
|
|
]; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param string $pluginName |
|
101
|
|
|
* |
|
102
|
|
|
* @return \Spryker\Shared\Chart\Dependency\Plugin\ChartPluginInterface |
|
103
|
|
|
*/ |
|
104
|
|
|
protected function getChartPluginByName($pluginName): ChartPluginInterface |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->getFactory() |
|
107
|
|
|
->createChartPluginCollection() |
|
108
|
|
|
->getChartPluginByName($pluginName); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths