1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace BitBag\SyliusMolliePlugin\Twig\Extension; |
14
|
|
|
|
15
|
|
|
use BitBag\SyliusMolliePlugin\BitBagSyliusMolliePlugin; |
16
|
|
|
use BitBag\SyliusMolliePlugin\Checker\Version\MolliePluginLatestVersionCheckerInterface; |
17
|
|
|
use Twig\Environment; |
18
|
|
|
use Twig\Extension\AbstractExtension; |
19
|
|
|
use Twig\TwigFunction; |
20
|
|
|
|
21
|
|
|
final class MolliePluginLatestVersion extends AbstractExtension |
22
|
|
|
{ |
23
|
|
|
/** @var MolliePluginLatestVersionCheckerInterface */ |
24
|
|
|
private $latestVersionChecker; |
25
|
|
|
|
26
|
|
|
public function __construct(MolliePluginLatestVersionCheckerInterface $latestVersionChecker) |
27
|
|
|
{ |
28
|
|
|
$this->latestVersionChecker = $latestVersionChecker; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getFunctions(): array |
32
|
|
|
{ |
33
|
|
|
return [ |
34
|
|
|
new TwigFunction( |
35
|
|
|
'bitbag_render_version_widget', |
36
|
|
|
[$this, 'versionRenderWidget'], |
37
|
|
|
[ |
38
|
|
|
'needs_environment' => true, |
39
|
|
|
'is_safe' => ['html'], |
40
|
|
|
] |
41
|
|
|
), |
42
|
|
|
]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function versionRenderWidget(Environment $environment): string |
46
|
|
|
{ |
47
|
|
|
$latestVersion = str_replace('v', '', $this->latestVersionChecker->checkLatestVersion()); |
48
|
|
|
|
49
|
|
|
if ($latestVersion === BitBagSyliusMolliePlugin::VERSION || empty($latestVersion)) { |
50
|
|
|
return ''; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $environment->render('@SyliusAdmin/PaymentMethod/_versionNotification.html.twig', [ |
54
|
|
|
'latestVersion' => $latestVersion, |
55
|
|
|
'currentVersion' => BitBagSyliusMolliePlugin::VERSION, |
56
|
|
|
]); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|